Skip to content

Commit

Permalink
Install cmake config to more standard location
Browse files Browse the repository at this point in the history
  • Loading branch information
graebm committed Dec 19, 2024
1 parent f6f6095 commit 6eae0c0
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,6 @@ project(aws-c-iot C)

option(USE_EXTERNAL_DEPS_SOURCES "Use dependencies provided by add_subdirectory command" OFF)

if (DEFINED CMAKE_PREFIX_PATH)
file(TO_CMAKE_PATH "${CMAKE_PREFIX_PATH}" CMAKE_PREFIX_PATH)
endif()

if (DEFINED CMAKE_INSTALL_PREFIX)
file(TO_CMAKE_PATH "${CMAKE_INSTALL_PREFIX}" CMAKE_INSTALL_PREFIX)
endif()

if (UNIX AND NOT APPLE)
include(GNUInstallDirs)
elseif(NOT DEFINED CMAKE_INSTALL_LIBDIR)
set(CMAKE_INSTALL_LIBDIR "lib")
endif()

# This is required in order to append /lib/cmake to each element in CMAKE_PREFIX_PATH
set(AWS_MODULE_DIR "/${CMAKE_INSTALL_LIBDIR}/cmake")
string(REPLACE ";" "${AWS_MODULE_DIR};" AWS_MODULE_PATH "${CMAKE_PREFIX_PATH}${AWS_MODULE_DIR}")
# Append that generated list to the module search path
list(APPEND CMAKE_MODULE_PATH ${AWS_MODULE_PATH})

if (USE_EXTERNAL_DEPS_SOURCES)
set(IN_SOURCE_BUILD ON)

Expand All @@ -35,6 +15,11 @@ if (USE_EXTERNAL_DEPS_SOURCES)
list(APPEND CMAKE_MODULE_PATH "${aws-c-common_SOURCE_DIR}/cmake")
endif()

if (NOT IN_SOURCE_BUILD)
# this is required so we can use aws-c-common's CMake modules
find_package(aws-c-common REQUIRED)
endif()

include(AwsCFlags)
include(AwsCheckHeaders)
include(AwsSharedLibSetup)
Expand Down Expand Up @@ -118,7 +103,7 @@ else()
endif()

install(EXPORT "${PROJECT_NAME}-targets"
DESTINATION "${LIBRARY_DIRECTORY}/${PROJECT_NAME}/cmake/${TARGET_DIR}"
DESTINATION "${LIBRARY_DIRECTORY}/cmake/${PROJECT_NAME}/${TARGET_DIR}"
NAMESPACE AWS::
COMPONENT Development)

Expand All @@ -127,7 +112,7 @@ configure_file("cmake/${PROJECT_NAME}-config.cmake"
@ONLY)

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
DESTINATION "${LIBRARY_DIRECTORY}/${PROJECT_NAME}/cmake/"
DESTINATION "${LIBRARY_DIRECTORY}/cmake/${PROJECT_NAME}/"
COMPONENT Development)

include(CTest)
Expand Down

0 comments on commit 6eae0c0

Please sign in to comment.