Skip to content

Commit

Permalink
draco: Improve installation and packaging support.
Browse files Browse the repository at this point in the history
- Fixed omission of draco_version.h when installed in static
  configurations.
- Remove DracoConfig.cmake: it was broken and we actually use
  draco-config.cmake.
- Update FindDraco.cmake so it actually has a chance of working
  properly. Fixed usage of find_path() and subsequent related errors.
- Correct the usage of CMakePackageConfigHelpers in installation target setup
  and the config template.
- Add a CMake version file.
- Normalize the Draco variables exposed in CMake.
  - draco_FOUND -> DRACO_FOUND
  - DRACO_INCLUDE_DIRS, draco_INCLUDE_DIRS -> DRACO_INCLUDE_DIR
  - DRACO_LIBRARIES, draco_LIBRARIES -> DRACO_LIBRARY
  - DRACO_LIBRARY_DIRS, draco_LIBRARY_DIRS -> DRACO_LIBRARY_DIR
  - draco_VERSION_STRING -> DRACO_VERSION
- Use full path variants of GNUInstallDirs variables to init our
  install paths.

Fixes #764

* Add install() for draco-version.cmake.
  • Loading branch information
tomfinegan authored Dec 6, 2021
1 parent 5272348 commit 931bafe
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 69 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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"
Expand Down
3 changes: 0 additions & 3 deletions cmake/DracoConfig.cmake

This file was deleted.

64 changes: 38 additions & 26 deletions cmake/FindDraco.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
6 changes: 4 additions & 2 deletions cmake/draco-config.cmake.template
Original file line number Diff line number Diff line change
@@ -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")
9 changes: 2 additions & 7 deletions cmake/draco.pc.template
Original file line number Diff line number Diff line change
@@ -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@
67 changes: 37 additions & 30 deletions cmake/draco_install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,77 +17,84 @@ 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$")
list(APPEND draco_api_includes ${file})
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()

0 comments on commit 931bafe

Please sign in to comment.