mirror of
https://git.mirrors.martin98.com/https://github.com/google/draco
synced 2025-08-12 04:19:01 +08:00
cmake: Support modernized import of Draco via draco::draco
This a refactoring of the CMake config file to follow best practices: - A draco-targets.cmake is generated with install(EXPORT ...), and included in draco-config.cmake. - For users consuming Draco with add_subdirectory(), a draco::draco alias is provided. - Removed find-draco.cmake-- CMake couldn't use it anyway due to the file name not matching CMake expectations for a find script. Note: this also removes the previous methods of hardcoding the C++ standard in the Draco build to C++11. Instead of direct manipulation of CMAKE_CXX_STANDARD target_compile_features() is used. External projects consuming Draco should now be able to set the standard to a newer version.
This commit is contained in:
parent
575e6ec2e8
commit
7109fbee87
@ -13,10 +13,6 @@
|
||||
# limitations under the License.
|
||||
|
||||
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
|
||||
|
||||
# Draco requires modern compiler support.
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
project(draco C CXX)
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
@ -970,6 +966,7 @@ else()
|
||||
${draco_include_paths}
|
||||
OBJLIB_DEPS
|
||||
${draco_object_library_deps})
|
||||
add_library(draco::draco ALIAS draco)
|
||||
|
||||
else()
|
||||
draco_add_library(NAME
|
||||
@ -1000,6 +997,11 @@ else()
|
||||
${draco_include_paths}
|
||||
LIB_DEPS
|
||||
draco_static)
|
||||
add_library(draco::draco ALIAS draco_shared)
|
||||
set_target_properties(draco_shared PROPERTIES EXPORT_NAME draco)
|
||||
else()
|
||||
add_library(draco::draco ALIAS draco_static)
|
||||
set_target_properties(draco_static PROPERTIES EXPORT_NAME draco)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
@ -1,6 +1,3 @@
|
||||
@PACKAGE_INIT@
|
||||
set_and_check(DRACO_INCLUDE_DIR "@CMAKE_INSTALL_FULL_INCLUDEDIR@")
|
||||
set_and_check(DRACO_LIBRARY_DIR "@CMAKE_INSTALL_FULL_LIBDIR@")
|
||||
find_library(_DRACO_LIBRARY PATHS ${DRACO_LIBRARY_DIR} NAMES draco)
|
||||
set_and_check(DRACO_LIBRARY ${_DRACO_LIBRARY})
|
||||
set(DRACO_FOUND YES)
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/draco-targets.cmake")
|
||||
|
@ -27,31 +27,6 @@ macro(draco_setup_install_target)
|
||||
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 "${libs_path}/pkgconfig")
|
||||
|
||||
# CMake config: draco-config.cmake
|
||||
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/draco")
|
||||
install(
|
||||
FILES "${draco_build}/draco-config.cmake"
|
||||
DESTINATION "${data_path}/cmake/draco")
|
||||
|
||||
# CMake version: draco-config-version.cmake
|
||||
write_basic_package_version_file(
|
||||
"${draco_build}/draco-config-version.cmake"
|
||||
VERSION ${DRACO_VERSION}
|
||||
COMPATIBILITY AnyNewerVersion)
|
||||
install(
|
||||
FILES "${draco_build}/draco-config-version.cmake"
|
||||
DESTINATION "${data_path}/cmake/draco")
|
||||
|
||||
foreach(file ${draco_sources})
|
||||
if(file MATCHES "h$")
|
||||
@ -86,15 +61,20 @@ macro(draco_setup_install_target)
|
||||
if(MSVC)
|
||||
install(
|
||||
TARGETS draco
|
||||
EXPORT dracoExport
|
||||
RUNTIME DESTINATION "${bin_path}"
|
||||
ARCHIVE DESTINATION "${libs_path}"
|
||||
LIBRARY DESTINATION "${libs_path}")
|
||||
else()
|
||||
install(TARGETS draco_static DESTINATION "${libs_path}")
|
||||
install(
|
||||
TARGETS draco_static
|
||||
EXPORT dracoExport
|
||||
DESTINATION "${libs_path}")
|
||||
|
||||
if(BUILD_SHARED_LIBS)
|
||||
install(
|
||||
TARGETS draco_shared
|
||||
EXPORT dracoExport
|
||||
RUNTIME DESTINATION "${bin_path}"
|
||||
ARCHIVE DESTINATION "${libs_path}"
|
||||
LIBRARY DESTINATION "${libs_path}")
|
||||
@ -109,4 +89,36 @@ macro(draco_setup_install_target)
|
||||
install(TARGETS draco_maya_wrapper DESTINATION "${libs_path}")
|
||||
endif()
|
||||
|
||||
# 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 "${libs_path}/pkgconfig")
|
||||
|
||||
# CMake config: draco-config.cmake
|
||||
configure_package_config_file(
|
||||
"${draco_root}/cmake/draco-config.cmake.template"
|
||||
"${draco_build}/draco-config.cmake"
|
||||
INSTALL_DESTINATION "${data_path}/cmake/draco")
|
||||
|
||||
write_basic_package_version_file(
|
||||
"${draco_build}/draco-config-version.cmake"
|
||||
VERSION ${DRACO_VERSION}
|
||||
COMPATIBILITY AnyNewerVersion)
|
||||
|
||||
export(
|
||||
EXPORT dracoExport
|
||||
NAMESPACE draco::
|
||||
FILE "${draco_build}/draco-targets.cmake")
|
||||
|
||||
install(
|
||||
EXPORT dracoExport
|
||||
NAMESPACE draco::
|
||||
FILE draco-targets.cmake
|
||||
DESTINATION "${data_path}/cmake/draco")
|
||||
|
||||
install(
|
||||
FILES
|
||||
"${draco_build}/draco-config.cmake"
|
||||
"${draco_build}/draco-config-version.cmake"
|
||||
DESTINATION "${data_path}/cmake/draco")
|
||||
endmacro()
|
||||
|
@ -101,6 +101,7 @@ macro(draco_add_executable)
|
||||
endif()
|
||||
|
||||
add_executable(${exe_NAME} ${exe_SOURCES})
|
||||
target_compile_features(${exe_NAME} PRIVATE cxx_std_11)
|
||||
|
||||
if(NOT EMSCRIPTEN)
|
||||
set_target_properties(${exe_NAME} PROPERTIES VERSION ${DRACO_VERSION})
|
||||
@ -273,6 +274,8 @@ macro(draco_add_library)
|
||||
endif()
|
||||
|
||||
add_library(${lib_NAME} ${lib_TYPE} ${lib_SOURCES})
|
||||
target_compile_features(${lib_NAME} PUBLIC cxx_std_11)
|
||||
target_include_directories(${lib_NAME} PUBLIC $<INSTALL_INTERFACE:include>)
|
||||
if(lib_SOURCES)
|
||||
draco_process_intrinsics_sources(TARGET ${lib_NAME} SOURCES ${lib_SOURCES})
|
||||
endif()
|
||||
|
@ -1,71 +0,0 @@
|
||||
# Finddraco
|
||||
#
|
||||
# Locates draco and sets the following variables:
|
||||
#
|
||||
# - DRACO_FOUND
|
||||
# - DRACO_INCLUDE_DIR
|
||||
# - DRACO_LIBARY_DIR
|
||||
# - DRACO_LIBRARY
|
||||
# - DRACO_VERSION
|
||||
#
|
||||
# DRACO_FOUND is set to YES only when all other variables are successfully
|
||||
# configured.
|
||||
include(GNUInstallDirs)
|
||||
|
||||
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_DIR)
|
||||
mark_as_advanced(DRACO_LIBRARY_DIR)
|
||||
mark_as_advanced(DRACO_LIBRARY)
|
||||
mark_as_advanced(DRACO_VERSION)
|
||||
|
||||
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}")
|
||||
|
||||
# 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_DIR)
|
||||
set(draco_version_file
|
||||
"${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
|
||||
"${draco_version}")
|
||||
string(REPLACE ";" "" draco_version "${draco_version}")
|
||||
string(REPLACE "\"" "" draco_version "${draco_version}")
|
||||
set(DRACO_VERSION ${draco_version})
|
||||
endif()
|
||||
|
||||
# Find the library.
|
||||
if(BUILD_SHARED_LIBS)
|
||||
find_library(DRACO_LIBRARY NAMES draco.dll libdraco.dylib libdraco.so)
|
||||
else()
|
||||
find_library(DRACO_LIBRARY NAMES draco.lib libdraco.a)
|
||||
endif()
|
||||
|
||||
# Store path to library.
|
||||
get_filename_component(DRACO_LIBRARY_DIR ${DRACO_LIBRARY} DIRECTORY)
|
||||
|
||||
if(DRACO_INCLUDE_DIR
|
||||
AND DRACO_LIBRARY_DIR
|
||||
AND DRACO_LIBRARY
|
||||
AND DRACO_VERSION)
|
||||
set(DRACO_FOUND YES)
|
||||
endif()
|
@ -20,10 +20,6 @@ include(GNUInstallDirs)
|
||||
find_package(draco REQUIRED CONFIG)
|
||||
|
||||
add_executable(install_check main.cc)
|
||||
# Update include paths and dependencies to allow for successful build of the
|
||||
# install_check target using Draco as configured for the current installation.
|
||||
target_include_directories(install_check PUBLIC "${DRACO_INCLUDE_DIR}")
|
||||
target_link_libraries(install_check "${DRACO_LIBRARY}")
|
||||
target_compile_features(install_check PRIVATE cxx_std_11)
|
||||
target_link_libraries(install_check PRIVATE draco::draco)
|
||||
|
||||
install(TARGETS install_check DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
|
Loading…
x
Reference in New Issue
Block a user