Skip to content

Commit

Permalink
CMake package should add the modules to CMAKE_MODULE_PATH
Browse files Browse the repository at this point in the history
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 awslabs/aws-c-event-stream#15 simply by moving `find_package(aws-c-common)` before the various module `include`s
Using `configure_package_config_file` makes it easier to have a relocatable package.
  • Loading branch information
Lectem authored and r-burns committed Oct 8, 2021
1 parent 73067c1 commit 6236f86
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 11 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions cmake/aws-c-common-config.cmake
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit 6236f86

Please sign in to comment.