diff --git a/CMakeLists.txt b/CMakeLists.txt index 63971f252..ecb1ceda9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ include(AwsFeatureTests) include(AwsSanitizers) include(AwsThreadAffinity) include(AwsSIMD) +include(CMakePackageConfigHelpers) include(CTest) set(GENERATED_ROOT_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated") @@ -228,9 +229,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") @@ -260,7 +268,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 e495210c4..fa800167c 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 "@PACKAGE_AWS_MODULE_INSTALL_DIR@") + set(THREADS_PREFER_PTHREAD_FLAG ON) if(WIN32 OR UNIX OR APPLE)