Add more CMake helper scripts plus more CMake updates.

- Disallow in-tree CMake runs.
- Adds back CONTRIBUTING.md.

This fixes #130 and hopefully addresses #163.
This commit is contained in:
Frank Galligan 2017-08-03 16:07:12 -07:00
parent 5c8b21d610
commit da71b48359
5 changed files with 119 additions and 48 deletions

View File

@ -5,6 +5,14 @@ set(draco_root "${CMAKE_CURRENT_SOURCE_DIR}")
set(draco_src_root "${draco_root}/src/draco")
set(draco_build_dir "${CMAKE_BINARY_DIR}")
if ("${draco_root}" STREQUAL "${draco_build_dir}")
message(FATAL_ERROR
"Building from within the Draco source tree is not supported.\n"
"Hint: mkdir -p ../draco_build && cd ../draco_build\n"
"Run cmake from there.")
endif ()
include(CMakePackageConfigHelpers)
include("${draco_root}/cmake/compiler_flags.cmake")
include("${draco_root}/cmake/util.cmake")
@ -772,22 +780,12 @@ else ()
set_target_properties(draco PROPERTIES SOVERSION 1)
endif ()
extract_version_string("${draco_src_root}/core/draco_version.h" draco_version)
if (NOT MSVC)
# Generate draco.pc.
# Extract the version string.
file(STRINGS "${draco_src_root}/core/draco_version.h" draco_version
REGEX "kDracoVersion\\[\\]")
list(GET draco_version 0 draco_version)
string(REPLACE "static const char kDracoVersion[] = " "" draco_version
"${draco_version}")
string(REPLACE ";" "" draco_version "${draco_version}")
string(REPLACE "\"" "" draco_version "${draco_version}")
set(prefix "${CMAKE_INSTALL_PREFIX}")
set(pkgconfig_file "${draco_build_dir}/draco.pc")
# Write aom.pc.
file(WRITE "${pkgconfig_file}" "# draco pkg-config.\n")
file(APPEND "${pkgconfig_file}" "prefix=${prefix}\n")
file(APPEND "${pkgconfig_file}" "exec_prefix=${prefix}/bin\n")
@ -836,8 +834,41 @@ else ()
DESTINATION "${CMAKE_INSTALL_PREFIX}/lib")
install(TARGETS draco_decoder draco_encoder DESTINATION
"${CMAKE_INSTALL_PREFIX}/bin")
install(FILES "${draco_root}/cmake/FindDraco.cmake"
DESTINATION "${CMAKE_INSTALL_PREFIX}/include/draco/cmake")
# Generate a CMake config file.
set(draco_include_install_dir "include/draco")
set(draco_lib_install_dir "lib")
set(draco_script_install_dir
"${CMAKE_INSTALL_PREFIX}/${draco_lib_install_dir}/draco/cmake")
set(draco_config_in_file "${draco_root}/cmake/DracoConfig.cmake")
set(draco_config_out_file "${draco_build_dir}/DracoConfig.cmake")
configure_package_config_file(
"${draco_config_in_file}"
"${draco_config_out_file}"
NO_CHECK_REQUIRED_COMPONENTS_MACRO
INSTALL_DESTINATION "${draco_lib_install_dir}/draco/cmake"
PATH_VARS draco_include_install_dir draco_lib_install_dir)
write_basic_package_version_file(
"${draco_build_dir}/DracoConfigVersion.cmake"
VERSION ${draco_version}
COMPATIBILITY SameMajorVersion)
# Read in the config file and rewrite it with a version string included.
file(STRINGS "${draco_config_out_file}" draco_config_strings)
file(WRITE "${draco_config_out_file}"
"set(draco_VERSION \"${draco_version}\")\n")
foreach (config_string ${draco_config_strings})
file(APPEND "${draco_config_out_file}" "${config_string}\n")
endforeach ()
# Add install rules for CMake helper scripts.
set(draco_cmake_helper_scripts
"${draco_root}/cmake/FindDraco.cmake"
"${draco_build_dir}/DracoConfig.cmake"
"${draco_build_dir}/DracoConfigVersion.cmake")
install(FILES ${draco_cmake_helper_scripts}
DESTINATION "${draco_script_install_dir}")
# Some generators complain about unknown link language for header only
# targets. Silence the harmless warnings/errors with some dummy source files.

27
CONTRIBUTING.md Normal file
View File

