Added `WHOLE_PROGRAM_OPTIMIZATION` option to the CMake file

This commit is contained in:
flobernd 2018-02-27 23:56:43 +01:00
parent 5a90a4d628
commit dd90a66d99
No known key found for this signature in database
GPG Key ID: 9C3AE0ED4A969F10
1 changed files with 24 additions and 0 deletions

View File

@ -26,6 +26,9 @@ option(ZYDIS_FEATURE_MVEX
option(BUILD_SHARED_LIBS
"Build shared libraries"
OFF)
option(WHOLE_PROGRAM_OPTIMIZATION
"Enable whole program optimization"
OFF)
option(ZYDIS_NO_LIBC
"Don't use any C standard library functions (for exotic build-envs like kernel drivers)"
OFF)
@ -70,6 +73,11 @@ target_include_directories("Zydis"
PUBLIC "include" ${PROJECT_BINARY_DIR}
PRIVATE "src")
target_compile_definitions("Zydis" PRIVATE "_CRT_SECURE_NO_WARNINGS" "ZYDIS_EXPORTS")
if (WHOLE_PROGRAM_OPTIMIZATION AND MSVC)
set_target_properties("Zydis" PROPERTIES COMPILE_FLAGS "/GL")
set_target_properties("Zydis" PROPERTIES LINK_FLAGS_RELEASE "/LTCG")
set_target_properties("Zydis" PROPERTIES STATIC_LIBRARY_FLAGS_RELEASE "/LTCG")
endif ()
generate_export_header("Zydis" BASE_NAME "ZYDIS" EXPORT_FILE_NAME "ZydisExportConfig.h")
if (NOT ZYDIS_FEATURE_ENCODER AND NOT ZYDIS_FEATURE_DECODER)
@ -159,6 +167,10 @@ if (ZYDIS_BUILD_EXAMPLES)
target_link_libraries("ZydisFuzzIn" "Zydis")
set_target_properties("FormatterHooks" PROPERTIES FOLDER "Examples")
target_compile_definitions("ZydisFuzzIn" PRIVATE "_CRT_SECURE_NO_WARNINGS")
if (WHOLE_PROGRAM_OPTIMIZATION AND MSVC)
set_target_properties("ZydisFuzzIn" PROPERTIES COMPILE_FLAGS "/GL")
set_target_properties("ZydisFuzzIn" PROPERTIES LINK_FLAGS_RELEASE "/LTCG")
endif ()
if (ZYDIS_FUZZ_AFL_FAST)
target_compile_definitions("ZydisFuzzIn" PRIVATE "ZYDIS_FUZZ_AFL_FAST")
endif ()
@ -167,6 +179,10 @@ if (ZYDIS_BUILD_EXAMPLES)
target_link_libraries("ZydisPerfTest" "Zydis")
set_target_properties("FormatterHooks" PROPERTIES FOLDER "Examples")
target_compile_definitions("ZydisPerfTest" PRIVATE "_CRT_SECURE_NO_WARNINGS")
if (WHOLE_PROGRAM_OPTIMIZATION AND MSVC)
set_target_properties("ZydisPerfTest" PROPERTIES COMPILE_FLAGS "/GL")
set_target_properties("ZydisPerfTest" PROPERTIES LINK_FLAGS_RELEASE "/LTCG")
endif ()
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
target_compile_definitions("ZydisPerfTest" PRIVATE "_GNU_SOURCE")
find_package(Threads REQUIRED)
@ -185,10 +201,18 @@ if (ZYDIS_BUILD_TOOLS)
target_link_libraries("ZydisDisasm" "Zydis")
set_target_properties ("ZydisDisasm" PROPERTIES FOLDER "Tools")
target_compile_definitions("ZydisDisasm" PRIVATE "_CRT_SECURE_NO_WARNINGS")
if (WHOLE_PROGRAM_OPTIMIZATION AND MSVC)
set_target_properties("ZydisDisasm" PROPERTIES COMPILE_FLAGS "/GL")
set_target_properties("ZydisDisasm" PROPERTIES LINK_FLAGS_RELEASE "/LTCG")
endif ()
add_executable("ZydisInfo" "tools/ZydisInfo.c")
target_link_libraries("ZydisInfo" "Zydis")
set_target_properties ("ZydisInfo" PROPERTIES FOLDER "Tools")
target_compile_definitions("ZydisInfo" PRIVATE "_CRT_SECURE_NO_WARNINGS")
if (WHOLE_PROGRAM_OPTIMIZATION AND MSVC)
set_target_properties("ZydisInfo" PROPERTIES COMPILE_FLAGS "/GL")
set_target_properties("ZydisInfo" PROPERTIES LINK_FLAGS_RELEASE "/LTCG")
endif ()
endif ()
endif ()