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
|
|
|
|
2020-04-13 16:44:42 +00:00
|
|
|
function(common_target_properties target)
|
2020-06-26 01:04:38 +00:00
|
|
|
get_target_property(_targetType ${target} TYPE)
|
|
|
|
|
2019-02-12 16:31:17 +00:00
|
|
|
set(__visibility PUBLIC)
|
2020-06-26 01:04:38 +00:00
|
|
|
if(_targetType STREQUAL INTERFACE_LIBRARY)
|
2019-02-12 16:31:17 +00:00
|
|
|
set(__interface 1)
|
|
|
|
set(__visibility INTERFACE)
|
|
|
|
endif()
|
2020-04-13 17:53:01 +00:00
|
|
|
|
|
|
|
get_target_property(__sources ${target} SOURCES)
|
|
|
|
foreach(__src IN LISTS __sources)
|
|
|
|
string(REGEX MATCH ".*/qrc_.*\\.cpp$" __qrc ${__src})
|
2020-04-14 09:20:01 +00:00
|
|
|
if(__qrc)
|
2020-04-13 17:53:01 +00:00
|
|
|
set_property(SOURCE ${__qrc} PROPERTY COTIRE_EXCLUDED ON)
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
2020-04-13 16:44:42 +00:00
|
|
|
target_compile_features(${target} ${__visibility} ${COMMON_CXX_FEATURES})
|
2020-04-22 16:14:03 +00:00
|
|
|
if(_targetType STREQUAL "EXECUTABLE")
|
|
|
|
set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY
|
|
|
|
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
|
|
|
|
if(CMAKE_CXX_COMPILE_OPTIONS_PIE)
|
|
|
|
target_compile_options(${target} PUBLIC "${CMAKE_CXX_COMPILE_OPTIONS_PIE}")
|
|
|
|
endif()
|
2019-02-21 10:42:38 +00:00
|
|
|
endif()
|
2020-06-26 01:04:38 +00:00
|
|
|
|
2019-12-03 16:23:14 +00:00
|
|
|
target_include_directories(
|
2020-04-13 16:44:42 +00:00
|
|
|
${target}
|
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>)
|
2020-06-26 01:04:38 +00:00
|
|
|
|
2019-02-12 16:31:17 +00:00
|
|
|
if(APPLE)
|
2020-04-13 16:44:42 +00:00
|
|
|
target_compile_definitions(${target} ${__visibility} Darwin)
|
2019-02-12 16:31:17 +00:00
|
|
|
endif()
|
2020-06-26 01:04:38 +00:00
|
|
|
|
2019-02-12 16:31:17 +00:00
|
|
|
if(NOT __interface)
|
|
|
|
if(TARGET Qt5::Core)
|
2019-10-07 10:52:50 +00:00
|
|
|
if(_targetType STREQUAL "EXECUTABLE")
|
2020-04-13 16:44:42 +00:00
|
|
|
target_compile_options(${target} PUBLIC "${Qt5Core_EXECUTABLE_COMPILE_FLAGS}")
|
2019-02-21 10:42:38 +00:00
|
|
|
endif()
|
2020-04-25 14:35:24 +00:00
|
|
|
if(NOT CMLIB_DEBUG_OUTPUT)
|
|
|
|
add_definitions(-DQT_NO_DEBUG_OUTPUT)
|
|
|
|
endif()
|
|
|
|
if(NOT CMLIB_INFO_OUTPUT)
|
|
|
|
add_definitions(-DQT_NO_INFO_OUTPUT)
|
|
|
|
endif()
|
|
|
|
if(NOT CMLIB_WARNING_OUTPUT)
|
|
|
|
add_definitions(-DQT_NO_WARNING_OUTPUT)
|
|
|
|
endif()
|
2019-02-12 16:31:17 +00:00
|
|
|
endif()
|
|
|
|
if(CMAKE_CXX_COMPILER_IS_GCC AND NOT APPLE)
|
2020-06-26 01:09:40 +00:00
|
|
|
set_property(TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--no-as-needed")
|
2019-02-12 16:31:17 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2019-10-09 14:10:17 +00:00
|
|
|
# LTO only for executables (not libraries) in Release build type
|
2020-06-26 01:04:38 +00:00
|
|
|
if(_targetType STREQUAL "EXECUTABLE" AND CMAKE_BUILD_TYPE STREQUAL "Release")
|
2019-10-09 14:10:17 +00:00
|
|
|
check_cxx_compiler_flag(-flto CXX_HAS_LTO_FLAG)
|
|
|
|
check_cxx_compiler_flag(-fno-fat-lto-objects CXX_HAS_NO_FAT_LTO_FLAG)
|
2020-06-25 08:30:48 +00:00
|
|
|
if(CXX_HAS_LTO_FLAG)
|
2020-06-26 01:04:38 +00:00
|
|
|
target_compile_options(${target} PUBLIC "-flto")
|
2020-06-26 01:09:40 +00:00
|
|
|
set_property(TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS " -flto")
|
2020-06-25 08:30:48 +00:00
|
|
|
if(CXX_HAS_NO_FAT_LTO_FLAG)
|
2020-06-26 01:04:38 +00:00
|
|
|
target_compile_options(${target} PUBLIC "-fno-fat-lto-objects")
|
2020-06-26 01:09:40 +00:00
|
|
|
set_property(TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS " -fno-fat-lto-objects")
|
2019-10-09 14:10:17 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2021-05-30 17:32:08 +00:00
|
|
|
# cmake-format: off
|
|
|
|
set_property(TARGET ${target}
|
|
|
|
PROPERTY COTIRE_ENABLE_PRECOMPILED_HEADER ${CMLIB_COTIRE_ENABLE_PRECOMPILED_HEADER})
|
|
|
|
set_property(TARGET ${target}
|
|
|
|
PROPERTY COTIRE_ADD_UNITY_BUILD ${CMLIB_COTIRE_ADD_UNITY_BUILD})
|
|
|
|
# cmake-format: on
|
2020-04-18 18:03:03 +00:00
|
|
|
|
2020-03-30 08:44:45 +00:00
|
|
|
if(CMAKE_BUILD_TYPE STREQUAL Profile)
|
2020-04-13 16:44:42 +00:00
|
|
|
target_compile_definitions(${target} ${__visibility} PROFILE)
|
2020-03-30 08:44:45 +00:00
|
|
|
elseif(CMAKE_BUILD_TYPE STREQUAL Debug)
|
2020-04-13 16:44:42 +00:00
|
|
|
target_compile_definitions(${target} ${__visibility} DEBUG)
|
2020-03-30 08:44:45 +00:00
|
|
|
elseif(CMAKE_BUILD_TYPE STREQUAL Release)
|
2020-04-13 16:44:42 +00:00
|
|
|
target_compile_definitions(${target} ${__visibility} RELEASE)
|
2020-03-30 08:44:45 +00:00
|
|
|
elseif(CMAKE_BUILD_TYPE STREQUAL None)
|
2020-04-13 16:44:42 +00:00
|
|
|
target_compile_definitions(${target} ${__visibility} ANALYSIS)
|
2020-03-30 08:44:45 +00:00
|
|
|
endif()
|
2021-05-30 17:32:08 +00:00
|
|
|
target_compile_definitions(${target} ${__visibility} "TARGET_LSB_ID_${LSB_DISTRIBUTOR_ID}")
|
|
|
|
target_compile_definitions(${target} ${__visibility} "TARGET_LSB_CODENAME_${LSB_CODENAME}")
|
2019-02-12 16:31:17 +00:00
|
|
|
endfunction()
|