From b1d05c1f94dc45f7414bcd4c27ba49c86abbedb7 Mon Sep 17 00:00:00 2001 From: Lectem Date: Wed, 5 Feb 2020 01:07:17 +0100 Subject: [PATCH] CMake package should add the modules to CMAKE_MODULE_PATH Right now aws-c-event-stream needs a lot of boilerplate code to determine the modules installation path while the aws-c-common package should provide it. This would fix https://github.com/awslabs/aws-c-event-stream/issues/15 simply by moving `find_package(aws-c-common REQUIRED)` before the various module `include`s Using `configure_package_config_file` makes it easier to have a relocatable package. --- CMakeLists.txt | 14 +++++++++++--- cmake/aws-c-common-config.cmake | 4 ++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1502eba78..353a4828f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ include(AwsSharedLibSetup) include(AwsFeatureTests) include(AwsSanitizers) include(AwsSIMD) +include(CMakePackageConfigHelpers) include(CTest) set(GENERATED_ROOT_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated") @@ -195,9 +196,16 @@ endforeach() aws_prepare_shared_lib_exports(${PROJECT_NAME}) -configure_file("cmake/${PROJECT_NAME}-config.cmake" +set(AWS_MODULE_INSTALL_DIR "${LIBRARY_DIRECTORY}/cmake") + +configure_package_config_file( + "cmake/${PROJECT_NAME}-config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" - @ONLY) + INSTALL_DESTINATION "${LIBRARY_DIRECTORY}/${PROJECT_NAME}/cmake" + PATH_VARS AWS_MODULE_INSTALL_DIR + # Imported targets do not require the following macros + NO_SET_AND_CHECK_MACRO + NO_CHECK_REQUIRED_COMPONENTS_MACRO) if (BUILD_SHARED_LIBS) set (TARGET_DIR "shared") @@ -226,7 +234,7 @@ list(APPEND EXPORT_MODULES ) install(FILES ${EXPORT_MODULES} - DESTINATION "${LIBRARY_DIRECTORY}/cmake" + DESTINATION "${AWS_MODULE_INSTALL_DIR}" COMPONENT Development) # This should come last, to ensure all variables defined by cmake will be available for export diff --git a/cmake/aws-c-common-config.cmake b/cmake/aws-c-common-config.cmake index 0c138ef4c..e867394ae 100644 --- a/cmake/aws-c-common-config.cmake +++ b/cmake/aws-c-common-config.cmake @@ -1,3 +1,7 @@ +@PACKAGE_INIT@ + +list(APPEND CMAKE_MODULE_PATH "@AWS_MODULE_INSTALL_DIR@") + set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED)