Skip to content

Commit

Permalink
Add function so all projects can set the same common CMake policies
Browse files Browse the repository at this point in the history
  • Loading branch information
graebm committed Aug 14, 2024
1 parent 15a9e48 commit 82fc2ba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
10 changes: 1 addition & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ project(aws-c-common LANGUAGES C VERSION 0.1.0)

message(STATUS "CMake ${CMAKE_VERSION}")

if (POLICY CMP0069)
cmake_policy(SET CMP0069 NEW) # Enable LTO/IPO if available in the compiler, see AwsCFlags
endif()

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 Down Expand Up @@ -189,7 +181,7 @@ file(GLOB COMMON_SRC
${AWS_COMMON_EXTERNAL_SRC}
)


aws_set_common_policies()
add_library(${PROJECT_NAME} ${COMMON_SRC})
aws_set_common_properties(${PROJECT_NAME} NO_WEXTRA)
aws_prepare_symbol_visibility_args(${PROJECT_NAME} "AWS_COMMON")
Expand Down
18 changes: 16 additions & 2 deletions cmake/AwsCFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ function(aws_check_posix_lfs extra_flags variable)
endif()
endfunction()

# This function sets common CMake policies.
# Call this before calling add_library() or add_executable().
function(aws_set_common_policies)
# Enable LTO/IPO if available in the compiler
if (POLICY CMP0069)
cmake_policy(SET CMP0069 NEW)
endif()

# Honor visibility properties for all target types
if (POLICY CMP0063)
cmake_policy(SET CMP0063 NEW)
endif()
endfunction()

# This function will set all common flags on a target
# Options:
# NO_WGNU: Disable -Wgnu
Expand Down Expand Up @@ -231,7 +245,6 @@ function(aws_set_common_properties target)

# try to check whether compiler supports LTO/IPO
if (POLICY CMP0069)
cmake_policy(SET CMP0069 NEW)
include(CheckIPOSupported OPTIONAL RESULT_VARIABLE ipo_check_exists)
if (ipo_check_exists)
check_ipo_supported(RESULT ipo_supported)
Expand All @@ -257,5 +270,6 @@ function(aws_set_common_properties target)
target_compile_definitions(${target} PRIVATE ${AWS_C_DEFINES_PRIVATE} PUBLIC ${AWS_C_DEFINES_PUBLIC})
set_target_properties(${target} PROPERTIES LINKER_LANGUAGE C C_STANDARD 99 C_STANDARD_REQUIRED ON)
set_target_properties(${target} PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${_ENABLE_LTO_EXPR}>)
set_target_properties(${target} PROPERTIES C_VISIBILITY_PRESET hidden CXX_VISIBILITY_PRESET hidden)
set_target_properties(${target} PROPERTIES C_VISIBILITY_PRESET hidden CXX_VISIBILITY_PRESET hidden
set_target_properties(${target} PROPERTIES VISIBILITY_INLINES_HIDDEN ON)
endfunction()

0 comments on commit 82fc2ba

Please sign in to comment.