2019-02-16 10:10:12 +00:00
|
|
|
set(COMMON_CXX_FEATURES cxx_alias_templates cxx_nullptr cxx_override)
|
2019-02-12 16:31:17 +00:00
|
|
|
|
|
|
|
function(common_target_properties Name)
|
|
|
|
get_target_property(__type ${Name} TYPE)
|
|
|
|
set(__visibility PUBLIC)
|
|
|
|
if(__type STREQUAL INTERFACE_LIBRARY)
|
|
|
|
set(__interface 1)
|
|
|
|
set(__visibility INTERFACE)
|
|
|
|
endif()
|
2020-03-29 05:44:48 +00:00
|
|
|
target_compile_features(
|
|
|
|
${Name}
|
|
|
|
${__visibility}
|
|
|
|
${COMMON_CXX_FEATURES})
|
2019-02-21 10:42:38 +00:00
|
|
|
get_target_property(_targetType ${Name} TYPE)
|
2019-10-07 10:52:50 +00:00
|
|
|
if(_targetType STREQUAL "EXECUTABLE" AND CMAKE_CXX_COMPILE_OPTIONS_PIE)
|
2019-02-21 10:42:38 +00:00
|
|
|
target_compile_options(${Name} PUBLIC "${CMAKE_CXX_COMPILE_OPTIONS_PIE}")
|
|
|
|
endif()
|
2019-12-03 16:23:14 +00:00
|
|
|
target_include_directories(
|
|
|
|
${Name}
|
2020-04-01 18:42:59 +00:00
|
|
|
PUBLIC $<INSTALL_INTERFACE:include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>)
|
2019-02-12 16:31:17 +00:00
|
|
|
if(APPLE)
|
2020-03-29 05:44:48 +00:00
|
|
|
target_compile_definitions(
|
|
|
|
${Name}
|
|
|
|
${__visibility}
|
|
|
|
Darwin)
|
2019-02-12 16:31:17 +00:00
|
|
|
endif()
|
|
|
|
if(NOT __interface)
|
|
|
|
if(TARGET Qt5::Core)
|
2019-10-07 10:52:50 +00:00
|
|
|
if(_targetType STREQUAL "EXECUTABLE")
|
2019-02-21 10:42:38 +00:00
|
|
|
target_compile_options(${Name} PUBLIC "${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
|
|
|
|
endif()
|
2019-12-03 16:23:14 +00:00
|
|
|
set_target_properties(${Name} PROPERTIES AUTOMOC TRUE AUTORCC TRUE)
|
2019-02-12 16:31:17 +00:00
|
|
|
endif()
|
|
|
|
if(TARGET Qt5::Widgets)
|
|
|
|
set_target_properties(${Name} PROPERTIES AUTOUIC TRUE)
|
2019-10-07 10:52:50 +00:00
|
|
|
# if(CMAKE_VERSION VERSION_LESS 3.7.99)
|
|
|
|
# target_include_directories(
|
|
|
|
# ${Name}
|
|
|
|
# PUBLIC
|
|
|
|
# $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/${Name}_autogen/include>
|
|
|
|
# )
|
|
|
|
# endif()
|
2019-02-12 16:31:17 +00:00
|
|
|
endif()
|
|
|
|
if(CMAKE_CXX_COMPILER_IS_GCC AND NOT APPLE)
|
|
|
|
set_target_properties(${Name} PROPERTIES LINK_FLAGS "-Wl,--no-as-needed")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2019-10-09 14:10:17 +00:00
|
|
|
# LTO only for executables (not libraries) in Release build type
|
|
|
|
get_target_property(target_type ${Name} TYPE)
|
|
|
|
if(target_type STREQUAL "EXECUTABLE" AND CMAKE_BUILD_TYPE STREQUAL "Release")
|
|
|
|
check_cxx_compiler_flag(-flto CXX_HAS_LTO_FLAG)
|
|
|
|
check_cxx_compiler_flag(-fno-fat-lto-objects CXX_HAS_NO_FAT_LTO_FLAG)
|
|
|
|
if(CMAKE_CXX_COMPILER_IS_GCC AND CXX_HAS_LTO_FLAG)
|
2019-12-03 16:23:14 +00:00
|
|
|
find_program(
|
|
|
|
CMAKE_GCC_AR
|
2020-04-01 18:42:59 +00:00
|
|
|
NAMES "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar${_CMAKE_TOOLCHAIN_SUFFIX}" "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar"
|
2019-12-03 16:23:14 +00:00
|
|
|
HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
|
|
|
|
find_program(
|
|
|
|
CMAKE_GCC_NM
|
2020-04-01 18:42:59 +00:00
|
|
|
NAMES "${_CMAKE_TOOLCHAIN_PREFIX}gcc-nm${_CMAKE_TOOLCHAIN_SUFFIX}" "${_CMAKE_TOOLCHAIN_PREFIX}gcc-nm"
|
2019-12-03 16:23:14 +00:00
|
|
|
HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
|
|
|
|
find_program(
|
|
|
|
CMAKE_GCC_RANLIB
|
|
|
|
NAMES "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib${_CMAKE_TOOLCHAIN_SUFFIX}"
|
|
|
|
"${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib"
|
|
|
|
HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
|
|
|
|
if(CMAKE_GCC_AR
|
|
|
|
AND CMAKE_GCC_NM
|
|
|
|
AND CMAKE_GCC_RANLIB)
|
2019-10-09 14:10:17 +00:00
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto")
|
|
|
|
if(CXX_HAS_NO_FAT_LTO_FLAG)
|
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-fat-lto-objects")
|
|
|
|
endif()
|
|
|
|
set(CMAKE_AR "${CMAKE_GCC_AR}")
|
|
|
|
set(CMAKE_NM "${CMAKE_GCC_NM}")
|
|
|
|
set(CMAKE_RANLIB "${CMAKE_GCC_RANLIB}")
|
|
|
|
else()
|
2020-04-01 18:42:59 +00:00
|
|
|
message(WARNING "GCC indicates LTO support, but binutils wrappers could not be found. Disabling LTO.")
|
2019-10-09 14:10:17 +00:00
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
check_enable_compiler_flag(-flto)
|
|
|
|
check_enable_compiler_flag(-fno-fat-lto-objects)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2020-03-30 08:44:45 +00:00
|
|
|
if(CMAKE_BUILD_TYPE STREQUAL Profile)
|
|
|
|
target_compile_definitions(
|
|
|
|
${Name}
|
|
|
|
${__visibility}
|
|
|
|
PROFILE)
|
|
|
|
elseif(CMAKE_BUILD_TYPE STREQUAL Debug)
|
|
|
|
target_compile_definitions(
|
|
|
|
${Name}
|
|
|
|
${__visibility}
|
|
|
|
DEBUG)
|
|
|
|
elseif(CMAKE_BUILD_TYPE STREQUAL Release)
|
|
|
|
target_compile_definitions(
|
|
|
|
${Name}
|
|
|
|
${__visibility}
|
|
|
|
RELEASE)
|
|
|
|
elseif(CMAKE_BUILD_TYPE STREQUAL None)
|
|
|
|
target_compile_definitions(
|
|
|
|
${Name}
|
|
|
|
${__visibility}
|
|
|
|
ANALYSIS)
|
|
|
|
endif()
|
2020-03-30 20:02:17 +00:00
|
|
|
target_compile_definitions(
|
2020-04-01 18:42:59 +00:00
|
|
|
${Name}
|
|
|
|
${__visibility}
|
|
|
|
"TARGET_LSB_ID_${LSB_DISTRIBUTOR_ID}"
|
|
|
|
"TARGET_LSB_CODENAME_${LSB_CODENAME}")
|
2019-02-12 16:31:17 +00:00
|
|
|
endfunction()
|