首页 > 其他分享 >Configure CMake Compile and Link Options with Generator Expression

Configure CMake Compile and Link Options with Generator Expression

时间:2022-10-16 07:44:27浏览次数:46  
标签:Enable CMake Configure Generator frame PRIVATE fsanitize address pointer

target_compile_options(${PROJECT_NAME}
    PRIVATE
        # Enable All Warnings
        $<$<CXX_COMPILER_ID:MSVC>:/W4 /sdl>
        $<$<CXX_COMPILER_ID:GNU>:-Wall -Wextra>
        $<$<CXX_COMPILER_ID:Clang,AppleClang>:
            -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic>

    PRIVATE
        # Enable Optimizations
        $<$<CXX_COMPILER_ID:MSVC>:
            $<$<CONFIG:Debug>:/Od /GS /RTC1>
            $<$<CONFIG:Release>:/O2 /Oi /Ot /GL /Gy>
        >
        $<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:
            $<$<CONFIG:Debug>:-O0>
            $<$<CONFIG:Release>:-O3 -march=native>
        >

    PRIVATE
        # Enable Address Sanitizer
        $<$<CXX_COMPILER_ID:GNU,Clang>:
            $<$<VERSION_GREATER:${CMAKE_VERSION},3.12>:
                $<$<CONFIG:Debug>:-fsanitize=address -fno-omit-frame-pointer>
                $<$<CONFIG:RelWithDebInfo>:-fsanitize=address -fno-omit-frame-pointer>
            >
        >
)

if (${CMAKE_VERSION} VERSION_GREATER 3.12)
    target_link_options(${PROJECT_NAME}
        PRIVATE
            # Enable Address Sanitizer
            $<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:
                $<$<CONFIG:Debug>:-fsanitize=address -fno-omit-frame-pointer>
                $<$<CONFIG:RelWithDebInfo>:-fsanitize=address -fno-omit-frame-pointer>
            >
    )
endif()

标签:Enable,CMake,Configure,Generator,frame,PRIVATE,fsanitize,address,pointer
From: https://www.cnblogs.com/fang-d/p/16795582.html

相关文章