@ -0,0 +1,27 @@
Want to contribute? Great! First, read this page (including the small print at the end).
### Before you contribute
Before we can use your code, you must sign the
[Google Individual Contributor License Agreement]
(https://cla.developers.google.com/about/google-individual)
(CLA), which you can do online. The CLA is necessary mainly because you own the
copyright to your changes, even after your contribution becomes part of our
codebase, so we need your permission to use and distribute your code. We also
need to be sure of various other things—for instance that you'll tell us if you
know that your code infringes on other people's patents. You don't have to sign
the CLA until after you've submitted your code for review and a member has
approved it, but you must do it before we can put your code into our codebase.
Before you start working on a larger contribution, you should get in touch with
us first through the issue tracker with your idea so that we can help out and
possibly guide you. Coordinating up front makes it much easier to avoid
frustration later on.
### Code reviews
All submissions, including submissions by project members, require review. We
use GitHub pull requests for this purpose.
### The small print
Contributions made by corporations are covered by a different agreement than
the one above, the
[Software Grant and Corporate Contributor License Agreement]
(https://cla.developers.google.com/about/google-corporate).

3
cmake/DracoConfig.cmake Normal file
View File

@ -0,0 +1,3 @@
@PACKAGE_INIT@
set_and_check(draco_INCLUDE_DIR "@PACKAGE_draco_include_install_dir@")
set_and_check(draco_LIBRARY_DIR "@PACKAGE_draco_lib_install_dir@")

View File

@ -1,58 +1,58 @@
# FindDraco
# Finddraco
#
# Locates Draco and sets the following variables:
# Locates draco and sets the following variables:
#
# Drace_FOUND
# Draco_INCLUDE_DIRS
# Draco_LIBARY_DIRS
# Draco_LIBRARIES
# Draco_VERSION_STRING
# draco_FOUND
# draco_INCLUDE_DIRS
# draco_LIBARY_DIRS
# draco_LIBRARIES
# draco_VERSION_STRING
#
# Draco_FOUND is set to YES only when all other variables are successfully
# draco_FOUND is set to YES only when all other variables are successfully
# configured.
unset(Draco_FOUND)
unset(Draco_INCLUDE_DIRS)
unset(Draco_LIBRARY_DIRS)
unset(Draco_LIBRARIES)
unset(Draco_VERSION_STRING)
unset(draco_FOUND)
unset(draco_INCLUDE_DIRS)
unset(draco_LIBRARY_DIRS)
unset(draco_LIBRARIES)
unset(draco_VERSION_STRING)
mark_as_advanced(Draco_FOUND)
mark_as_advanced(Draco_INCLUDE_DIRS)
mark_as_advanced(Draco_LIBRARY_DIRS)
mark_as_advanced(Draco_LIBRARIES)
mark_as_advanced(Draco_VERSION_STRING)
mark_as_advanced(draco_FOUND)
mark_as_advanced(draco_INCLUDE_DIRS)
mark_as_advanced(draco_LIBRARY_DIRS)
mark_as_advanced(draco_LIBRARIES)
mark_as_advanced(draco_VERSION_STRING)
set(Draco_version_file_no_prefix "draco/src/draco/core/draco_version.h")
set(draco_version_file_no_prefix "draco/src/draco/core/draco_version.h")
# Set Draco_INCLUDE_DIRS
find_path(Draco_INCLUDE_DIRS NAMES "${Draco_version_file_no_prefix}")
# Set draco_INCLUDE_DIRS
find_path(draco_INCLUDE_DIRS NAMES "${draco_version_file_no_prefix}")
# Extract the version string from draco_version.h.
if (Draco_INCLUDE_DIRS)
set(Draco_version_file
"${Draco_INCLUDE_DIRS}/draco/src/draco/core/draco_version.h")
file(STRINGS "${Draco_version_file}" draco_version
REGEX "kDracoVersion")
if (draco_INCLUDE_DIRS)
set(draco_version_file
"${draco_INCLUDE_DIRS}/draco/src/draco/core/draco_version.h")
file(STRINGS "${draco_version_file}" draco_version
REGEX "kdracoVersion")
list(GET draco_version 0 draco_version)
string(REPLACE "static const char kDracoVersion[] = " "" draco_version
string(REPLACE "static const char kdracoVersion[] = " "" draco_version
"${draco_version}")
string(REPLACE ";" "" draco_version "${draco_version}")
string(REPLACE "\"" "" draco_version "${draco_version}")
set(Draco_VERSION_STRING ${draco_version})
set(draco_VERSION_STRING ${draco_version})
endif ()
# Find the library.
if (BUILD_SHARED_LIBS)
find_library(Draco_LIBRARIES NAMES draco.dll libdraco.dylib libdraco.so)
find_library(draco_LIBRARIES NAMES draco.dll libdraco.dylib libdraco.so)
else ()
find_library(Draco_LIBRARIES NAMES draco.lib libdraco.a)
find_library(draco_LIBRARIES NAMES draco.lib libdraco.a)
endif ()
# Store path to library.
get_filename_component(Draco_LIBRARY_DIRS ${Draco_LIBRARIES} DIRECTORY)
get_filename_component(draco_LIBRARY_DIRS ${draco_LIBRARIES} DIRECTORY)
if (Draco_INCLUDE_DIRS AND Draco_LIBRARY_DIRS AND Draco_LIBRARIES AND
Draco_VERSION_STRING)
set(Draco_FOUND YES)
if (draco_INCLUDE_DIRS AND draco_LIBRARY_DIRS AND draco_LIBRARIES AND
draco_VERSION_STRING)
set(draco_FOUND YES)
endif ()

View File

@ -16,5 +16,15 @@ function (add_dummy_source_file_to_target target_name extension)
target_sources(${target_name} PRIVATE ${dummy_source_file})
endfunction ()
function (extract_version_string version_file version_string_out_var)
file(STRINGS "${version_file}" draco_version REGEX "kDracoVersion")
list(GET draco_version 0 draco_version)
string(REPLACE "static const char kDracoVersion[] = " "" draco_version
"${draco_version}")
string(REPLACE ";" "" draco_version "${draco_version}")
string(REPLACE "\"" "" draco_version "${draco_version}")
set("${version_string_out_var}" "${draco_version}" PARENT_SCOPE)
endfunction ()
endif() # DRACO_CMAKE_UTIL_CMAKE_