@@ -92,13 +92,11 @@ set(linyaps-box_ACTIVE_LOG_LEVEL
9292
9393set (linyaps-box_ENABLE_CPM
9494 OFF
95- CACHE BOOL "enable CPM"
96- )
95+ CACHE BOOL "enable CPM" )
9796
9897set (linyaps-box_HARDENING
9998 ON
100- CACHE BOOL "enable hardening"
101- )
99+ CACHE BOOL "enable hardening" )
102100
103101set (CMAKE_POSITION_INDEPENDENT_CODE ON )
104102
@@ -111,8 +109,7 @@ endif()
111109# if just want to try local packages at first set CPM_USE_LOCAL_PACKAGES ON
112110set (linyaps-box_CPM_LOCAL_PACKAGES_ONLY
113111 OFF
114- CACHE BOOL "use local packages only"
115- )
112+ CACHE BOOL "use local packages only" )
116113
117114# ==============================================================================
118115
@@ -122,10 +119,8 @@ if(linyaps-box_HARDENING)
122119 "${CMAKE_EXE_LINKER_FLAGS } -pie -Wl,-z,relro -Wl,-z,now" )
123120 add_compile_options (-fstack-protector-strong )
124121
125- if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug" )
126- message (STATUS "Non-Debug build, enabling FORTIFY_SOURCE" )
127- add_compile_definitions (_FORTIFY_SOURCE=2 )
128- endif ()
122+ message (STATUS "Non-Debug build, enabling FORTIFY_SOURCE" )
123+ add_compile_definitions ("$<$<NOT :$<CONFIG :Debug >>:_FORTIFY_SOURCE =2>" )
129124endif ()
130125
131126set (linyaps-box_LIBRARY linyaps-box)
@@ -295,11 +290,11 @@ if(linyaps-box_ENABLE_CPM)
295290 EXCLUDE_FROM_ALL ON
296291 OPTIONS "BUILD_TESTING OFF" )
297292 CPMFindPackage (
298- NAME fmt
299- VERSION 10.1.0
300- GITHUB_REPOSITORY fmtlib/fmt
301- GIT_TAG 12.2.0
302- EXCLUDE_FROM_ALL ON )
293+ NAME fmt
294+ VERSION 10.1.0
295+ GITHUB_REPOSITORY fmtlib/fmt
296+ GIT_TAG 12.2.0
297+ EXCLUDE_FROM_ALL ON )
303298endif ()
304299
305300# find minimal version
@@ -329,13 +324,11 @@ endif()
329324
330325list (APPEND linyaps-box_LIBRARY_LINK_LIBRARIES CLI11::CLI11)
331326
332- set (FMT_TARGET fmt::fmt)
333- if (linyaps-box_STATIC)
334- set (FMT_TARGET fmt::fmt-header-only)
335- endif ()
327+ set (FMT_TARGET
328+ "$<IF :$<BOOL :${linyaps-box_STATIC} >,fmt ::fmt -header -only ,fmt ::fmt >" )
336329
337330find_package (fmt 10.1.0 QUIET )
338- if (NOT fmt_FOUND)
331+ if (NOT fmt_FOUND)
339332 # if fmt is not found in local system. just use fmt::fmt with static linkage
340333 # for boosting compiling speed.
341334 set (FMT_TARGET fmt::fmt)
@@ -393,10 +386,9 @@ target_compile_definitions(
393386 "LINYAPS_BOX_ACTIVE_LOG_LEVEL=${linyaps-box_ACTIVE_LOG_LEVEL} " )
394387target_compile_options ("${linyaps-box_LIBRARY} "
395388 PRIVATE -fmacro-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=. )
396- if (linyaps-box_STATIC)
397- target_compile_definitions ("${linyaps-box_LIBRARY} "
398- PUBLIC "LINYAPS_BOX_STATIC_LINK" )
399- endif ()
389+ target_compile_definitions (
390+ "${linyaps-box_LIBRARY} "
391+ PUBLIC "$<$<BOOL :${linyaps-box_STATIC} >:LINYAPS_BOX_STATIC_LINK >" )
400392
401393if (linyaps-box_ENABLE_SECCOMP)
402394 target_compile_definitions ("${linyaps-box_LIBRARY} "
@@ -413,18 +405,22 @@ if(linyaps-box_ENABLE_CAP)
413405endif ()
414406
415407if (linyaps-box_ENABLE_COVERAGE)
416- if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
417- target_compile_options ("${linyaps-box_LIBRARY} "
418- PRIVATE -fprofile-instr-generate -fcoverage-mapping )
419- target_link_options ("${linyaps-box_LIBRARY} " PUBLIC
420- -fprofile-instr-generate -fcoverage-mapping )
421- elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
422- target_compile_options ("${linyaps-box_LIBRARY} " PRIVATE --coverage )
423- target_link_options ("${linyaps-box_LIBRARY} " PUBLIC --coverage )
424- else ()
408+ if (NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_CXX_COMPILER_ID
409+ STREQUAL "GNU" )
425410 message (
426411 FATAL_ERROR "Coverage is not supported for ${CMAKE_CXX_COMPILER_ID } ." )
427412 endif ()
413+ target_compile_options (
414+ "${linyaps-box_LIBRARY} "
415+ PRIVATE "$<$<CXX_COMPILER_ID :Clang ,AppleClang >:-fprofile -instr -generate >"
416+ "$<$<CXX_COMPILER_ID :Clang ,AppleClang >:-fcoverage -mapping >"
417+ "$<$<CXX_COMPILER_ID :GNU >:--coverage >" )
418+ target_link_options (
419+ "${linyaps-box_LIBRARY} "
420+ PUBLIC
421+ "$<$<CXX_COMPILER_ID :Clang ,AppleClang >:-fprofile -instr -generate >"
422+ "$<$<CXX_COMPILER_ID :Clang ,AppleClang >:-fcoverage -mapping >"
423+ "$<$<CXX_COMPILER_ID :GNU >:--coverage >" )
428424endif ()
429425
430426# ==============================================================================
@@ -439,10 +435,10 @@ add_executable("${linyaps-box_APP}" ${linyaps-box_APP_SOURCE})
439435target_include_directories ("${linyaps-box_APP} "
440436 ${linyaps-box_APP_SOURCE_INCLUDE_DIRS} )
441437target_link_libraries ("${linyaps-box_APP} " ${linyaps-box_APP_LINK_LIBRARIES} )
442- if (linyaps-box_STATIC)
443- target_link_options ( "${linyaps-box_APP} " PRIVATE -static -static-libgcc
444- - static-libstdc++ )
445- endif ( )
438+ target_link_options (
439+ "${linyaps-box_APP} " PRIVATE "$<$< BOOL : ${linyaps-box_STATIC} >: -static >"
440+ "$<$< BOOL : ${linyaps-box_STATIC} >:- static -libgcc >"
441+ "$<$< BOOL : ${linyaps-box_STATIC} >:- static - libstdc ++>" )
446442target_compile_features ("${linyaps-box_APP} " PRIVATE cxx_std_17 )
447443set_property (TARGET "${linyaps-box_APP} " PROPERTY CXX_STANDARD 17)
448444set_property (TARGET "${linyaps-box_APP} " PROPERTY CXX_EXTENSIONS OFF )
0 commit comments