Skip to content

Commit

Permalink
A bunch of CMake fixes (#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
graebm authored Jan 28, 2025
1 parent 9c093c4 commit 83247bd
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 38 deletions.
38 changes: 12 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,37 +1,23 @@
cmake_minimum_required(VERSION 3.9)
cmake_minimum_required(VERSION 3.9...3.31)
project(aws-c-mqtt C)

option(ASSERT_LOCK_HELD "Enable ASSERT_SYNCED_DATA_LOCK_HELD for checking thread issue" OFF)
if (ASSERT_LOCK_HELD)
add_definitions(-DASSERT_LOCK_HELD)
endif()

if (DEFINED CMAKE_PREFIX_PATH)
file(TO_CMAKE_PATH "${CMAKE_PREFIX_PATH}" CMAKE_PREFIX_PATH)
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()

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})

include(AwsCFlags)
include(AwsCheckHeaders)
include(AwsSharedLibSetup)
include(AwsSanitizers)
include(CheckCCompilerFlag)
include(AwsFindPackage)
include(GNUInstallDirs)

file(GLOB AWS_MQTT_HEADERS
"include/aws/mqtt/*.h"
Expand Down Expand Up @@ -93,11 +79,11 @@ aws_use_package(aws-c-http)
target_link_libraries(${PROJECT_NAME} PUBLIC ${DEP_AWS_LIBS})
aws_prepare_shared_lib_exports(${PROJECT_NAME})

install(FILES ${AWS_MQTT_HEADERS} DESTINATION "include/aws/mqtt" COMPONENT Development)
install(FILES ${AWS_MQTT5_HEADERS} DESTINATION "include/aws/mqtt/v5" COMPONENT Development)
install(FILES ${AWS_MQTT_RR_HEADERS} DESTINATION "include/aws/mqtt/request-response" COMPONENT Development)
install(FILES ${AWS_MQTT_TESTING_HEADERS} DESTINATION "include/aws/testing/mqtt" COMPONENT Development)
install(FILES ${AWS_MQTT_PRIV_EXPOSED_HEADERS} DESTINATION "include/aws/mqtt/private" COMPONENT Development)
install(FILES ${AWS_MQTT_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/aws/mqtt" COMPONENT Development)
install(FILES ${AWS_MQTT5_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/aws/mqtt/v5" COMPONENT Development)
install(FILES ${AWS_MQTT_RR_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/aws/mqtt/request-response" COMPONENT Development)
install(FILES ${AWS_MQTT_TESTING_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/aws/testing/mqtt" COMPONENT Development)
install(FILES ${AWS_MQTT_PRIV_EXPOSED_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/aws/mqtt/private" COMPONENT Development)

if (BUILD_SHARED_LIBS)
set (TARGET_DIR "shared")
Expand All @@ -106,7 +92,7 @@ else()
endif()

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

Expand All @@ -115,7 +101,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 "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}/"
COMPONENT Development)

include(CTest)
Expand Down
4 changes: 1 addition & 3 deletions bin/elastipubsub/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
project(elastipubsub C)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_INSTALL_PREFIX}/lib/cmake")

file(GLOB ELASTIPUBSUB_SRC
"*.c"
)
Expand All @@ -25,5 +23,5 @@ install(TARGETS ${ELASTIPUBSUB_PROJECT_NAME}
EXPORT ${ELASTIPUBSUB_PROJECT_NAME}-targets
COMPONENT Runtime
RUNTIME
DESTINATION bin
DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT Runtime)
4 changes: 1 addition & 3 deletions bin/elastipubsub5/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
project(elastipubsub5 C)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_INSTALL_PREFIX}/lib/cmake")

file(GLOB ELASTIPUBSUB_SRC
"*.c"
)
Expand All @@ -25,5 +23,5 @@ install(TARGETS ${ELASTIPUBSUB_MQTT5_PROJECT_NAME}
EXPORT ${ELASTIPUBSUB_MQTT5_PROJECT_NAME}-targets
COMPONENT Runtime
RUNTIME
DESTINATION bin
DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT Runtime)
4 changes: 1 addition & 3 deletions bin/elastishadow/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
project(elastishadow C)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_INSTALL_PREFIX}/lib/cmake")

file(GLOB ELASTISHADOW_SRC
"*.c"
)
Expand All @@ -25,5 +23,5 @@ install(TARGETS ${ELASTISHADOW_PROJECT_NAME}
EXPORT ${ELASTISHADOW_PROJECT_NAME}-targets
COMPONENT Runtime
RUNTIME
DESTINATION bin
DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT Runtime)
4 changes: 1 addition & 3 deletions bin/mqtt5canary/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
project(mqtt5canary C)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_INSTALL_PREFIX}/lib/cmake")

file(GLOB MQTT5CANARY_SRC
"*.c"
)
Expand All @@ -25,5 +23,5 @@ install(TARGETS ${MQTT5CANARY_PROJECT_NAME}
EXPORT ${MQTT5CANARY_PROJECT_NAME}-targets
COMPONENT Runtime
RUNTIME
DESTINATION bin
DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT Runtime)

0 comments on commit 83247bd

Please sign in to comment.