From 9cb5583461066ef08e0258218c2a3a850e6aeb79 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sun, 24 Mar 2024 22:05:51 +0800 Subject: [PATCH] build: add LTO compile option --- CMakeLists.txt | 15 ++++++++++----- third_party/ThirdParty.cmake | 1 - 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 50609c4..0c9c29f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,8 +4,9 @@ project(md5sum LANGUAGES CXX) # ------------------------------------------------------------------------------------ # option(MD5_SHARED_LIB "Built as a dynamic library." OFF) -option(MD5_ENABLE_TESTING "Enable testing of the md5sum library." ON) -option(MD5_ENABLE_BENCHMARK "Enable benchmark of the md5sum library." ON) +option(MD5_ENABLE_LTO "Enable LTO optimization of the library." ON) +option(MD5_ENABLE_TESTING "Enable testing of the md5sum library." OFF) +option(MD5_ENABLE_BENCHMARK "Enable benchmark of the md5sum library." OFF) # ------------------------------------------------------------------------------------ # @@ -30,7 +31,11 @@ set(CMAKE_CXX_STANDARD ${MD5_CXX_STANDARD}) if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) # using release build in default endif() -add_compile_options(-Wall -Wextra) + +add_compile_options(-Wall -Wextra -Werror) +if (MD5_ENABLE_LTO) + add_compile_options(-flto=auto) +endif() file(GLOB MD5_SRC src/impl/*.cc) if (NOT MD5_SHARED_LIB) @@ -41,7 +46,7 @@ else() endif() target_include_directories(md5sum PUBLIC src/) -set(MD5_COMPILE_OPTIONS -fno-rtti -fno-exceptions -pedantic) +set(MD5_COMPILE_OPTIONS -fno-rtti -fno-exceptions) target_compile_options(md5sum PRIVATE ${MD5_COMPILE_OPTIONS}) add_library(md5sum::md5sum ALIAS md5sum) @@ -61,7 +66,7 @@ endif() if (MD5_ENABLE_BENCHMARK) add_executable(md5_benchmark benchmark.cc) target_link_libraries(md5_benchmark PRIVATE md5sum benchmark::benchmark_main) - target_compile_options(md5_benchmark PRIVATE -fno-rtti -fno-exceptions) + target_compile_options(md5_benchmark PRIVATE ${MD5_COMPILE_OPTIONS}) endif() # ------------------------------------------------------------------------------------ # diff --git a/third_party/ThirdParty.cmake b/third_party/ThirdParty.cmake index 8356d91..a49bfe0 100644 --- a/third_party/ThirdParty.cmake +++ b/third_party/ThirdParty.cmake @@ -3,7 +3,6 @@ if (MD5_ENABLE_TESTING) endif() if (MD5_ENABLE_BENCHMARK) - set(BENCHMARK_ENABLE_LTO ON) set(BENCHMARK_ENABLE_TESTING OFF) set(BENCHMARK_ENABLE_EXCEPTIONS OFF) add_subdirectory(third_party/benchmark/ EXCLUDE_FROM_ALL)