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

Update CMake to 3.9 #1159

Merged
merged 22 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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.4.1)
cmake_minimum_required(VERSION 3.9)

# AWS lib
set(path_to_common "${CMAKE_CURRENT_LIST_DIR}/../../../../..")
Expand Down
7 changes: 1 addition & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0.

cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.9)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comment about WHY we're picking CMake 3.9. Because it's the latest supported version in ... RHEL5? Amazon Linux 1?

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


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
17 changes: 8 additions & 9 deletions cmake/AwsCFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
include(CheckCCompilerFlag)
include(CheckIncludeFile)
include(CheckSymbolExists)
include(CMakeParseArguments) # needed for CMake v3.4 and lower

option(AWS_ENABLE_LTO "Enables LTO on libraries. Ensure this is set on all consumed targets, or linking will fail" OFF)
option(LEGACY_COMPILER_SUPPORT "This enables builds with compiler versions such as gcc 4.1.2. This is not a 'supported' feature; it's just a best effort." OFF)
Expand Down Expand Up @@ -173,6 +172,7 @@ function(aws_set_common_properties target)
set_property(TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--exclude-libs,libcrypto.a")
endif()


endif()

check_include_file(stdint.h HAS_STDINT)
Expand Down Expand Up @@ -231,7 +231,6 @@ function(aws_set_common_properties target)

# try to check whether compiler supports LTO/IPO
if (POLICY CMP0069)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we're not trying to rewrite the world, but since this touches a POLICY ... we can replace this if (POLICY CMP0069) block with simpler code

        # check whether compiler supports LTO/IPO
        include(CheckIPOSupported)
        check_ipo_supported(RESULT ipo_supported)
        if (ipo_supported)
            message(STATUS "Enabling IPO/LTO for Release builds")
        else()
            message(STATUS "AWS_ENABLE_LTO is enabled, but cmake/compiler does not support it, disabling")
            set(_ENABLE_LTO_EXPR OFF)
        endif()

see: https://cmake.org/cmake/help/v3.9/policy/CMP0069.html

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 @@ -247,13 +246,6 @@ function(aws_set_common_properties target)
set(_ENABLE_LTO_EXPR OFF)
endif()

if(BUILD_SHARED_LIBS)
if (NOT MSVC)
# this should only be set when building shared libs.
list(APPEND AWS_C_FLAGS "-fvisibility=hidden")
endif()
endif()

if(AWS_ENABLE_TRACING)
target_link_libraries(${target} PRIVATE ittnotify)
else()
Expand All @@ -264,4 +256,11 @@ 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}>)

# Don't hide symbols in Debug builds.
# We do this so that backtraces are more likely to show function names.
# We mostly use backtraces to diagnose memory leaks.
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
set_target_properties(${target} PROPERTIES C_VISIBILITY_PRESET hidden CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN ON)
endif ()
endfunction()
9 changes: 6 additions & 3 deletions cmake/AwsTestHarness.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ function(generate_test_driver driver_exe_name)
add_executable(${driver_exe_name} ${CMAKE_CURRENT_BINARY_DIR}/test_runner.c ${TESTS})
aws_set_common_properties(${driver_exe_name} NO_WEXTRA NO_PEDANTIC)

# Some versions of CMake (3.9-3.11) generate a test_runner.c file with
# a strncpy() call that triggers the "stringop-overflow" warning in GCC 8.1+
# This warning doesn't exist until GCC 7 though, so test for it before disabling.
# Some versions of CMake (3.9-3.11) generate a test_runner.c file with
# a strncpy() call that triggers the "stringop-overflow" warning in GCC 8.1+
# This warning doesn't exist until GCC 7 though, so test for it before disabling.
if (NOT MSVC)
check_c_compiler_flag(-Wno-stringop-overflow HAS_WNO_STRINGOP_OVERFLOW)
if (HAS_WNO_STRINGOP_OVERFLOW)
Expand All @@ -57,6 +57,9 @@ function(generate_test_driver driver_exe_name)
target_compile_definitions(${driver_exe_name} PRIVATE AWS_UNSTABLE_TESTING_API=1)
target_include_directories(${driver_exe_name} PRIVATE ${CMAKE_CURRENT_LIST_DIR})

# Export symbols so that backtraces are more likely to show function names.
set_target_properties(${driver_exe_name} PROPERTIES ENABLE_EXPORTS ON)

foreach(name IN LISTS TEST_CASES)
add_test(${name} ${driver_exe_name} "${name}")
set_tests_properties("${name}" PROPERTIES SKIP_RETURN_CODE ${SKIP_RETURN_CODE_VALUE})
Expand Down
11 changes: 5 additions & 6 deletions tests/memtrace_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static int s_test_memtrace_stacks(struct aws_allocator *allocator, void *ctx) {
/* only bother to run this test if the platform can do a backtrace */
void *probe_stack[1];
if (!aws_backtrace(probe_stack, 1)) {
return 0;
return AWS_OP_SKIP;
}

test_logger_init(&s_test_logger, allocator, AWS_LL_TRACE, 0);
Expand Down Expand Up @@ -146,27 +146,26 @@ static int s_test_memtrace_stacks(struct aws_allocator *allocator, void *ctx) {
/* if this is not a debug build, there may not be symbols, so the test cannot
* verify if a best effort was made */
#if defined(DEBUG_BUILD)
/* fprintf(stderr, "%s\n", test_logger->log_buffer.buffer); */
fprintf(stderr, "%s\n", test_logger->log_buffer.buffer);
char s_alloc_1_addr[32];
char s_alloc_2_addr[32];
char s_alloc_3_addr[32];
char s_alloc_4_addr[32];
# if defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable : 4054) /* type cast function pointer to data pointer */
# endif

snprintf(s_alloc_1_addr, AWS_ARRAY_SIZE(s_alloc_1_addr), "0x%tx", (uintptr_t)(void *)s_alloc_1);
snprintf(s_alloc_2_addr, AWS_ARRAY_SIZE(s_alloc_2_addr), "0x%tx", (uintptr_t)(void *)s_alloc_2);
snprintf(s_alloc_3_addr, AWS_ARRAY_SIZE(s_alloc_3_addr), "0x%tx", (uintptr_t)(void *)s_alloc_3);
snprintf(s_alloc_4_addr, AWS_ARRAY_SIZE(s_alloc_4_addr), "0x%tx", (uintptr_t)(void *)s_alloc_4);
# pragma warning(pop)
# endif /* defined(_MSC_VER) */

const char *log_buffer = (const char *)test_logger->log_buffer.buffer;
ASSERT_TRUE(strstr(log_buffer, "s_alloc_1") || strstr(log_buffer, s_alloc_1_addr));
ASSERT_TRUE(strstr(log_buffer, "s_alloc_2") || strstr(log_buffer, s_alloc_2_addr));
ASSERT_TRUE(strstr(log_buffer, "s_alloc_3") || strstr(log_buffer, s_alloc_3_addr));
ASSERT_TRUE(strstr(log_buffer, "s_alloc_4") || strstr(log_buffer, s_alloc_4_addr));
#endif
#endif /* DEBUG_BUILD */

/* reset log */
aws_byte_buf_reset(&test_logger->log_buffer, true);
Expand Down
Loading