diff --git a/CMake/external_fastdds.cmake b/CMake/external_fastdds.cmake index 856e0dbfc7..7cd817544a 100644 --- a/CMake/external_fastdds.cmake +++ b/CMake/external_fastdds.cmake @@ -67,7 +67,10 @@ function(get_fastdds) message(CHECK_PASS "Done") endfunction() +string(REPLACE "${ADDITIONAL_COMPILER_FLAGS}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +string(REPLACE "${ADDITIONAL_COMPILER_FLAGS}" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") # Trigger the FastDDS build get_fastdds() - +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ADDITIONAL_COMPILER_FLAGS}") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ADDITIONAL_COMPILER_FLAGS}") diff --git a/CMake/external_foonathan_memory.cmake b/CMake/external_foonathan_memory.cmake index f6c4938267..2bd26fe1c6 100644 --- a/CMake/external_foonathan_memory.cmake +++ b/CMake/external_foonathan_memory.cmake @@ -41,4 +41,10 @@ function(get_foonathan_memory) endfunction() +string(REPLACE "${ADDITIONAL_COMPILER_FLAGS}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +string(REPLACE "${ADDITIONAL_COMPILER_FLAGS}" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") + get_foonathan_memory() + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ADDITIONAL_COMPILER_FLAGS}") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ADDITIONAL_COMPILER_FLAGS}") diff --git a/CMake/external_json.cmake b/CMake/external_json.cmake index 69c84ffeec..5c55114e7a 100644 --- a/CMake/external_json.cmake +++ b/CMake/external_json.cmake @@ -46,5 +46,10 @@ function(get_nlohmann_json) endfunction() +string(REPLACE "${ADDITIONAL_COMPILER_FLAGS}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +string(REPLACE "${ADDITIONAL_COMPILER_FLAGS}" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") # Trigger the build get_nlohmann_json() + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ADDITIONAL_COMPILER_FLAGS}") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ADDITIONAL_COMPILER_FLAGS}") diff --git a/CMake/external_libcurl.cmake b/CMake/external_libcurl.cmake index 2fce83548d..64f57b178a 100644 --- a/CMake/external_libcurl.cmake +++ b/CMake/external_libcurl.cmake @@ -1,7 +1,7 @@ if(CHECK_FOR_UPDATES) - set(FLAGS_ORIGIN "${CMAKE_C_FLAGS}") - string(REPLACE "-Werror" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") # -Werror causes libcurl build to fail + string(REPLACE "${ADDITIONAL_COMPILER_FLAGS}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + string(REPLACE "${ADDITIONAL_COMPILER_FLAGS}" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") include(ExternalProject) message(STATUS "Building libcurl enabled") @@ -64,5 +64,6 @@ if(CHECK_FOR_UPDATES) endif() endif() - set(CMAKE_C_FLAGS "${FLAGS_ORIGIN}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ADDITIONAL_COMPILER_FLAGS}") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ADDITIONAL_COMPILER_FLAGS}") endif() #CHECK_FOR_UPDATES diff --git a/CMake/unix_config.cmake b/CMake/unix_config.cmake index dbb4cc9a10..e05bfc59b7 100644 --- a/CMake/unix_config.cmake +++ b/CMake/unix_config.cmake @@ -71,12 +71,10 @@ macro(os_set_flags) # see https://readthedocs.intel.com/SecureCodingStandards/2023.Q2.0/compiler/c-cpp/ for more details if (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|armv7l") # Jetson system, some flags are not recognized - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat -Wformat-security -fPIC -D_FORTIFY_SOURCE=2 -fstack-protector") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat -Wformat-security -fPIC -D_FORTIFY_SOURCE=2 -fstack-protector") + set(ADDITIONAL_COMPILER_FLAGS "-Wformat -Wformat-security -fPIC -D_FORTIFY_SOURCE=2 -fstack-protector") else() #‘-mfunction-return’ and ‘-fcf-protection’ are not compatible, so specifing -fcf-protection=none - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat -Wformat-security -fPIC -D_FORTIFY_SOURCE=2 -fcf-protection=none -mfunction-return=thunk -mindirect-branch=thunk -mindirect-branch-register -fstack-protector") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat -Wformat-security -fPIC -D_FORTIFY_SOURCE=2 -fcf-protection=none -mfunction-return=thunk -mindirect-branch=thunk -mindirect-branch-register -fstack-protector") + set(ADDITIONAL_COMPILER_FLAGS "-Wformat -Wformat-security -fPIC -D_FORTIFY_SOURCE=2 -fcf-protection=none -mfunction-return=thunk -mindirect-branch=thunk -mindirect-branch-register -fstack-protector") endif() set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -pie") @@ -85,9 +83,11 @@ macro(os_set_flags) message(STATUS "Configuring for Debug build") else() # Release, RelWithDebInfo, or multi configuration generator is being used (aka not specifing build type, or building with VS) message(STATUS "Configuring for Release build") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -z noexecstack -Wl,-z,relro,-z,now -fstack-protector-strong") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -z noexecstack -Wl,-z,relro,-z,now -fstack-protector-strong") + set(ADDITIONAL_COMPILER_FLAGS "${ADDITIONAL_COMPILER_FLAGS} -Werror -z noexecstack -Wl,-z,relro,-z,now -fstack-protector-strong") endif() + + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ADDITIONAL_COMPILER_FLAGS}") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ADDITIONAL_COMPILER_FLAGS}") ################# diff --git a/CMake/windows_config.cmake b/CMake/windows_config.cmake index 614c7e9f96..97244907e2 100644 --- a/CMake/windows_config.cmake +++ b/CMake/windows_config.cmake @@ -55,20 +55,19 @@ macro(os_set_flags) # see https://readthedocs.intel.com/SecureCodingStandards/2023.Q2.0/compiler/c-cpp/ for more details - - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Gy /DYNAMICBASE /GS /wd4101") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Gy /DYNAMICBASE /GS /wd4101") + set(ADDITIONAL_COMPILER_FLAGS "/Gy /DYNAMICBASE /GS /wd4101") if(CMAKE_BUILD_TYPE STREQUAL "Debug") message(STATUS "Configuring for Debug build") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") else() # Release, RelWithDebInfo, or multi configuration generator is being used (aka not specifing build type, or building with VS) message(STATUS "Configuring for Release build") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX /sdl") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX /sdl") + set(ADDITIONAL_COMPILER_FLAGS "${ADDITIONAL_COMPILER_FLAGS} /WX /sdl") set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} /INCREMENTAL:NO /LTCG /NXCOMPAT") # ignoring '/INCREMENTAL' due to '/LTCG' specification endif() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ADDITIONAL_COMPILER_FLAGS}") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ADDITIONAL_COMPILER_FLAGS}") + ################# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj /wd4819") diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index c70314062e..6bf02b578e 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -1,5 +1,8 @@ string(REPLACE ${PROJECT_SOURCE_DIR}/ "" _rel_path ${CMAKE_CURRENT_LIST_DIR}) +string(REPLACE "${ADDITIONAL_COMPILER_FLAGS}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +string(REPLACE "${ADDITIONAL_COMPILER_FLAGS}" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") + include(CMake/external_json.cmake) add_subdirectory( "${CMAKE_CURRENT_LIST_DIR}/rsutils" ) @@ -18,3 +21,5 @@ if( BUILD_WITH_DDS ) add_subdirectory( "${CMAKE_CURRENT_LIST_DIR}/realdds" ) endif() +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ADDITIONAL_COMPILER_FLAGS}") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ADDITIONAL_COMPILER_FLAGS}")