From 871456d099f8f42da695ad31e56c2037596391ed Mon Sep 17 00:00:00 2001 From: Sam Fuller Date: Wed, 4 Oct 2017 03:57:17 -0700 Subject: [PATCH] CMake: Generate and install CMake config files --- CMakeLists.txt | 40 ++++++++++++++++++++++++++++++++++++---- Config.cmake.in | 4 ++++ 2 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 Config.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 31b0752..801396e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,24 +57,56 @@ add_library(cubeb src/cubeb_log.cpp src/cubeb_strings.c $) -target_include_directories(cubeb PUBLIC include) +target_include_directories(cubeb + PUBLIC $ $ +) target_include_directories(cubeb PRIVATE src) target_compile_definitions(cubeb PRIVATE OUTSIDE_SPEEX) target_compile_definitions(cubeb PRIVATE FLOATING_POINT) target_compile_definitions(cubeb PRIVATE EXPORT=) target_compile_definitions(cubeb PRIVATE RANDOM_PREFIX=speex) -install(TARGETS cubeb DESTINATION ${CMAKE_INSTALL_PREFIX}) - add_sanitizers(cubeb) include(GenerateExportHeader) generate_export_header(cubeb EXPORT_FILE_NAME ${CMAKE_BINARY_DIR}/exports/cubeb_export.h) -target_include_directories(cubeb PUBLIC ${CMAKE_BINARY_DIR}/exports) +target_include_directories(cubeb + PUBLIC $ +) install(DIRECTORY ${CMAKE_SOURCE_DIR}/include DESTINATION ${CMAKE_INSTALL_PREFIX}) install(DIRECTORY ${CMAKE_BINARY_DIR}/exports/ DESTINATION ${CMAKE_INSTALL_PREFIX}/include/cubeb) +include(CMakePackageConfigHelpers) +write_basic_package_version_file( + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + COMPATIBILITY SameMajorVersion +) + +configure_package_config_file( + "Config.cmake.in" + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + INSTALL_DESTINATION "lib/cmake/${PROJECT_NAME}" +) + +install(TARGETS cubeb + EXPORT "${PROJECT_NAME}Targets" + DESTINATION ${CMAKE_INSTALL_PREFIX} + LIBRARY DESTINATION "lib" + ARCHIVE DESTINATION "lib" + RUNTIME DESTINATION "bin" + INCLUDES DESTINATION "include" +) +install( + FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + DESTINATION "lib/cmake/${PROJECT_NAME}" +) +install( + EXPORT "${PROJECT_NAME}Targets" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "lib/cmake/${PROJECT_NAME}" +) + add_library(speex OBJECT src/speex/resample.c) set_target_properties(speex PROPERTIES POSITION_INDEPENDENT_CODE TRUE) diff --git a/Config.cmake.in b/Config.cmake.in new file mode 100644 index 0000000..c5326ef --- /dev/null +++ b/Config.cmake.in @@ -0,0 +1,4 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/cubebTargets.cmake") +check_required_components(cubeb) \ No newline at end of file