diff --git a/CMakeLists.txt b/CMakeLists.txt index 67b80f7f3fc4a..6f1d07c582908 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,7 +50,13 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT CMAKE_HOST_APPLE) # So disable this tool check in further enable_language() commands. set(CMAKE_PLATFORM_HAS_INSTALLNAME FALSE) endif() +set(APPEND_CPPFLAGS "" CACHE STRING "Preprocessor flags that are appended to the flags added by the build system.") +set(APPEND_CFLAGS "" CACHE STRING "C compiler flags that are appended to the flags added by the build system.") +set(APPEND_CXXFLAGS "" CACHE STRING "(Objective) C++ compiler flags that are appended to the flags added by the build system.") +set(APPEND_LDFLAGS "" CACHE STRING "Linker flags that are appended to the flags added by the build system.") +set(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX ${PROJECT_SOURCE_DIR}/cmake/module/OverrideCXX.cmake) enable_language(CXX) +unset(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) @@ -165,14 +171,6 @@ cmake_dependent_option(ENABLE_FUZZ "Build for fuzzing. Enabling this will disabl option(INSTALL_MAN "Install man pages." ON) -set(APPEND_CPPFLAGS "" CACHE STRING "Preprocessor flags that are appended to the flags added by the build system.") -set(APPEND_CFLAGS "" CACHE STRING "C compiler flags that are appended to the flags added by the build system.") -set(APPEND_CXXFLAGS "" CACHE STRING "(Objective) C++ compiler flags that are appended to the flags added by the build system.") -set(APPEND_LDFLAGS "" CACHE STRING "Linker flags that are appended to the flags added by the build system.") -string(APPEND CMAKE_CXX_COMPILE_OBJECT " ${APPEND_CPPFLAGS} ${APPEND_CXXFLAGS}") -string(APPEND CMAKE_CXX_CREATE_SHARED_LIBRARY " ${APPEND_LDFLAGS}") -string(APPEND CMAKE_CXX_LINK_EXECUTABLE " ${APPEND_LDFLAGS}") - set(configure_warnings) include(CheckPIESupported) diff --git a/cmake/module/OverrideCXX.cmake b/cmake/module/OverrideCXX.cmake new file mode 100644 index 0000000000000..9407682a2ec16 --- /dev/null +++ b/cmake/module/OverrideCXX.cmake @@ -0,0 +1,15 @@ +# Copyright (c) 2024-present The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or https://opensource.org/license/mit/. + +if(NOT "${APPEND_CPPFLAGS}${APPEND_CXXFLAGS}" STREQUAL "") + set(CMAKE_CXX_COMPILE_OBJECT + " ${APPEND_CPPFLAGS} ${APPEND_CXXFLAGS} -o -c " + ) +endif() + +if(NOT "${APPEND_LDFLAGS}" STREQUAL "") + set(CMAKE_CXX_LINK_EXECUTABLE + " ${APPEND_LDFLAGS} -o " + ) +endif() diff --git a/cmake/module/OverrideOBJCXX.cmake b/cmake/module/OverrideOBJCXX.cmake new file mode 100644 index 0000000000000..31c857d99785a --- /dev/null +++ b/cmake/module/OverrideOBJCXX.cmake @@ -0,0 +1,9 @@ +# Copyright (c) 2024-present The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or https://opensource.org/license/mit/. + +if(NOT "${APPEND_CPPFLAGS}${APPEND_CXXFLAGS}" STREQUAL "") + set(CMAKE_OBJCXX_COMPILE_OBJECT + " -x objective-c++ ${APPEND_CPPFLAGS} ${APPEND_CXXFLAGS} -o -c " + ) +endif() diff --git a/src/qt/CMakeLists.txt b/src/qt/CMakeLists.txt index 6f8a95d305333..d1ad7d966edd0 100644 --- a/src/qt/CMakeLists.txt +++ b/src/qt/CMakeLists.txt @@ -18,12 +18,13 @@ find_package(Qt5 5.11.3 MODULE REQUIRED unset(qt_components) if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + set(CMAKE_USER_MAKE_RULES_OVERRIDE_OBJCXX ${PROJECT_SOURCE_DIR}/cmake/module/OverrideOBJCXX.cmake) enable_language(OBJCXX) + unset(CMAKE_USER_MAKE_RULES_OVERRIDE_OBJCXX) set(CMAKE_OBJCXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") set(CMAKE_OBJCXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") set(CMAKE_OBJCXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") set(CMAKE_OBJCXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}") - string(APPEND CMAKE_OBJCXX_COMPILE_OBJECT " ${APPEND_CPPFLAGS} ${APPEND_CXXFLAGS}") endif() function(import_plugins target)