Skip to content

Commit

Permalink
remove additional flags from third party
Browse files Browse the repository at this point in the history
  • Loading branch information
AviaAv committed Sep 26, 2024
1 parent 8d8daa9 commit 97fb665
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 16 deletions.
5 changes: 4 additions & 1 deletion CMake/external_fastdds.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
6 changes: 6 additions & 0 deletions CMake/external_foonathan_memory.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
5 changes: 5 additions & 0 deletions CMake/external_json.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
7 changes: 4 additions & 3 deletions CMake/external_libcurl.cmake
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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
12 changes: 6 additions & 6 deletions CMake/unix_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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}")

#################

Expand Down
11 changes: 5 additions & 6 deletions CMake/windows_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 5 additions & 0 deletions third-party/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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" )
Expand All @@ -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}")

0 comments on commit 97fb665

Please sign in to comment.