Skip to content

Commit

Permalink
add helper function, unignore warnings on dds target
Browse files Browse the repository at this point in the history
  • Loading branch information
AviaAv committed Oct 28, 2024
1 parent 24c4dcc commit a64cc1f
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 26 deletions.
5 changes: 0 additions & 5 deletions CMake/external_fastdds.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ function(get_fastdds)

add_library(dds INTERFACE)
target_link_libraries( dds INTERFACE fastcdr fastrtps )
if (MSVC)
target_compile_options( dds INTERFACE "/W0" )
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options( dds INTERFACE "-w" )
endif()

add_definitions(-DBUILD_WITH_DDS)

Expand Down
7 changes: 3 additions & 4 deletions CMake/external_libcurl.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
if(CHECK_FOR_UPDATES)

string(REPLACE "${SECURITY_COMPILER_FLAGS}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") # remove flags
string(REPLACE "${SECURITY_COMPILER_FLAGS}" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
pop_security_flags() # remove security flags

include(ExternalProject)
message(STATUS "Building libcurl enabled")

Expand Down Expand Up @@ -63,6 +63,5 @@ if(CHECK_FOR_UPDATES)
endif()
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SECURITY_COMPILER_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SECURITY_COMPILER_FLAGS}")
push_security_flags()
endif() #CHECK_FOR_UPDATES
20 changes: 20 additions & 0 deletions CMake/security_flags_helper_functions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
macro(push_security_flags) # remove security flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SECURITY_COMPILER_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SECURITY_COMPILER_FLAGS}")
endmacro()

macro(pop_security_flags) # append security flags
string(REPLACE "${SECURITY_COMPILER_FLAGS}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE "${SECURITY_COMPILER_FLAGS}" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
endmacro()

macro(set_security_flags_for_executable) # replace flag fPIC (Position-Independent Code) with fPIE (Position-Independent Executable)
string(REPLACE "-fPIC" "-fPIE" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE "-fPIC" "-fPIE" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
endmacro()

macro(unset_security_flags_for_executable) # replace flag fPIE (Position-Independent Executable) with fPIC (Position-Independent Code)
string(REPLACE "-fPIE" "-fPIC" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE "-fPIE" "-fPIC" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
endmacro()

3 changes: 1 addition & 2 deletions CMake/unix_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ macro(os_set_flags)
set(SECURITY_COMPILER_FLAGS "${SECURITY_COMPILER_FLAGS} -Werror -z noexecstack -Wl,-z,relro,-z,now -fstack-protector-strong")
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SECURITY_COMPILER_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SECURITY_COMPILER_FLAGS}")
push_security_flags()

set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -pie")

Expand Down
3 changes: 1 addition & 2 deletions CMake/windows_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ macro(os_set_flags)
set(SECURITY_COMPILER_FLAGS "${SECURITY_COMPILER_FLAGS} /WX /sdl")
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SECURITY_COMPILER_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SECURITY_COMPILER_FLAGS}")
push_security_flags()

if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} /INCREMENTAL:NO /LTCG /NXCOMPAT") # ignoring '/INCREMENTAL' due to '/LTCG' specification
Expand Down
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ endif()

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/CMake)

# include security flags helper functions
include(CMake/security_flags_helper_functions.cmake)

# include librealsense general configuration
include(CMake/global_config.cmake)

Expand Down Expand Up @@ -61,17 +64,15 @@ target_link_libraries( ${LRS_TARGET} PUBLIC rsutils )
if(BUILD_WITH_DDS)
if (CMAKE_SYSTEM MATCHES "Windows" OR CMAKE_SYSTEM MATCHES "Linux")

string(REPLACE "${SECURITY_COMPILER_FLAGS}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") # remove security flags
string(REPLACE "${SECURITY_COMPILER_FLAGS}" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
pop_security_flags()

message(STATUS "Building with FastDDS")
include(CMake/external_foonathan_memory.cmake)
include(CMake/external_fastdds.cmake)

target_link_libraries( ${LRS_TARGET} PRIVATE realdds )

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SECURITY_COMPILER_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SECURITY_COMPILER_FLAGS}")
push_security_flags()

else()
MESSAGE(STATUS "Turning off `BUILD_WITH_DDS` as it's only supported on Windows & Linux and not on ${CMAKE_SYSTEM}")
Expand Down
4 changes: 2 additions & 2 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
# View the makefile commands during build
#set(CMAKE_VERBOSE_MAKEFILE on)

string(REPLACE "-fPIC" "-fPIE" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") # examples are executables so we want position indepandent executables and not libraries
set_security_flags_for_executable() # examples are executables so we want position indepandent executables and not libraries

set( DEPENDENCIES ${LRS_TARGET} )
if(BUILD_GRAPHICAL_EXAMPLES)
Expand Down Expand Up @@ -43,4 +43,4 @@ add_subdirectory(motion)
add_subdirectory(gl)
add_subdirectory(hdr)

string(REPLACE "-fPIE" "-fPIC" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
unset_security_flags_for_executable()
8 changes: 3 additions & 5 deletions third-party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ string(REPLACE ${PROJECT_SOURCE_DIR}/ "" _rel_path ${CMAKE_CURRENT_LIST_DIR})

add_subdirectory( "${CMAKE_CURRENT_LIST_DIR}/rsutils" )

string(REPLACE "${SECURITY_COMPILER_FLAGS}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") # remove security flags
string(REPLACE "${SECURITY_COMPILER_FLAGS}" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
pop_security_flags()

include(CMake/external_json.cmake)
# Add additional include directories to allow file to include rosbag headers
Expand All @@ -21,6 +20,5 @@ if( BUILD_WITH_DDS )
add_subdirectory( "${CMAKE_CURRENT_LIST_DIR}/realdds" )
endif()

# restore flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SECURITY_COMPILER_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SECURITY_COMPILER_FLAGS}")
# restore security flags
push_security_flags()
4 changes: 2 additions & 2 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
# View the makefile commands during build
#set(CMAKE_VERBOSE_MAKEFILE on)

string(REPLACE "-fPIC" "-fPIE" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") # tools are executables so we want position indepandent executables and not libraries
set_security_flags_for_executable() # tools are executables so we want position indepandent executables and not libraries

list( APPEND DEPENDENCIES ${LRS_TARGET} tclap )

Expand Down Expand Up @@ -48,4 +48,4 @@ if(BUILD_EXAMPLES)
endif()
endif()

string(REPLACE "-fPIE" "-fPIC" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
unset_security_flags_for_executable()

0 comments on commit a64cc1f

Please sign in to comment.