1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-13 19:50:34 +00:00

CMake improvements: Move _FORTIFY_SOURCE=2 definition to targets, do not apply in Debug mode. Make use of add_compile_definitions() instead of add_definitions() when available

This commit is contained in:
Carles Fernandez 2022-12-03 23:55:12 +01:00
parent bb03d42177
commit 2cde7c0fe8
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
4 changed files with 95 additions and 88 deletions

View File

@ -274,7 +274,11 @@ endif()
# allow 'large' files in 32 bit builds
if(UNIX)
add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES)
if(CMAKE_VERSION VERSION_GREATER 3.12.0)
add_compile_definitions(_LARGEFILE_SOURCE _FILE_OFFSET_BITS=64 _LARGE_FILES)
else()
add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES)
endif()
endif()
# If this is an out-of-tree build, do not pollute the original source directory
@ -1115,13 +1119,11 @@ if(NOT VOLKGNSSSDR_FOUND)
if(PYTHON_EXECUTABLE)
set(USE_THIS_PYTHON "-DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}")
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
if(CMAKE_GENERATOR STREQUAL Xcode)
set(VOLK_GNSSSDR_BUILD_COMMAND "xcodebuild"
"-configuration" $<$<CONFIG:Debug>:Debug>$<$<CONFIG:Release>:Release>$<$<CONFIG:RelWithDebInfo>:RelWithDebInfo>$<$<CONFIG:MinSizeRel>:MinSizeRel>
"-alltargets"
)
endif()
if(CMAKE_GENERATOR STREQUAL Xcode)
set(VOLK_GNSSSDR_BUILD_COMMAND "xcodebuild"
"-configuration" $<$<CONFIG:Debug>:Debug>$<$<CONFIG:Release>:Release>$<$<CONFIG:RelWithDebInfo>:RelWithDebInfo>$<$<CONFIG:MinSizeRel>:MinSizeRel>
)
endif()
if(CMAKE_TOOLCHAIN_FILE)
@ -1155,11 +1157,7 @@ if(NOT VOLKGNSSSDR_FOUND)
${STRIP_VOLK_GNSSSDR_PROFILE}
${USE_THIS_PYTHON}
)
if(CMAKE_VERSION VERSION_GREATER 3.18.99 AND CMAKE_GENERATOR STREQUAL Xcode)
if(XCODE_VERSION VERSION_GREATER 11)
set(VOLK_GNSSSDR_CMAKE_ARGS ${VOLK_GNSSSDR_CMAKE_ARGS} -T buildsystem=1)
endif()
endif()
if(DEFINED ENV{OECORE_TARGET_SYSROOT})
set(VOLK_GNSSSDR_CMAKE_ARGS ${VOLK_GNSSSDR_CMAKE_ARGS}
-DCROSSCOMPILE_MULTILIB=TRUE

View File

@ -9,9 +9,6 @@
# Project setup
########################################################################
cmake_minimum_required(VERSION 2.8.12...3.25)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Choose build type: None Debug Release RelWithDebInfo MinSizeRel")
project(volk_gnsssdr)
enable_language(CXX)
@ -227,7 +224,11 @@ endif()
set(CROSSCOMPILE_MULTILIB ${CROSSCOMPILE_MULTILIB} CACHE STRING "Define \"true\" if you have and want to use multiple C development libs installed for cross compile")
if(MSVC)
add_definitions(-D_USE_MATH_DEFINES) # enables math constants on all supported versions of MSVC
if(CMAKE_VERSION VERSION_GREATER 3.12.0)
add_compile_definitions(_USE_MATH_DEFINES) # enables math constants on all supported versions of MSVC
else()
add_definitions(-D_USE_MATH_DEFINES) # enables math constants on all supported versions of MSVC
endif()
add_compile_options(/W1) # reduce warnings
add_compile_options(/wo4309)
add_compile_options(/wd4752)
@ -237,11 +238,11 @@ endif()
# allow 'large' files in 32 bit builds
if(UNIX)
add_definitions(-D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64
-D_LARGE_FILES
-D_FORTIFY_SOURCE=2
)
if(CMAKE_VERSION VERSION_GREATER 3.12.0)
add_compile_definitions(_LARGEFILE_SOURCE _FILE_OFFSET_BITS=64 _LARGE_FILES)
else()
add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES)
endif()
endif()
@ -319,7 +320,11 @@ if(MSVC)
endif()
set(BOOST_ALL_DYN_LINK "${BOOST_ALL_DYN_LINK}" CACHE BOOL "boost enable dynamic linking")
if(BOOST_ALL_DYN_LINK)
add_definitions(-DBOOST_ALL_DYN_LINK) # setup boost auto-linking in msvc
if(CMAKE_VERSION VERSION_GREATER 3.12.0)
add_compile_definitions(BOOST_ALL_DYN_LINK) # enables math constants on all supported versions of MSVC
else()
add_definitions(-DBOOST_ALL_DYN_LINK) # setup boost auto-linking in msvc
endif()
else()
unset(BOOST_REQUIRED_COMPONENTS) # empty components list for static link
endif()

