From d9fa9912d0098fcfc45a00bfa21850171eee58a0 Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Tue, 4 Apr 2023 02:18:40 -0400 Subject: [PATCH 01/11] Disabled unused but set variable warnings in CMakeLists.txt --- CMakeLists.txt | 3 +++ test/test_lang_bind_helper.cpp | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 03d87cf16ac..49b551b399e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,6 +112,9 @@ else() # compilers that we still support. It is also harmless, unlike pessimizing moves. add_cxx_flag_if_supported(-Wno-redundant-move) + # MacOS Clang 14.0.3 started enabling unused-but-set-variables by default + add_cxx_flag_if_supported(-Wno-unused-but-set-variable) + # Ninja buffers output so we need to tell the compiler to use colors even though stdout isn't a tty. if("${CMAKE_GENERATOR}" STREQUAL "Ninja") add_cxx_flag_if_supported(-fdiagnostics-color) diff --git a/test/test_lang_bind_helper.cpp b/test/test_lang_bind_helper.cpp index 7335fc66996..cc98b6f353e 100644 --- a/test/test_lang_bind_helper.cpp +++ b/test/test_lang_bind_helper.cpp @@ -3986,7 +3986,7 @@ struct HandoverControl { while (m_handover != nullptr) m_changed.wait(lg); // std::cout << " -- put " << h << std::endl; - m_handover = move(h); + m_handover = std::move(h); m_changed.notify_all(); } void get(std::unique_ptr& h) @@ -3996,7 +3996,7 @@ struct HandoverControl { while (m_handover == nullptr) m_changed.wait(lg); // std::cout << " -- get " << m_handover << std::endl; - h = move(m_handover); + h = std::move(m_handover); m_handover = nullptr; m_changed.notify_all(); } @@ -4005,7 +4005,7 @@ struct HandoverControl { LockGuard lg(m_lock); if (m_handover == nullptr) return false; - h = move(m_handover); + h = std::move(m_handover); m_handover = nullptr; m_changed.notify_all(); return true; From 71bb665c65e881424d7388322c8f1b9c10e28e67 Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Tue, 4 Apr 2023 02:23:17 -0400 Subject: [PATCH 02/11] Updated changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d1a1f99b49..f5e09484d2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ ----------- ### Internals -* None. +* Fix compiler warnings with MacOS Clang 14.0.3 ([PR #6467](https://github.com/realm/realm-core/pull/6467)) ---------------------------------------------- From 74c74f4331f498517e63fef8257cf45f0c4a00f7 Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Tue, 4 Apr 2023 10:06:13 -0400 Subject: [PATCH 03/11] Fix warnings in existing files --- test/test_query.cpp | 2 -- test/test_shared.cpp | 3 --- 2 files changed, 5 deletions(-) diff --git a/test/test_query.cpp b/test/test_query.cpp index 72ac7996648..b25379965c0 100644 --- a/test/test_query.cpp +++ b/test/test_query.cpp @@ -2904,7 +2904,6 @@ TEST_IF(Query_StrIndex3, TEST_DURATION > 0) std::vector vec; - size_t n = 0; #if defined REALM_DEBUG || REALM_ANDROID for (int i = 0; i < 4; i++) { #else @@ -2924,7 +2923,6 @@ TEST_IF(Query_StrIndex3, TEST_DURATION > 0) ObjKey key = ttt.create_object().set_all(0, longstrings ? "AAAAAAAAAAAAAAAAAAAAAAAA" : "AA").get_key(); if (!longstrings) { - n++; vec.push_back(key); } } diff --git a/test/test_shared.cpp b/test/test_shared.cpp index 4a64de052ed..a1a113408d8 100644 --- a/test/test_shared.cpp +++ b/test/test_shared.cpp @@ -1841,13 +1841,10 @@ TEST(Shared_StringIndexBug3) } Random random(random_int()); // Seed from slow global generator - size_t transactions = 0; std::vector keys; for (size_t n = 0; n < 100; ++n) { const uint64_t action = random.draw_int_mod(1000); - transactions++; - if (action <= 500) { // delete random user auto tr = db->start_write(); From 6460bc9f471c9cfd55ce89c9f6a33364be7cf506 Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Tue, 4 Apr 2023 13:15:01 -0400 Subject: [PATCH 04/11] Remove global no-unused-but-set warnings and add back for parser files --- CMakeLists.txt | 14 ++++++++++++-- src/realm/parser/CMakeLists.txt | 13 ++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 49b551b399e..a2fd7b9153f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,17 @@ function(add_cxx_flag_if_supported flag) endif() endfunction() +function(check_if_cxx_compiler_flag_supported flag out_var) + if(flag MATCHES "^-Wno-") + # Compilers ignore unknown -Wno-foo flags, so look for -Wfoo instead. + string(REPLACE "-Wno-" "-W" check_flag ${flag}) + else() + set(check_flag ${flag}) + endif() + + check_cxx_compiler_flag(${check_flag} ${out_var}) +endfunction() + function(use_faster_linker) # If a linker has already been set, don't override. if ("${CMAKE_EXE_LINKER_FLAGS}" MATCHES "-fuse-ld=") @@ -112,8 +123,7 @@ else() # compilers that we still support. It is also harmless, unlike pessimizing moves. add_cxx_flag_if_supported(-Wno-redundant-move) - # MacOS Clang 14.0.3 started enabling unused-but-set-variables by default - add_cxx_flag_if_supported(-Wno-unused-but-set-variable) + check_if_cxx_compiler_flag_supported(-Wno-unused-but-set-variable HAS-Wno-unused-but-set-variable) # Ninja buffers output so we need to tell the compiler to use colors even though stdout isn't a tty. if("${CMAKE_GENERATOR}" STREQUAL "Ninja") diff --git a/src/realm/parser/CMakeLists.txt b/src/realm/parser/CMakeLists.txt index 39f2b42d786..9ca9e3a3998 100644 --- a/src/realm/parser/CMakeLists.txt +++ b/src/realm/parser/CMakeLists.txt @@ -33,6 +33,9 @@ endif() set(REALM_PARSER_SOURCES driver.cpp keypath_mapping.cpp +) # REALM_PARSER_SOURCES + +set(REALM_PARSER_GENERAED generated/query_flex.cpp generated/query_bison.cpp ) # REALM_PARSER_SOURCES @@ -56,13 +59,21 @@ set(REALM_PARSER_EXTRAS query_flex.ll ) +# Add custom warning flags for generated parser files +if(HAS-Wno-unused-but-set-variable) + foreach(SRC_ IN LISTS REALM_PARSER_GENERAED) + get_filename_component(SRC_BASENAME_ ${SRC_} NAME_WE) + set_source_files_properties(${SRC_} PROPERTIES COMPILE_OPTIONS "-Wno-unused-but-set-variable") + endforeach() +endif() + if(MSVC) set_source_files_properties(generated/query_flex.cpp PROPERTIES COMPILE_OPTIONS "/wd4018") else() set_source_files_properties(generated/query_flex.cpp PROPERTIES COMPILE_OPTIONS "-Wno-unreachable-code;-Wno-sign-compare") endif() -add_library(QueryParser STATIC ${REALM_PARSER_SOURCES} ${REALM_PARSER_HEADERS} ${REALM_PARSER_EXTRAS}) +add_library(QueryParser STATIC ${REALM_PARSER_SOURCES} ${REALM_PARSER_GENERAED} ${REALM_PARSER_HEADERS} ${REALM_PARSER_EXTRAS}) add_library(realm-parser ALIAS QueryParser) add_library(Realm::QueryParser ALIAS QueryParser) target_link_libraries(QueryParser PUBLIC Storage) From 8bb2ca7bcf54292c55d87f031e503276f429765e Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Tue, 4 Apr 2023 13:45:16 -0400 Subject: [PATCH 05/11] Disable the unused-but-set warning on the 3rd party Catch library --- CMakeLists.txt | 2 +- external/CMakeLists.txt | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 external/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index a2fd7b9153f..e90ba63163a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -313,7 +313,7 @@ elseif(APPLE AND NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin") endif() set(CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS ON CACHE BOOL "Enable Catch2's optional standard library stringmakers") -add_subdirectory(external/catch EXCLUDE_FROM_ALL) +add_subdirectory(external EXCLUDE_FROM_ALL) # Cmake does not let us easily set the deployment target per-target, but Catch2 # can use modern features because we only run tests on recent OS versions. diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt new file mode 100644 index 00000000000..114b722f220 --- /dev/null +++ b/external/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 3.15) + +add_cxx_flag_if_supported(-Wno-unused-but-set-variable) +add_subdirectory(catch) From e7292f53a656463e53416d86ad95bf30f75c1386 Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Wed, 5 Apr 2023 10:13:44 -0400 Subject: [PATCH 06/11] Updates from review and added append_source_file_compile_options function --- CMakeLists.txt | 24 ++++++++++++------------ src/realm/parser/CMakeLists.txt | 16 ++++++++++------ test/CMakeLists.txt | 3 ++- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e90ba63163a..67ee7e1b06d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,7 +43,7 @@ elseif(APPLE) set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) endif() -function(add_cxx_flag_if_supported flag) +function(check_if_cxx_compiler_flag_supported flag out_var) if(flag MATCHES "^-Wno-") # Compilers ignore unknown -Wno-foo flags, so look for -Wfoo instead. string(REPLACE "-Wno-" "-W" check_flag ${flag}) @@ -51,21 +51,23 @@ function(add_cxx_flag_if_supported flag) set(check_flag ${flag}) endif() - check_cxx_compiler_flag(${check_flag} HAVE${check_flag}) - if(HAVE${check_flag}) + check_cxx_compiler_flag(${check_flag} ${out_var}) +endfunction() + +function(add_cxx_flag_if_supported flag) + check_if_cxx_compiler_flag_supported(${flag} HAVE${flag}) + if(HAVE${flag}) add_compile_options($<$:${flag}>) endif() endfunction() -function(check_if_cxx_compiler_flag_supported flag out_var) - if(flag MATCHES "^-Wno-") - # Compilers ignore unknown -Wno-foo flags, so look for -Wfoo instead. - string(REPLACE "-Wno-" "-W" check_flag ${flag}) +function(append_source_file_compile_options file property) + get_source_file_property(SRC_PROPS_${file} ${file} COMPILE_OPTIONS) + if ("${SRC_PROPS_${file}}" STREQUAL "NOTFOUND" OR "${SRC_PROPS_${file}}" STREQUAL "") + set_source_files_properties(${file} PROPERTIES COMPILE_OPTIONS "${property}") else() - set(check_flag ${flag}) + set_source_files_properties(${file} PROPERTIES COMPILE_OPTIONS "${SRC_PROPS_${file}};${property}") endif() - - check_cxx_compiler_flag(${check_flag} ${out_var}) endfunction() function(use_faster_linker) @@ -123,8 +125,6 @@ else() # compilers that we still support. It is also harmless, unlike pessimizing moves. add_cxx_flag_if_supported(-Wno-redundant-move) - check_if_cxx_compiler_flag_supported(-Wno-unused-but-set-variable HAS-Wno-unused-but-set-variable) - # Ninja buffers output so we need to tell the compiler to use colors even though stdout isn't a tty. if("${CMAKE_GENERATOR}" STREQUAL "Ninja") add_cxx_flag_if_supported(-fdiagnostics-color) diff --git a/src/realm/parser/CMakeLists.txt b/src/realm/parser/CMakeLists.txt index 9ca9e3a3998..9738d50ab66 100644 --- a/src/realm/parser/CMakeLists.txt +++ b/src/realm/parser/CMakeLists.txt @@ -59,18 +59,22 @@ set(REALM_PARSER_EXTRAS query_flex.ll ) -# Add custom warning flags for generated parser files -if(HAS-Wno-unused-but-set-variable) +# Add custom warning flags for generated parser files if the flag is supported +set(PARSER_COMPILE_EXTRA -Wno-unused-but-set-variable) + +check_if_cxx_compiler_flag_supported(${PARSER_COMPILE_EXTRA} HAVE${PARSER_COMPILE_EXTRA}) + +if(HAVE${PARSER_COMPILE_EXTRA}) foreach(SRC_ IN LISTS REALM_PARSER_GENERAED) - get_filename_component(SRC_BASENAME_ ${SRC_} NAME_WE) - set_source_files_properties(${SRC_} PROPERTIES COMPILE_OPTIONS "-Wno-unused-but-set-variable") + append_source_file_compile_options(${SRC_} "${PARSER_COMPILE_EXTRA}") endforeach() endif() +# Append additional compile options to the generated/query_flex.cpp file if(MSVC) - set_source_files_properties(generated/query_flex.cpp PROPERTIES COMPILE_OPTIONS "/wd4018") + append_source_file_compile_options(generated/query_flex.cpp "/wd4018") else() - set_source_files_properties(generated/query_flex.cpp PROPERTIES COMPILE_OPTIONS "-Wno-unreachable-code;-Wno-sign-compare") + append_source_file_compile_options(generated/query_flex.cpp "-Wno-unreachable-code;-Wno-sign-compare") endif() add_library(QueryParser STATIC ${REALM_PARSER_SOURCES} ${REALM_PARSER_GENERAED} ${REALM_PARSER_HEADERS} ${REALM_PARSER_EXTRAS}) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f5ee6bcc9a8..bb11359e37d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -122,7 +122,8 @@ set(CORE_TESTS ${CORE_TEST_SOURCES} ${LARGE_TEST_SOURCES} ${FUZZY_TEST_SOURCES}) # FIXME: Benchmarks if (MSVC) - set_source_files_properties(test_query.cpp test_query_big.cpp PROPERTIES COMPILE_FLAGS /bigobj) + append_source_file_compile_options(test_query.cpp /bigobj) + append_source_file_compile_options(test_query_big.cpp /bigobj) endif() # Resources required for running the tests From ed0edf97ae5c0b934946a0346af2a2cf72f90bde Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Wed, 5 Apr 2023 16:05:38 -0400 Subject: [PATCH 07/11] Updates from review - beefed up append compile options function --- CMakeLists.txt | 32 ++++++++++++++++++++++++++------ src/realm/parser/CMakeLists.txt | 18 +++++------------- test/CMakeLists.txt | 3 +-- 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 67ee7e1b06d..47fc87593b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,13 +61,33 @@ function(add_cxx_flag_if_supported flag) endif() endfunction() -function(append_source_file_compile_options file property) - get_source_file_property(SRC_PROPS_${file} ${file} COMPILE_OPTIONS) - if ("${SRC_PROPS_${file}}" STREQUAL "NOTFOUND" OR "${SRC_PROPS_${file}}" STREQUAL "") - set_source_files_properties(${file} PROPERTIES COMPILE_OPTIONS "${property}") - else() - set_source_files_properties(${file} PROPERTIES COMPILE_OPTIONS "${SRC_PROPS_${file}};${property}") + +# Usage: append_source_file_compile_options(FILE FLAG ) +# or: append_source_file_compile_options(FILES ... FLAGS ...) +function(append_source_file_compile_options) + set(options) + set(args) + set(list_args FILES FLAGS) + cmake_parse_arguments(append_options "${options}" "${args}" "${list_args}" ${ARGN}) + if ("${append_options_FILES}" STREQUAL "") + message(FATAL_ERROR "Missing FILES argument for append_source_file_compile_options") + endif() + if ("${append_options_FLAGS}" STREQUAL "") + message(FATAL_ERROR "Missing FLAGS argument for append_source_file_compile_options") endif() + foreach(FLAG_ IN LISTS append_options_FLAGS) + check_if_cxx_compiler_flag_supported(${FLAG_} HAVE${FLAG_}) + if (HAVE${FLAG_}) + foreach(SRC_ IN LISTS append_options_FILES) + get_source_file_property(SRC_PROPS_${SRC_} ${SRC_} COMPILE_OPTIONS) + if ("${SRC_PROPS_${SRC_}}" STREQUAL "NOTFOUND" OR "${SRC_PROPS_${SRC_}}" STREQUAL "") + set_source_files_properties(${SRC_} PROPERTIES COMPILE_OPTIONS "${FLAG_}") + elseif(NOT "${FLAG_}" IN_LIST SRC_PROPS_${SRC_}) + set_source_files_properties(${SRC_} PROPERTIES COMPILE_OPTIONS "${SRC_PROPS_${SRC_}};${FLAG_}") + endif() + endforeach() + endif() + endforeach() endfunction() function(use_faster_linker) diff --git a/src/realm/parser/CMakeLists.txt b/src/realm/parser/CMakeLists.txt index 9738d50ab66..12dda0ada14 100644 --- a/src/realm/parser/CMakeLists.txt +++ b/src/realm/parser/CMakeLists.txt @@ -35,7 +35,7 @@ set(REALM_PARSER_SOURCES keypath_mapping.cpp ) # REALM_PARSER_SOURCES -set(REALM_PARSER_GENERAED +set(REALM_PARSER_GENERATED generated/query_flex.cpp generated/query_bison.cpp ) # REALM_PARSER_SOURCES @@ -60,24 +60,16 @@ set(REALM_PARSER_EXTRAS ) # Add custom warning flags for generated parser files if the flag is supported -set(PARSER_COMPILE_EXTRA -Wno-unused-but-set-variable) - -check_if_cxx_compiler_flag_supported(${PARSER_COMPILE_EXTRA} HAVE${PARSER_COMPILE_EXTRA}) - -if(HAVE${PARSER_COMPILE_EXTRA}) - foreach(SRC_ IN LISTS REALM_PARSER_GENERAED) - append_source_file_compile_options(${SRC_} "${PARSER_COMPILE_EXTRA}") - endforeach() -endif() +append_source_file_compile_options(FILES ${REALM_PARSER_GENERATED} FLAGS -Wno-unused-but-set-variable) # Append additional compile options to the generated/query_flex.cpp file if(MSVC) - append_source_file_compile_options(generated/query_flex.cpp "/wd4018") + append_source_file_compile_options(FILES generated/query_flex.cpp FLAGS /wd4018) else() - append_source_file_compile_options(generated/query_flex.cpp "-Wno-unreachable-code;-Wno-sign-compare") + append_source_file_compile_options(FILES generated/query_flex.cpp FLAGS -Wno-unreachable-code -Wno-sign-compare) endif() -add_library(QueryParser STATIC ${REALM_PARSER_SOURCES} ${REALM_PARSER_GENERAED} ${REALM_PARSER_HEADERS} ${REALM_PARSER_EXTRAS}) +add_library(QueryParser STATIC ${REALM_PARSER_SOURCES} ${REALM_PARSER_GENERATED} ${REALM_PARSER_HEADERS} ${REALM_PARSER_EXTRAS}) add_library(realm-parser ALIAS QueryParser) add_library(Realm::QueryParser ALIAS QueryParser) target_link_libraries(QueryParser PUBLIC Storage) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index bb11359e37d..00dee4e77b3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -122,8 +122,7 @@ set(CORE_TESTS ${CORE_TEST_SOURCES} ${LARGE_TEST_SOURCES} ${FUZZY_TEST_SOURCES}) # FIXME: Benchmarks if (MSVC) - append_source_file_compile_options(test_query.cpp /bigobj) - append_source_file_compile_options(test_query_big.cpp /bigobj) + append_source_file_compile_options(FILES test_query.cpp test_query_big.cpp FLAGS /bigobj) endif() # Resources required for running the tests From 9563e27cb268b75dc3533bbfff7d785354459322 Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Wed, 5 Apr 2023 16:38:52 -0400 Subject: [PATCH 08/11] Some simplification of append compile options function --- CMakeLists.txt | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 47fc87593b2..25d4016d5c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,28 +62,27 @@ function(add_cxx_flag_if_supported flag) endfunction() -# Usage: append_source_file_compile_options(FILE FLAG ) -# or: append_source_file_compile_options(FILES ... FLAGS ...) +# Usage: append_source_file_compile_options(FILES [ ...] FLAGS [ ...]) function(append_source_file_compile_options) set(options) set(args) set(list_args FILES FLAGS) cmake_parse_arguments(append_options "${options}" "${args}" "${list_args}" ${ARGN}) - if ("${append_options_FILES}" STREQUAL "") + if (NOT append_options_FILES) message(FATAL_ERROR "Missing FILES argument for append_source_file_compile_options") endif() - if ("${append_options_FLAGS}" STREQUAL "") + if (NOT append_options_FLAGS) message(FATAL_ERROR "Missing FLAGS argument for append_source_file_compile_options") endif() foreach(FLAG_ IN LISTS append_options_FLAGS) - check_if_cxx_compiler_flag_supported(${FLAG_} HAVE${FLAG_}) - if (HAVE${FLAG_}) + check_if_cxx_compiler_flag_supported(${FLAG_} FLAG_SUPPORTED) + if (FLAG_SUPPORTED) foreach(SRC_ IN LISTS append_options_FILES) - get_source_file_property(SRC_PROPS_${SRC_} ${SRC_} COMPILE_OPTIONS) - if ("${SRC_PROPS_${SRC_}}" STREQUAL "NOTFOUND" OR "${SRC_PROPS_${SRC_}}" STREQUAL "") + get_source_file_property(OLD_OPTS ${SRC_} COMPILE_OPTIONS) + if (NOT OLD_OPTS) set_source_files_properties(${SRC_} PROPERTIES COMPILE_OPTIONS "${FLAG_}") - elseif(NOT "${FLAG_}" IN_LIST SRC_PROPS_${SRC_}) - set_source_files_properties(${SRC_} PROPERTIES COMPILE_OPTIONS "${SRC_PROPS_${SRC_}};${FLAG_}") + elseif(NOT "${FLAG_}" IN_LIST OLD_OPTS) + set_source_files_properties(${SRC_} PROPERTIES COMPILE_OPTIONS "${OLD_OPTS};${FLAG_}") endif() endforeach() endif() From ff727ad488ca652d903b867f54725c949e4a2c93 Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Wed, 5 Apr 2023 20:46:55 -0400 Subject: [PATCH 09/11] Added status back to append compile options for debug --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 25d4016d5c1..90e11d8342a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,8 +81,10 @@ function(append_source_file_compile_options) get_source_file_property(OLD_OPTS ${SRC_} COMPILE_OPTIONS) if (NOT OLD_OPTS) set_source_files_properties(${SRC_} PROPERTIES COMPILE_OPTIONS "${FLAG_}") + message(STATUS "Adding '${FLAG_}' for '${SRC_}' - options: ${OLD_OPTS}") elseif(NOT "${FLAG_}" IN_LIST OLD_OPTS) set_source_files_properties(${SRC_} PROPERTIES COMPILE_OPTIONS "${OLD_OPTS};${FLAG_}") + message(STATUS "Appending '${FLAG_}' for '${SRC_}' - options: ${OLD_OPTS}") endif() endforeach() endif() From fab83751e3e835dd19779c098efb61775165c7eb Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Wed, 5 Apr 2023 21:24:16 -0400 Subject: [PATCH 10/11] check compile flag variable is global --- CMakeLists.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 90e11d8342a..c86fa4869ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,5 @@ cmake_minimum_required(VERSION 3.15) +message(STATUS "CMake version: ${CMAKE_VERSION}") set(CMAKE_BUILD_TYPE Debug CACHE STRING "") project(RealmCore) @@ -61,7 +62,6 @@ function(add_cxx_flag_if_supported flag) endif() endfunction() - # Usage: append_source_file_compile_options(FILES [ ...] FLAGS [ ...]) function(append_source_file_compile_options) set(options) @@ -75,8 +75,9 @@ function(append_source_file_compile_options) message(FATAL_ERROR "Missing FLAGS argument for append_source_file_compile_options") endif() foreach(FLAG_ IN LISTS append_options_FLAGS) - check_if_cxx_compiler_flag_supported(${FLAG_} FLAG_SUPPORTED) - if (FLAG_SUPPORTED) + message(STATUS "Append compile flag: ${FLAG_}") + check_if_cxx_compiler_flag_supported(${FLAG_} HAVE${FLAG_}) + if (HAVE${FLAG_}) foreach(SRC_ IN LISTS append_options_FILES) get_source_file_property(OLD_OPTS ${SRC_} COMPILE_OPTIONS) if (NOT OLD_OPTS) From c404a42c36b69186c303c3e00e9f4f1449e2a273 Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Wed, 5 Apr 2023 21:49:02 -0400 Subject: [PATCH 11/11] Cleanup after debugging --- CMakeLists.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c86fa4869ed..e1895b8f32b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,8 @@ elseif(APPLE) set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) endif() +# Sets/clears the {FLAG} variable if the compiler flag is supported or not +# The compiler flag check is only performed once and the value is cached as the out variable name function(check_if_cxx_compiler_flag_supported flag out_var) if(flag MATCHES "^-Wno-") # Compilers ignore unknown -Wno-foo flags, so look for -Wfoo instead. @@ -75,17 +77,14 @@ function(append_source_file_compile_options) message(FATAL_ERROR "Missing FLAGS argument for append_source_file_compile_options") endif() foreach(FLAG_ IN LISTS append_options_FLAGS) - message(STATUS "Append compile flag: ${FLAG_}") check_if_cxx_compiler_flag_supported(${FLAG_} HAVE${FLAG_}) if (HAVE${FLAG_}) foreach(SRC_ IN LISTS append_options_FILES) get_source_file_property(OLD_OPTS ${SRC_} COMPILE_OPTIONS) if (NOT OLD_OPTS) set_source_files_properties(${SRC_} PROPERTIES COMPILE_OPTIONS "${FLAG_}") - message(STATUS "Adding '${FLAG_}' for '${SRC_}' - options: ${OLD_OPTS}") elseif(NOT "${FLAG_}" IN_LIST OLD_OPTS) set_source_files_properties(${SRC_} PROPERTIES COMPILE_OPTIONS "${OLD_OPTS};${FLAG_}") - message(STATUS "Appending '${FLAG_}' for '${SRC_}' - options: ${OLD_OPTS}") endif() endforeach() endif()