Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A bunch of CMake fixes #1178

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AWSCRTAndroidTestRunner/app/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.9)
cmake_minimum_required(VERSION 3.9...3.31)

# AWS lib
set(path_to_common "${CMAKE_CURRENT_LIST_DIR}/../../../../..")
Expand Down
17 changes: 7 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@

# As of October 2024, we picked 3.9 as our version because internally we still support RHEL5 and AL2012, and CMake 3.9
# was the latest version available on those platforms.
cmake_minimum_required(VERSION 3.9)
cmake_minimum_required(VERSION 3.9...3.31)
option(ALLOW_CROSS_COMPILED_TESTS "Allow tests to be compiled via cross compile, for use with qemu" OFF)

project(aws-c-common LANGUAGES C VERSION 0.1.0)

message(STATUS "CMake ${CMAKE_VERSION}")

if (POLICY CMP0077)
cmake_policy(SET CMP0077 OLD) # Enable options to get their values from normal variables
endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(AwsCFlags)
include(AwsCheckHeaders)
Expand All @@ -23,6 +19,7 @@ include(AwsSanitizers)
include(AwsThreadAffinity)
include(AwsThreadName)
include(CTest)
include(GNUInstallDirs)

set(GENERATED_ROOT_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated")
set(GENERATED_INCLUDE_DIR "${GENERATED_ROOT_DIR}/include")
Expand Down Expand Up @@ -247,7 +244,7 @@ foreach(HEADER_SRCPATH IN ITEMS ${AWS_COMMON_HEADERS} ${AWS_COMMON_OS_HEADERS} $

unset(HEADER_DSTDIR)

foreach(POTENTIAL_PREFIX IN ITEMS ${GENERATED_ROOT_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
foreach(POTENTIAL_PREFIX IN ITEMS "${GENERATED_INCLUDE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/include")
string(LENGTH ${POTENTIAL_PREFIX} _prefixlen)
string(SUBSTRING ${HEADER_DIR} 0 ${_prefixlen} _actual_prefix)
if(${_actual_prefix} STREQUAL ${POTENTIAL_PREFIX})
Expand All @@ -261,7 +258,7 @@ foreach(HEADER_SRCPATH IN ITEMS ${AWS_COMMON_HEADERS} ${AWS_COMMON_OS_HEADERS} $
endif()

install(FILES ${HEADER_SRCPATH}
DESTINATION ${HEADER_DSTDIR}
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${HEADER_DSTDIR}"
COMPONENT Development)
endforeach()

Expand All @@ -278,12 +275,12 @@ 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)

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)

list(APPEND EXPORT_MODULES
Expand All @@ -300,7 +297,7 @@ list(APPEND EXPORT_MODULES
)

install(FILES ${EXPORT_MODULES}
DESTINATION "${LIBRARY_DIRECTORY}/cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}/modules"
COMPONENT Development)

# This should come last, to ensure all variables defined by cmake will be available for export
Expand Down
2 changes: 0 additions & 2 deletions bin/system_info/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
project(print-sys-info C)

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

file(GLOB SI_SRC
"*.c"
)
Expand Down
26 changes: 6 additions & 20 deletions cmake/AwsSharedLibSetup.cmake
Original file line number Diff line number Diff line change
@@ -1,46 +1,32 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0.

set(LIBRARY_DIRECTORY lib)
set(RUNTIME_DIRECTORY bin)
# Set the default lib installation path on GNU systems with GNUInstallDirs
if (UNIX AND NOT APPLE)
include(GNUInstallDirs)
set(LIBRARY_DIRECTORY ${CMAKE_INSTALL_LIBDIR})
set(RUNTIME_DIRECTORY ${CMAKE_INSTALL_BINDIR})

# this is the absolute dumbest thing in the world, but find_package won't work without it
# also I verified this is correctly NOT "lib64" when CMAKE_C_FLAGS includes "-m32"
if (${LIBRARY_DIRECTORY} STREQUAL "lib64")
set(FIND_LIBRARY_USE_LIB64_PATHS true)
endif()
endif()

include(GNUInstallDirs)

function(aws_prepare_shared_lib_exports target)
if (BUILD_SHARED_LIBS)
install(TARGETS ${target}
EXPORT ${target}-targets
ARCHIVE
DESTINATION ${LIBRARY_DIRECTORY}
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT Development
LIBRARY
DESTINATION ${LIBRARY_DIRECTORY}
DESTINATION ${CMAKE_INSTALL_LIBDIR}
NAMELINK_SKIP
COMPONENT Runtime
RUNTIME
DESTINATION ${RUNTIME_DIRECTORY}
DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT Runtime)
install(TARGETS ${target}
EXPORT ${target}-targets
LIBRARY
DESTINATION ${LIBRARY_DIRECTORY}
DESTINATION ${CMAKE_INSTALL_LIBDIR}
NAMELINK_ONLY
COMPONENT Development)
else()
install(TARGETS ${target}
EXPORT ${target}-targets
ARCHIVE DESTINATION ${LIBRARY_DIRECTORY}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT Development)
endif()
endfunction()
Expand Down
2 changes: 1 addition & 1 deletion cmake/CPackConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ endif()
# By default, we'll try to claim the cmake directory under the library directory
# and the aws include directory. We have to share both of these
set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION
/usr/${LIBRARY_DIRECTORY}/cmake
/usr/${CMAKE_INSTALL_LIBDIR}/cmake
/usr/include/aws)

# Include CPack, which generates the package target
Expand Down
3 changes: 3 additions & 0 deletions cmake/aws-c-common-config.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# make installed modules (e.g. AwsCFlags.cmake) available to dependencies
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/modules)

set(THREADS_PREFER_PTHREAD_FLAG ON)

if(WIN32 OR UNIX OR APPLE)
Expand Down