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:
parent
bb03d42177
commit
2cde7c0fe8
@ -274,7 +274,11 @@ endif()
|
|||||||
|
|
||||||
# allow 'large' files in 32 bit builds
|
# allow 'large' files in 32 bit builds
|
||||||
if(UNIX)
|
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()
|
endif()
|
||||||
|
|
||||||
# If this is an out-of-tree build, do not pollute the original source directory
|
# 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)
|
if(PYTHON_EXECUTABLE)
|
||||||
set(USE_THIS_PYTHON "-DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}")
|
set(USE_THIS_PYTHON "-DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}")
|
||||||
endif()
|
endif()
|
||||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
|
||||||
if(CMAKE_GENERATOR STREQUAL Xcode)
|
if(CMAKE_GENERATOR STREQUAL Xcode)
|
||||||
set(VOLK_GNSSSDR_BUILD_COMMAND "xcodebuild"
|
set(VOLK_GNSSSDR_BUILD_COMMAND "xcodebuild"
|
||||||
"-configuration" $<$<CONFIG:Debug>:Debug>$<$<CONFIG:Release>:Release>$<$<CONFIG:RelWithDebInfo>:RelWithDebInfo>$<$<CONFIG:MinSizeRel>:MinSizeRel>
|
"-configuration" $<$<CONFIG:Debug>:Debug>$<$<CONFIG:Release>:Release>$<$<CONFIG:RelWithDebInfo>:RelWithDebInfo>$<$<CONFIG:MinSizeRel>:MinSizeRel>
|
||||||
"-alltargets"
|
)
|
||||||
)
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(CMAKE_TOOLCHAIN_FILE)
|
if(CMAKE_TOOLCHAIN_FILE)
|
||||||
@ -1155,11 +1157,7 @@ if(NOT VOLKGNSSSDR_FOUND)
|
|||||||
${STRIP_VOLK_GNSSSDR_PROFILE}
|
${STRIP_VOLK_GNSSSDR_PROFILE}
|
||||||
${USE_THIS_PYTHON}
|
${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})
|
if(DEFINED ENV{OECORE_TARGET_SYSROOT})
|
||||||
set(VOLK_GNSSSDR_CMAKE_ARGS ${VOLK_GNSSSDR_CMAKE_ARGS}
|
set(VOLK_GNSSSDR_CMAKE_ARGS ${VOLK_GNSSSDR_CMAKE_ARGS}
|
||||||
-DCROSSCOMPILE_MULTILIB=TRUE
|
-DCROSSCOMPILE_MULTILIB=TRUE
|
||||||
|
@ -9,9 +9,6 @@
|
|||||||
# Project setup
|
# Project setup
|
||||||
########################################################################
|
########################################################################
|
||||||
cmake_minimum_required(VERSION 2.8.12...3.25)
|
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")
|
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Choose build type: None Debug Release RelWithDebInfo MinSizeRel")
|
||||||
project(volk_gnsssdr)
|
project(volk_gnsssdr)
|
||||||
enable_language(CXX)
|
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")
|
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)
|
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(/W1) # reduce warnings
|
||||||
add_compile_options(/wo4309)
|
add_compile_options(/wo4309)
|
||||||
add_compile_options(/wd4752)
|
add_compile_options(/wd4752)
|
||||||
@ -237,11 +238,11 @@ endif()
|
|||||||
|
|
||||||
# allow 'large' files in 32 bit builds
|
# allow 'large' files in 32 bit builds
|
||||||
if(UNIX)
|
if(UNIX)
|
||||||
add_definitions(-D_LARGEFILE_SOURCE
|
if(CMAKE_VERSION VERSION_GREATER 3.12.0)
|
||||||
-D_FILE_OFFSET_BITS=64
|
add_compile_definitions(_LARGEFILE_SOURCE _FILE_OFFSET_BITS=64 _LARGE_FILES)
|
||||||
-D_LARGE_FILES
|
else()
|
||||||
-D_FORTIFY_SOURCE=2
|
add_definitions(-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES)
|
||||||
)
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
@ -319,7 +320,11 @@ if(MSVC)
|
|||||||
endif()
|
endif()
|
||||||
set(BOOST_ALL_DYN_LINK "${BOOST_ALL_DYN_LINK}" CACHE BOOL "boost enable dynamic linking")
|
set(BOOST_ALL_DYN_LINK "${BOOST_ALL_DYN_LINK}" CACHE BOOL "boost enable dynamic linking")
|
||||||
if(BOOST_ALL_DYN_LINK)
|
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()
|
else()
|
||||||
unset(BOOST_REQUIRED_COMPONENTS) # empty components list for static link
|
unset(BOOST_REQUIRED_COMPONENTS) # empty components list for static link
|
||||||
endif()
|
endif()
|
||||||
|
@ -35,8 +35,6 @@ add_executable(volk_gnsssdr_profile
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/volk_gnsssdr_option_helpers.cc
|
${CMAKE_CURRENT_SOURCE_DIR}/volk_gnsssdr_option_helpers.cc
|
||||||
)
|
)
|
||||||
|
|
||||||
add_dependencies(volk_gnsssdr_profile volk_gnsssdr)
|
|
||||||
|
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
target_include_directories(volk_gnsssdr_profile
|
target_include_directories(volk_gnsssdr_profile
|
||||||
PRIVATE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/cmake/msvc>
|
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})
|
target_link_libraries(volk_gnsssdr_profile PRIVATE ${Boost_LIBRARIES})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
if(FILESYSTEM_FOUND)
|
if(FILESYSTEM_FOUND)
|
||||||
add_definitions(-DHAS_STD_FILESYSTEM=1)
|
add_definitions(-DHAS_STD_FILESYSTEM=1)
|
||||||
if(${find_experimental})
|
if(${find_experimental})
|
||||||
@ -72,10 +69,8 @@ if(ENABLE_STATIC_LIBS)
|
|||||||
target_link_libraries(volk_gnsssdr_profile PRIVATE volk_gnsssdr_static ${orc_lib})
|
target_link_libraries(volk_gnsssdr_profile PRIVATE volk_gnsssdr_static ${orc_lib})
|
||||||
else()
|
else()
|
||||||
target_link_libraries(volk_gnsssdr_profile PRIVATE volk_gnsssdr ${orc_lib})
|
target_link_libraries(volk_gnsssdr_profile PRIVATE volk_gnsssdr ${orc_lib})
|
||||||
add_dependencies(volk_gnsssdr_profile volk_gnsssdr)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
if(ENABLE_STRIP)
|
if(ENABLE_STRIP)
|
||||||
if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND NOT WIN32)
|
if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND NOT WIN32)
|
||||||
set_target_properties(volk_gnsssdr_profile
|
set_target_properties(volk_gnsssdr_profile
|
||||||
@ -84,23 +79,19 @@ if(ENABLE_STRIP)
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
install(
|
install(
|
||||||
TARGETS volk_gnsssdr_profile
|
TARGETS volk_gnsssdr_profile
|
||||||
DESTINATION bin
|
DESTINATION bin
|
||||||
COMPONENT "volk_gnsssdr"
|
COMPONENT "volk_gnsssdr"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# MAKE volk_gnsssdr-config-info
|
# 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)
|
add_executable(volk_gnsssdr-config-info volk_gnsssdr-config-info.cc ${CMAKE_CURRENT_SOURCE_DIR}/volk_gnsssdr_option_helpers.cc)
|
||||||
|
|
||||||
|
|
||||||
if(ENABLE_STATIC_LIBS)
|
if(ENABLE_STATIC_LIBS)
|
||||||
target_link_libraries(volk_gnsssdr-config-info volk_gnsssdr_static ${orc_lib})
|
target_link_libraries(volk_gnsssdr-config-info volk_gnsssdr_static ${orc_lib})
|
||||||
else()
|
else()
|
||||||
target_link_libraries(volk_gnsssdr-config-info volk_gnsssdr ${orc_lib})
|
target_link_libraries(volk_gnsssdr-config-info volk_gnsssdr ${orc_lib})
|
||||||
add_dependencies(volk_gnsssdr-config-info volk_gnsssdr)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(ENABLE_STRIP)
|
if(ENABLE_STRIP)
|
||||||
@ -117,7 +108,6 @@ install(
|
|||||||
COMPONENT "volk_gnsssdr"
|
COMPONENT "volk_gnsssdr"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# Launch volk_gnsssdr_profile if requested to do so
|
# Launch volk_gnsssdr_profile if requested to do so
|
||||||
if(ENABLE_PROFILING)
|
if(ENABLE_PROFILING)
|
||||||
if(DEFINED VOLK_CONFIGPATH)
|
if(DEFINED VOLK_CONFIGPATH)
|
||||||
|
@ -558,65 +558,75 @@ else()
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Add dynamic library
|
# Add dynamic library
|
||||||
if(CMAKE_GENERATOR STREQUAL Xcode)
|
# Note: new Xcode buildsystem does not allow building both static and dynamic libraries
|
||||||
add_library(volk_gnsssdr SHARED ${volk_gnsssdr_sources})
|
# so we only build dynamic if ENABLE_STATIC_LIBS is not enabled in that generator.
|
||||||
else()
|
# For other generators than XCode, the dynamic library is always built.
|
||||||
add_library(volk_gnsssdr SHARED $<TARGET_OBJECTS:volk_gnsssdr_obj>)
|
if(NOT (ENABLE_STATIC_LIBS AND (CMAKE_GENERATOR STREQUAL Xcode)))
|
||||||
endif()
|
if(CMAKE_GENERATOR STREQUAL Xcode)
|
||||||
if(USE_CPU_FEATURES)
|
add_library(volk_gnsssdr SHARED ${volk_gnsssdr_sources})
|
||||||
if(CPUFEATURES_FOUND)
|
|
||||||
target_link_libraries(volk_gnsssdr
|
|
||||||
PUBLIC ${volk_gnsssdr_libraries}
|
|
||||||
PRIVATE CpuFeature::cpu_features
|
|
||||||
)
|
|
||||||
else()
|
else()
|
||||||
target_link_libraries(volk_gnsssdr
|
add_library(volk_gnsssdr SHARED $<TARGET_OBJECTS:volk_gnsssdr_obj>)
|
||||||
PUBLIC ${volk_gnsssdr_libraries}
|
endif()
|
||||||
PRIVATE cpu_features
|
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()
|
endif()
|
||||||
else()
|
if(USE_CPU_FEATURES)
|
||||||
target_link_libraries(volk_gnsssdr PUBLIC ${volk_gnsssdr_libraries})
|
if(CPUFEATURES_FOUND)
|
||||||
endif()
|
target_include_directories(volk_gnsssdr
|
||||||
target_include_directories(volk_gnsssdr
|
PRIVATE
|
||||||
PUBLIC $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
|
$<TARGET_PROPERTY:CpuFeature::cpu_features,INTERFACE_INCLUDE_DIRECTORIES>
|
||||||
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
|
)
|
||||||
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/kernels>
|
else()
|
||||||
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
|
target_include_directories(volk_gnsssdr
|
||||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
|
PRIVATE
|
||||||
PUBLIC $<INSTALL_INTERFACE:include>
|
$<TARGET_PROPERTY:cpu_features,INTERFACE_INCLUDE_DIRECTORIES>
|
||||||
)
|
)
|
||||||
if(USE_CPU_FEATURES)
|
endif()
|
||||||
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
|
||||||
# Configure target properties
|
if(ORC_FOUND)
|
||||||
if(ORC_FOUND)
|
target_link_libraries(volk_gnsssdr PRIVATE ${ORC_LIBRARIES})
|
||||||
target_link_libraries(volk_gnsssdr PRIVATE ${ORC_LIBRARIES})
|
endif()
|
||||||
endif()
|
if(NOT MSVC)
|
||||||
if(NOT MSVC)
|
target_link_libraries(volk_gnsssdr PUBLIC m)
|
||||||
target_link_libraries(volk_gnsssdr PUBLIC m)
|
endif()
|
||||||
endif()
|
set_target_properties(volk_gnsssdr PROPERTIES VERSION ${VERSION})
|
||||||
set_target_properties(volk_gnsssdr PROPERTIES VERSION ${VERSION})
|
set_target_properties(volk_gnsssdr PROPERTIES SOVERSION ${SOVERSION})
|
||||||
set_target_properties(volk_gnsssdr PROPERTIES SOVERSION ${SOVERSION})
|
set_target_properties(volk_gnsssdr PROPERTIES DEFINE_SYMBOL "volk_gnsssdr_EXPORTS")
|
||||||
set_target_properties(volk_gnsssdr PROPERTIES DEFINE_SYMBOL "volk_gnsssdr_EXPORTS")
|
|
||||||
|
|
||||||
# Install locations
|
# Install locations
|
||||||
install(TARGETS volk_gnsssdr
|
install(TARGETS volk_gnsssdr
|
||||||
EXPORT VOLK_GNSSSDR-export
|
EXPORT VOLK_GNSSSDR-export
|
||||||
LIBRARY DESTINATION lib${LIB_SUFFIX} COMPONENT "volk_gnsssdr_runtime" # .so file
|
LIBRARY DESTINATION lib${LIB_SUFFIX} COMPONENT "volk_gnsssdr_runtime" # .so file
|
||||||
ARCHIVE DESTINATION lib${LIB_SUFFIX} COMPONENT "volk_gnsssdr_devel" # .lib file
|
ARCHIVE DESTINATION lib${LIB_SUFFIX} COMPONENT "volk_gnsssdr_devel" # .lib file
|
||||||
RUNTIME DESTINATION bin COMPONENT "volk_gnsssdr_runtime" # .dll file
|
RUNTIME DESTINATION bin COMPONENT "volk_gnsssdr_runtime" # .dll file
|
||||||
)
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
# Configure static library
|
# Configure static library
|
||||||
if(ENABLE_STATIC_LIBS)
|
if(ENABLE_STATIC_LIBS)
|
||||||
@ -654,7 +664,11 @@ if(ENABLE_STATIC_LIBS)
|
|||||||
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
|
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
PRIVATE ${CMAKE_CURRENT_SOURCE_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)
|
set_target_properties(volk_gnsssdr_static PROPERTIES OUTPUT_NAME volk_gnsssdr)
|
||||||
|
|
||||||
install(TARGETS volk_gnsssdr_static
|
install(TARGETS volk_gnsssdr_static
|
||||||
|
Loading…
Reference in New Issue
Block a user