diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dc1a62ae14..f48b3c9b8ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ ----------- ### Internals -* None. +* Fix compiler warnings with MacOS Clang 14.0.3 ([PR #6467](https://github.com/realm/realm-core/pull/6467)) ---------------------------------------------- diff --git a/CMakeLists.txt b/CMakeLists.txt index 03d87cf16ac..e1895b8f32b 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) @@ -43,7 +44,9 @@ elseif(APPLE) set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) endif() -function(add_cxx_flag_if_supported flag) +# 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. string(REPLACE "-Wno-" "-W" check_flag ${flag}) @@ -51,12 +54,43 @@ 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() +# 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 (NOT append_options_FILES) + message(FATAL_ERROR "Missing FILES argument for append_source_file_compile_options") + endif() + 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_}) + 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_}") + elseif(NOT "${FLAG_}" IN_LIST OLD_OPTS) + set_source_files_properties(${SRC_} PROPERTIES COMPILE_OPTIONS "${OLD_OPTS};${FLAG_}") + endif() + endforeach() + endif() + endforeach() +endfunction() + function(use_faster_linker) # If a linker has already been set, don't override. if ("${CMAKE_EXE_LINKER_FLAGS}" MATCHES "-fuse-ld=") @@ -300,7 +334,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) diff --git a/src/realm/parser/CMakeLists.txt b/src/realm/parser/CMakeLists.txt index 39f2b42d786..12dda0ada14 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_GENERATED generated/query_flex.cpp generated/query_bison.cpp ) # REALM_PARSER_SOURCES @@ -56,13 +59,17 @@ set(REALM_PARSER_EXTRAS query_flex.ll ) +# Add custom warning flags for generated parser files if the flag is supported +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) - set_source_files_properties(generated/query_flex.cpp PROPERTIES COMPILE_OPTIONS "/wd4018") + append_source_file_compile_options(FILES generated/query_flex.cpp FLAGS /wd4018) else() - set_source_files_properties(generated/query_flex.cpp PROPERTIES COMPILE_OPTIONS "-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_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 f5ee6bcc9a8..00dee4e77b3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -122,7 +122,7 @@ 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(FILES test_query.cpp test_query_big.cpp FLAGS /bigobj) endif() # Resources required for running the tests 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; 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();