diff --git a/CMakeLists.txt b/CMakeLists.txt index d90c4613..c1ef42dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,7 +35,6 @@ if("${draco_root}" STREQUAL "${draco_build}") "And re-run CMake from the draco_build directory.") endif() -include(CMakePackageConfigHelpers) include(FindPythonInterp) include("${draco_root}/cmake/draco_build_definitions.cmake") include("${draco_root}/cmake/draco_cpu_detection.cmake") @@ -347,6 +346,7 @@ list(APPEND draco_core_sources "${draco_src_root}/core/draco_index_type_vector.h" "${draco_src_root}/core/draco_types.cc" "${draco_src_root}/core/draco_types.h" + "${draco_src_root}/core/draco_version.h" "${draco_src_root}/core/encoder_buffer.cc" "${draco_src_root}/core/encoder_buffer.h" "${draco_src_root}/core/hash_utils.cc" diff --git a/cmake/DracoConfig.cmake b/cmake/DracoConfig.cmake deleted file mode 100644 index be5e1fae..00000000 --- a/cmake/DracoConfig.cmake +++ /dev/null @@ -1,3 +0,0 @@ -@PACKAGE_INIT@ -set_and_check(draco_INCLUDE_DIR "@PACKAGE_draco_include_install_dir@") -set_and_check(draco_LIBRARY_DIR "@PACKAGE_draco_lib_install_dir@") diff --git a/cmake/FindDraco.cmake b/cmake/FindDraco.cmake index 0a919306..11e1189b 100644 --- a/cmake/FindDraco.cmake +++ b/cmake/FindDraco.cmake @@ -7,50 +7,62 @@ # # draco_FOUND is set to YES only when all other variables are successfully # configured. +include(GNUInstallDirs) -unset(draco_FOUND) -unset(draco_INCLUDE_DIRS) -unset(draco_LIBRARY_DIRS) -unset(draco_LIBRARIES) -unset(draco_VERSION_STRING) +unset(DRACO_FOUND) +unset(DRACO_INCLUDE_DIR) +unset(DRACO_LIBRARY_DIR) +unset(DRACO_LIBRARY) +unset(DRACO_VERSION) -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_DIR) +mark_as_advanced(DRACO_LIBRARY_DIR) +mark_as_advanced(DRACO_LIBRARIES) +mark_as_advanced(DRACO_VERSION) -set(draco_version_file_no_prefix "draco/src/draco/core/draco_version.h") +if(NOT DRACO_SEARCH_DIR) + set(DRACO_SEARCH_DIR ${CMAKE_INSTALL_FULL_INCLUDEDIR}) +endif() + +set(draco_features_dir "${DRACO_SEARCH_DIR}/draco") + +# Set DRACO_INCLUDE_DIR +find_path( + DRACO_INCLUDE_DIR + NAMES "draco_features.h" + PATHS "${draco_features_dir}") -# Set draco_INCLUDE_DIRS -find_path(draco_INCLUDE_DIRS NAMES "${draco_version_file_no_prefix}") +# The above returned "path/to/draco/", strip "draco" so that projects can +# include draco sources using draco[/subdir]/file.h, like the draco sources. +get_filename_component(DRACO_INCLUDE_DIR ${DRACO_INCLUDE_DIR} DIRECTORY) # Extract the version string from draco_version.h. -if(draco_INCLUDE_DIRS) +if(DRACO_INCLUDE_DIR) set(draco_version_file - "${draco_INCLUDE_DIRS}/draco/src/draco/core/draco_version.h") - file(STRINGS "${draco_version_file}" draco_version REGEX "kdracoVersion") + "${DRACO_INCLUDE_DIR}/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 ${draco_version}) endif() # Find the library. if(BUILD_SHARED_LIBS) - find_library(draco_LIBRARIES NAMES draco.dll libdraco.dylib libdraco.so) + find_library(DRACO_LIBRARY NAMES draco.dll libdraco.dylib libdraco.so) else() - find_library(draco_LIBRARIES NAMES draco.lib libdraco.a) + find_library(DRACO_LIBRARY NAMES draco.lib libdraco.a) endif() # Store path to library. -get_filename_component(draco_LIBRARY_DIRS ${draco_LIBRARIES} DIRECTORY) +get_filename_component(DRACO_LIBRARY_DIR ${DRACO_LIBRARY} DIRECTORY) -if(draco_INCLUDE_DIRS - AND draco_LIBRARY_DIRS - AND draco_LIBRARIES - AND draco_VERSION_STRING) - set(draco_FOUND YES) +if(DRACO_INCLUDE_DIR + AND DRACO_LIBRARY_DIR + AND DRACO_LIBRARY + AND DRACO_VERSION) + set(DRACO_FOUND YES) endif() diff --git a/cmake/draco-config.cmake.template b/cmake/draco-config.cmake.template index ca4a456b..913b1b0c 100644 --- a/cmake/draco-config.cmake.template +++ b/cmake/draco-config.cmake.template @@ -1,2 +1,4 @@ -set(DRACO_INCLUDE_DIRS "@DRACO_INCLUDE_DIRS@") -set(DRACO_LIBRARIES "draco") +@PACKAGE_INIT@ +set_and_check(DRACO_INCLUDE_DIR "@CMAKE_INSTALL_FULL_INCLUDEDIR@") +set_and_check(DRACO_LIB_DIR "@CMAKE_INSTALL_FULL_LIBDIR@") +set_and_check(DRACO_LIBRARY "draco") diff --git a/cmake/draco.pc.template b/cmake/draco.pc.template index b8ae4821..050219cc 100644 --- a/cmake/draco.pc.template +++ b/cmake/draco.pc.template @@ -1,11 +1,6 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@ - Name: @PROJECT_NAME@ Description: Draco geometry de(com)pression library. Version: @DRACO_VERSION@ -Cflags: -I${includedir} -Libs: -L${libdir} -ldraco +Cflags: -I@includes_path@ +Libs: -L@libs_path@ -ldraco Libs.private: @CMAKE_THREAD_LIBS_INIT@ diff --git a/cmake/draco_install.cmake b/cmake/draco_install.cmake index 905bca68..88753c48 100644 --- a/cmake/draco_install.cmake +++ b/cmake/draco_install.cmake @@ -17,30 +17,41 @@ if(DRACO_CMAKE_DRACO_INSTALL_CMAKE_) endif() # DRACO_CMAKE_DRACO_INSTALL_CMAKE_ set(DRACO_CMAKE_DRACO_INSTALL_CMAKE_ 1) +include(CMakePackageConfigHelpers) +include(GNUInstallDirs) + # Sets up the draco install targets. Must be called after the static library # target is created. macro(draco_setup_install_target) - include(GNUInstallDirs) - - # pkg-config: draco.pc - set(prefix "${CMAKE_INSTALL_PREFIX}") - set(exec_prefix "\${prefix}") - set(libdir "\${prefix}/${CMAKE_INSTALL_LIBDIR}") - set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") + set(bin_path "${CMAKE_INSTALL_FULL_BINDIR}") + set(data_path "${CMAKE_INSTALL_FULL_DATAROOTDIR}") + set(includes_path "${CMAKE_INSTALL_FULL_INCLUDEDIR}") + set(libs_path "${CMAKE_INSTALL_FULL_LIBDIR}") set(draco_lib_name "draco") + # pkg-config: draco.pc configure_file("${draco_root}/cmake/draco.pc.template" "${draco_build}/draco.pc" @ONLY NEWLINE_STYLE UNIX) - install(FILES "${draco_build}/draco.pc" - DESTINATION "${prefix}/${CMAKE_INSTALL_LIBDIR}/pkgconfig") + install(FILES "${draco_build}/draco.pc" DESTINATION "${libs_path}/pkgconfig") # CMake config: draco-config.cmake - set(DRACO_INCLUDE_DIRS "${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") - configure_file("${draco_root}/cmake/draco-config.cmake.template" - "${draco_build}/draco-config.cmake" @ONLY NEWLINE_STYLE UNIX) + set(DRACO_INCLUDE_DIR "${includes_path}") + configure_package_config_file( + "${draco_root}/cmake/draco-config.cmake.template" + "${draco_build}/draco-config.cmake" + INSTALL_DESTINATION "${data_path}/cmake") install( FILES "${draco_build}/draco-config.cmake" - DESTINATION "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/cmake") + DESTINATION "${data_path}/cmake") + + # CMake version: draco-version.cmake + write_basic_package_version_file( + "${draco_build}/draco-version.cmake" + VERSION ${DRACO_VERSION} + COMPATIBILITY AnyNewerVersion) + install( + FILES "${draco_build}/draco-version.cmake" + DESTINATION "${data_path}/cmake") foreach(file ${draco_sources}) if(file MATCHES "h$") @@ -48,46 +59,42 @@ macro(draco_setup_install_target) endif() endforeach() + list(REMOVE_DUPLICATES draco_api_includes) + # Strip $draco_src_root from the file paths: we need to install relative to # $include_directory. list(TRANSFORM draco_api_includes REPLACE "${draco_src_root}/" "") - set(include_directory "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}") foreach(draco_api_include ${draco_api_includes}) get_filename_component(file_directory ${draco_api_include} DIRECTORY) - set(target_directory "${include_directory}/draco/${file_directory}") + set(target_directory "${includes_path}/draco/${file_directory}") install(FILES ${draco_src_root}/${draco_api_include} DESTINATION "${target_directory}") endforeach() install( FILES "${draco_build}/draco/draco_features.h" - DESTINATION "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/draco/") + DESTINATION "${includes_path}/draco/") - install(TARGETS draco_decoder DESTINATION - "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}") - install(TARGETS draco_encoder DESTINATION - "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}") + install(TARGETS draco_decoder DESTINATION "${bin_path}") + install(TARGETS draco_encoder DESTINATION "${bin_path}") if(MSVC) - install(TARGETS draco DESTINATION - "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") + install(TARGETS draco DESTINATION "${libs_path}") else() - install(TARGETS draco_static DESTINATION - "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") + install(TARGETS draco_static DESTINATION "${libs_path}") + if(BUILD_SHARED_LIBS) - install(TARGETS draco_shared DESTINATION - "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") + install(TARGETS draco_shared DESTINATION "${libs_path}") endif() endif() if(DRACO_UNITY_PLUGIN) - install(TARGETS dracodec_unity DESTINATION - "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") + install(TARGETS dracodec_unity DESTINATION "${libs_path}") endif() + if(DRACO_MAYA_PLUGIN) - install(TARGETS draco_maya_wrapper DESTINATION - "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") + install(TARGETS draco_maya_wrapper DESTINATION "${libs_path}") endif() endmacro()