View File

@ -35,8 +35,6 @@ add_executable(volk_gnsssdr_profile
${CMAKE_CURRENT_SOURCE_DIR}/volk_gnsssdr_option_helpers.cc
)
add_dependencies(volk_gnsssdr_profile volk_gnsssdr)
if(MSVC)
target_include_directories(volk_gnsssdr_profile
PRIVATE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/cmake/msvc>
@ -59,7 +57,6 @@ if(NOT FILESYSTEM_FOUND)
target_link_libraries(volk_gnsssdr_profile PRIVATE ${Boost_LIBRARIES})
endif()
if(FILESYSTEM_FOUND)
add_definitions(-DHAS_STD_FILESYSTEM=1)
if(${find_experimental})
@ -72,10 +69,8 @@ if(ENABLE_STATIC_LIBS)
target_link_libraries(volk_gnsssdr_profile PRIVATE volk_gnsssdr_static ${orc_lib})
else()
target_link_libraries(volk_gnsssdr_profile PRIVATE volk_gnsssdr ${orc_lib})
add_dependencies(volk_gnsssdr_profile volk_gnsssdr)
endif()
if(ENABLE_STRIP)
if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND NOT WIN32)
set_target_properties(volk_gnsssdr_profile
@ -84,23 +79,19 @@ if(ENABLE_STRIP)
endif()
endif()
install(
TARGETS volk_gnsssdr_profile
DESTINATION bin
COMPONENT "volk_gnsssdr"
)
# MAKE volk_gnsssdr-config-info
add_executable(volk_gnsssdr-config-info volk_gnsssdr-config-info.cc ${CMAKE_CURRENT_SOURCE_DIR}/volk_gnsssdr_option_helpers.cc)
if(ENABLE_STATIC_LIBS)
target_link_libraries(volk_gnsssdr-config-info volk_gnsssdr_static ${orc_lib})
else()
target_link_libraries(volk_gnsssdr-config-info volk_gnsssdr ${orc_lib})
add_dependencies(volk_gnsssdr-config-info volk_gnsssdr)
endif()
if(ENABLE_STRIP)
@ -117,7 +108,6 @@ install(
COMPONENT "volk_gnsssdr"
)
# Launch volk_gnsssdr_profile if requested to do so
if(ENABLE_PROFILING)
if(DEFINED VOLK_CONFIGPATH)

View File

@ -558,65 +558,75 @@ else()
endif()
# Add dynamic library
if(CMAKE_GENERATOR STREQUAL Xcode)
add_library(volk_gnsssdr SHARED ${volk_gnsssdr_sources})
else()
add_library(volk_gnsssdr SHARED $<TARGET_OBJECTS:volk_gnsssdr_obj>)
endif()
if(USE_CPU_FEATURES)
if(CPUFEATURES_FOUND)
target_link_libraries(volk_gnsssdr
PUBLIC ${volk_gnsssdr_libraries}
PRIVATE CpuFeature::cpu_features
)
# Note: new Xcode buildsystem does not allow building both static and dynamic libraries
# so we only build dynamic if ENABLE_STATIC_LIBS is not enabled in that generator.
# For other generators than XCode, the dynamic library is always built.
if(NOT (ENABLE_STATIC_LIBS AND (CMAKE_GENERATOR STREQUAL Xcode)))
if(CMAKE_GENERATOR STREQUAL Xcode)
add_library(volk_gnsssdr SHARED ${volk_gnsssdr_sources})
else()
target_link_libraries(volk_gnsssdr
PUBLIC ${volk_gnsssdr_libraries}
PRIVATE cpu_features
add_library(volk_gnsssdr SHARED $<TARGET_OBJECTS:volk_gnsssdr_obj>)
endif()
if(USE_CPU_FEATURES)
if(CPUFEATURES_FOUND)
target_link_libraries(volk_gnsssdr
PUBLIC ${volk_gnsssdr_libraries}
PRIVATE CpuFeature::cpu_features
)
else()
target_link_libraries(volk_gnsssdr
PUBLIC ${volk_gnsssdr_libraries}
PRIVATE cpu_features
)
endif()
else()
target_link_libraries(volk_gnsssdr PUBLIC ${volk_gnsssdr_libraries})
endif()
target_include_directories(volk_gnsssdr
PUBLIC $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/kernels>
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
PUBLIC $<INSTALL_INTERFACE:include>
)
if(UNIX)
target_compile_definitions(volk_gnsssdr
PUBLIC $<$<CONFIG:Release>:_FORTIFY_SOURCE=2>$<$<CONFIG:RelWithDebInfo>:_FORTIFY_SOURCE=2>
)
endif()
else()
target_link_libraries(volk_gnsssdr PUBLIC ${volk_gnsssdr_libraries})
endif()
target_include_directories(volk_gnsssdr
PUBLIC $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/kernels>
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
PUBLIC $<INSTALL_INTERFACE:include>
)
if(USE_CPU_FEATURES)
if(CPUFEATURES_FOUND)
target_include_directories(volk_gnsssdr
PRIVATE
$<TARGET_PROPERTY:CpuFeature::cpu_features,INTERFACE_INCLUDE_DIRECTORIES>
)
else()
target_include_directories(volk_gnsssdr
PRIVATE
$<TARGET_PROPERTY:cpu_features,INTERFACE_INCLUDE_DIRECTORIES>
)
if(USE_CPU_FEATURES)
if(CPUFEATURES_FOUND)
target_include_directories(volk_gnsssdr
PRIVATE
$<TARGET_PROPERTY:CpuFeature::cpu_features,INTERFACE_INCLUDE_DIRECTORIES>
)
else()
target_include_directories(volk_gnsssdr
PRIVATE
$<TARGET_PROPERTY:cpu_features,INTERFACE_INCLUDE_DIRECTORIES>
)
endif()
endif()
endif()
# Configure target properties
if(ORC_FOUND)
target_link_libraries(volk_gnsssdr PRIVATE ${ORC_LIBRARIES})
endif()
if(NOT MSVC)
target_link_libraries(volk_gnsssdr PUBLIC m)
endif()
set_target_properties(volk_gnsssdr PROPERTIES VERSION ${VERSION})
set_target_properties(volk_gnsssdr PROPERTIES SOVERSION ${SOVERSION})
set_target_properties(volk_gnsssdr PROPERTIES DEFINE_SYMBOL "volk_gnsssdr_EXPORTS")
# Configure target properties
if(ORC_FOUND)
target_link_libraries(volk_gnsssdr PRIVATE ${ORC_LIBRARIES})
endif()
if(NOT MSVC)
target_link_libraries(volk_gnsssdr PUBLIC m)
endif()
set_target_properties(volk_gnsssdr PROPERTIES VERSION ${VERSION})
set_target_properties(volk_gnsssdr PROPERTIES SOVERSION ${SOVERSION})
set_target_properties(volk_gnsssdr PROPERTIES DEFINE_SYMBOL "volk_gnsssdr_EXPORTS")
# Install locations
install(TARGETS volk_gnsssdr
EXPORT VOLK_GNSSSDR-export
LIBRARY DESTINATION lib${LIB_SUFFIX} COMPONENT "volk_gnsssdr_runtime" # .so file
ARCHIVE DESTINATION lib${LIB_SUFFIX} COMPONENT "volk_gnsssdr_devel" # .lib file
RUNTIME DESTINATION bin COMPONENT "volk_gnsssdr_runtime" # .dll file
)
# Install locations
install(TARGETS volk_gnsssdr
EXPORT VOLK_GNSSSDR-export
LIBRARY DESTINATION lib${LIB_SUFFIX} COMPONENT "volk_gnsssdr_runtime" # .so file
ARCHIVE DESTINATION lib${LIB_SUFFIX} COMPONENT "volk_gnsssdr_devel" # .lib file
RUNTIME DESTINATION bin COMPONENT "volk_gnsssdr_runtime" # .dll file
)
endif()
# Configure static library
if(ENABLE_STATIC_LIBS)
@ -654,7 +664,11 @@ if(ENABLE_STATIC_LIBS)
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
)
if(UNIX)
target_compile_definitions(volk_gnsssdr_static
PUBLIC $<$<CONFIG:Release>:_FORTIFY_SOURCE=2>$<$<CONFIG:RelWithDebInfo>:_FORTIFY_SOURCE=2>
)
endif()
set_target_properties(volk_gnsssdr_static PROPERTIES OUTPUT_NAME volk_gnsssdr)
install(TARGETS volk_gnsssdr_static