Skip to content

Commit 18197ae

Browse files
Make some optimizations to the CMake build system
I profiled initial CMake configuration and generation (Ninja) steps in LLVM-Project with just LLVM, MLIR, and Clang enabled using the command shown below. Based on the profile, I then implemented a number of optimizations. Initial time of `cmake` command @ 679d2b2: -- Configuring done (17.8s) -- Generating done (6.9s) After all below optimizations: -- Configuring done (12.8s) -- Generating done (4.7s) With a "toolchain check cache" (explained below): -- Configuring done (6.9s) -- Generating done (4.3s) There's definitely room for more optimizations -- another 20% at least. Most changes have a small impact. It's the gradual creep of inefficiencies that have added up over time to make the system less efficient than it could be. Command tested: ``` cmake -G Ninja -S llvm -B ${buildDir} \ -DLLVM_ENABLE_PROJECTS="mlir;clang" \ -DLLVM_TARGETS_TO_BUILD="X86;NVPTX" \ -DCMAKE_BUILD_TYPE=RelWithDebInfo \ -DLLVM_ENABLE_ASSERTIONS=ON \ -DLLVM_CCACHE_BUILD=ON \ -DBUILD_SHARED_LIBS=ON \ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLLVM_USE_LINKER=lld \ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ -DMLIR_ENABLE_BINDINGS_PYTHON=ON \ -DLLVM_TOOLCHAIN_CHECK_CACHE=${PWD}/.toolchain-check-cache.cmake \ --fresh ``` ## Optimizations: ### Optimize `check_linker_flag` calls In `AddLLVM.cmake`, there were a couple places where we call `check_linker_flag` every time `llvm_add_library` is called. Even in non-initial cmake configuration runs, this carries unreasonable overhead. Change: Host (CheckLinkerFlag)` in AddLLVM.cmake and optimize placement of `check_linker_flag` calls so that they are only made once. Impact: - <1 sec ### Make `add_lit_testsuites` optional The function `add_lit_testsuites` is used to recursively populate a set of convenience targets that run a filtered portion of a LIT test suite. So instead of running `check-mlir` you can run `check-mlir-dialect`. These targets are built recursively for each subdirectory (e.g. `check-mlir-dialect-tensor`, `check-mlir-dialect-math`, etc.). This call has quite a bit of overhead, especially for the main LLVM LIT test suite. Personally I use a combination of `ninja -C build check-mlir-build-only` and `llvm-lit` directly to run filtered portions of the MLIR LIT test suite, but I can imagine that others depend on these filtered targets. Change: Introduce a new option `LLVM_ENABLE_LIT_CONVENIENCE_TARGETS` which defaults to `ON`. When set to `OFF`, the function `add_lit_testsuites` just becomes a no-op. It's possible that we could also just improve the performance of `add_lit_testsuites` directly, but I didn't pursue this. Impact: ~1-2sec ### Reduce `file(GLOB)` calls in `LLVMProcessSources.cmake` The `llvm_process_sources` call is made whenver the `llvm_add_library` function is called. It makes several `file(GLOB)` calls, which can be expensive depending on the underlying filesystem/storage. The function globs for headers and TD files to add as sources to the target, but the comments suggest that this is only necessary for MSVC. In addition, it calls `llvm_check_source_file_list` to check that no source files in the directory are unused unless `PARTIAL_SOURCES_INTENDED` is set, which incurs another `file(GLOB)` call. Changes: Guard the `file(GLOB)` calls for populating header sources behind `if(MSVC)`. Only do the `llvm_check_source_file_list` check if a new option `LLVM_ENABLE_EXPENSIVE_CMAKE_CHECKS` is set to `ON`. Impact: depends on system. On my local workstation, impact is minimal. On another remote server I use, impact is much larger. ### Optimize initial symbol/flag checks made in `config-ix.cmake` and `HandleLLVMOptions.cmake` The `config-ix.cmake` and `HandleLLVMOptions.cmake` files make a number of calls to compile C/C++ programs in order to verify the precense of certain symbols or whether certain compiler flags are supported. These checks have the biggest impact on an initial `cmake` configuration time. I propose an "opt in" approach for amortizing these checks using a special generated CMake cache file as directed by the developer. An option `LLVM_TOOLCHAIN_CHECK_CACHE` is introduced. It should be set to a path like `-DLLVM_TOOLCHAIN_CHECK_CACHE=$PWD/.toolchain-check-cache.cmake`. Before entering the `config-ix.cmake` and `HandleLLVMOptions.cmake` files, if the `LLVM_TOOLCHAIN_CHECK_CACHE` option is set and exists, include that file to pre-populate cache variables. Otherwise, we save the current set of CMake cache variables names. After calling the `config-ix|HandleLLVMOptions` files, if the `LLVM_TOOLCHAIN_CHECK_CACHE` option is set but does not exist, check what new CMake cache variables were set by those scripts. Filter these variables by whether they are likely cache variables supporting symbol/flag checks (e.g. `CXX_SUPPORTS_.*|HAVE_.*` etc) and write the file to set all these cache variables to their current values. This allows a developer to obviate any subsequent checks, even in initial `cmake` configuration runs. The correctness depends on the developer knowing when it is invalid (e.g. they change toolchains or platforms) and us suddenly not changing the meaning of `CXX_SUPPORTS_SOME_FLAG` to correspond to a different flag. It could be extended the cache file to store a key used to check whether to regenerate the cache, but I didn't go there. Impact: Trivial overhead for cache generation, ~5sec reduction in initial config time. ### Reduce overhead of embedded Google Benchmark configuration Note: technically this could be lumped in with the above if we expanded scope of before/after change that the `LLVM_TOOLCHAIN_CHECK_CACHE` covers. GoogleBenchmark is embedded under the `third-party/benchmark` directory. Its CMake script does a compilation check for each flag that it wants to populate (even for `-Wall`). In comparison, LLVM's HandleLLVMOptions.cmake script takes a faster approach by skipping as many compilation checks as possible if the cache variable `LLVM_COMPILER_IS_GCC_COMPATIBLE` is true. Changes: Use `LLVM_COMPILER_IS_GCC_COMPATIBLE` to skip as many compilation checks as possible in GoogleBenchmark. Impact: ~1-2sec
1 parent 679d2b2 commit 18197ae

File tree

5 files changed

+149
-52
lines changed

5 files changed

+149
-52
lines changed

llvm/CMakeLists.txt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,11 @@ option(LLVM_INSTALL_GTEST
867867
"Install the llvm gtest library. This should be on if you want to do
868868
stand-alone builds of the other projects and run their unit tests." OFF)
869869

870+
option(LLVM_ENABLE_EXPENSIVE_CMAKE_CHECKS
871+
"Enable use of expensive CMake checks for unused source files" ON)
872+
option(LLVM_ENABLE_LIT_CONVENIENCE_TARGETS
873+
"Enable use of convenience targets for all subdirectories of a LIT test suite" ON)
874+
870875
option(LLVM_BUILD_BENCHMARKS "Add LLVM benchmark targets to the list of default
871876
targets. If OFF, benchmarks still could be built using Benchmarks target." OFF)
872877
option(LLVM_INCLUDE_BENCHMARKS "Generate benchmark targets. If OFF, benchmarks can't be built." ON)
@@ -1027,9 +1032,18 @@ endif()
10271032
find_package(Python3 ${LLVM_MINIMUM_PYTHON_VERSION} REQUIRED
10281033
COMPONENTS Interpreter)
10291034

1035+
set(LLVM_TOOLCHAIN_CHECK_CACHE "" CACHE PATH
1036+
"Path to where a generated *.cmake cache file will be saved.")
1037+
1038+
include(LLVMCacheSnapshot)
10301039
# All options referred to from HandleLLVMOptions have to be specified
10311040
# BEFORE this include, otherwise options will not be correctly set on
1032-
# first cmake run
1041+
# first cmake run.
1042+
if(LLVM_TOOLCHAIN_CHECK_CACHE AND EXISTS "${LLVM_TOOLCHAIN_CHECK_CACHE}")
1043+
include("${LLVM_TOOLCHAIN_CHECK_CACHE}")
1044+
elseif(LLVM_TOOLCHAIN_CHECK_CACHE)
1045+
llvm_get_list_of_existing_cache_variables(cache_before)
1046+
endif()
10331047
include(config-ix)
10341048

10351049
# By default, we target the host, but this can be overridden at CMake
@@ -1081,6 +1095,12 @@ endif()
10811095

10821096
include(HandleLLVMOptions)
10831097

1098+
if(LLVM_TOOLCHAIN_CHECK_CACHE AND NOT EXISTS "${LLVM_TOOLCHAIN_CHECK_CACHE}")
1099+
llvm_list_of_new_cache_variables_and_values(cache_before cache_new_pairs)
1100+
list(JOIN cache_new_pairs "\n" cache_new_pairs_joined)
1101+
file(WRITE "${LLVM_TOOLCHAIN_CHECK_CACHE}" "${cache_new_pairs_joined}")
1102+
endif()
1103+
10841104
######
10851105

10861106
# Configure all of the various header file fragments LLVM uses which depend on

llvm/cmake/modules/AddLLVM.cmake

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@ include(LLVMDistributionSupport)
33
include(LLVMProcessSources)
44
include(LLVM-Config)
55
include(DetermineGCCCompatible)
6+
include(CheckLinkerFlag)
67

78
# get_subproject_title(titlevar)
89
# Set ${outvar} to the title of the current LLVM subproject (Clang, MLIR ...)
9-
#
10+
#
1011
# The title is set in the subproject's top-level using the variable
1112
# LLVM_SUBPROJECT_TITLE. If it does not exist, it is assumed it is LLVM itself.
1213
# The title is not semantically significant, but use to create folders in
1314
# CMake-generated IDE projects (Visual Studio/XCode).
1415
function(get_subproject_title outvar)
1516
if (LLVM_SUBPROJECT_TITLE)
16-
set(${outvar} "${LLVM_SUBPROJECT_TITLE}" PARENT_SCOPE)
17+
set(${outvar} "${LLVM_SUBPROJECT_TITLE}" PARENT_SCOPE)
1718
else ()
1819
set(${outvar} "LLVM" PARENT_SCOPE)
1920
endif ()
@@ -269,7 +270,6 @@ if (NOT DEFINED LLVM_LINKER_DETECTED AND NOT WIN32)
269270
endif()
270271

271272
if("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
272-
include(CheckLinkerFlag)
273273
# Linkers that support Darwin allow a setting to internalize all symbol exports,
274274
# aiding in reducing binary size and often is applicable for executables.
275275
check_linker_flag(C "-Wl,-no_exported_symbols" LLVM_LINKER_SUPPORTS_NO_EXPORTED_SYMBOLS)
@@ -289,8 +289,23 @@ if (NOT DEFINED LLVM_LINKER_DETECTED AND NOT WIN32)
289289
endif()
290290
endif()
291291

292+
if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
293+
if(NOT LLVM_NO_DEAD_STRIP)
294+
if("${CMAKE_SYSTEM_NAME}" MATCHES "SunOS" AND LLVM_LINKER_IS_SOLARISLD)
295+
# Support for ld -z discard-unused=sections was only added in
296+
# Solaris 11.4. GNU ld ignores it, but warns every time.
297+
check_linker_flag(CXX "-Wl,-z,discard-unused=sections" LINKER_SUPPORTS_Z_DISCARD_UNUSED)
298+
endif()
299+
endif()
300+
endif()
301+
302+
# Check for existence of symbolic functions flag. Not supported
303+
# by the older BFD linker (such as on some OpenBSD archs), the
304+
# MinGW driver for LLD, and the Solaris native linker.
305+
check_linker_flag(CXX "-Wl,-Bsymbolic-functions"
306+
LLVM_LINKER_SUPPORTS_B_SYMBOLIC_FUNCTIONS)
307+
292308
function(add_link_opts target_name)
293-
include(CheckLinkerFlag)
294309
get_llvm_distribution(${target_name} in_distribution in_distribution_var)
295310
if(NOT in_distribution)
296311
# Don't LTO optimize targets that aren't part of any distribution.
@@ -320,9 +335,6 @@ function(add_link_opts target_name)
320335
set_property(TARGET ${target_name} APPEND_STRING PROPERTY
321336
LINK_FLAGS " -Wl,-dead_strip")
322337
elseif("${CMAKE_SYSTEM_NAME}" MATCHES "SunOS" AND LLVM_LINKER_IS_SOLARISLD)
323-
# Support for ld -z discard-unused=sections was only added in
324-
# Solaris 11.4. GNU ld ignores it, but warns every time.
325-
check_linker_flag(CXX "-Wl,-z,discard-unused=sections" LINKER_SUPPORTS_Z_DISCARD_UNUSED)
326338
if (LINKER_SUPPORTS_Z_DISCARD_UNUSED)
327339
set_property(TARGET ${target_name} APPEND_STRING PROPERTY
328340
LINK_FLAGS " -Wl,-z,discard-unused=sections")
@@ -349,12 +361,6 @@ function(add_link_opts target_name)
349361
set_property(TARGET ${target_name} APPEND_STRING PROPERTY
350362
LINK_FLAGS " -Wl,-brtl")
351363
endif()
352-
353-
# Check for existence of symbolic functions flag. Not supported
354-
# by the older BFD linker (such as on some OpenBSD archs), the
355-
# MinGW driver for LLD, and the Solaris native linker.
356-
check_linker_flag(CXX "-Wl,-Bsymbolic-functions"
357-
LLVM_LINKER_SUPPORTS_B_SYMBOLIC_FUNCTIONS)
358364
endfunction(add_link_opts)
359365

360366
# Set each output directory according to ${CMAKE_CONFIGURATION_TYPES}.
@@ -645,11 +651,11 @@ function(llvm_add_library name)
645651
endif()
646652
set_target_properties(${name} PROPERTIES FOLDER "${subproject_title}/Libraries")
647653

648-
## If were compiling with clang-cl use /Zc:dllexportInlines- to exclude inline
654+
## If were compiling with clang-cl use /Zc:dllexportInlines- to exclude inline
649655
## class members from being dllexport'ed to reduce compile time.
650656
## This will also keep us below the 64k exported symbol limit
651657
## https://blog.llvm.org/2018/11/30-faster-windows-builds-with-clang-cl_14.html
652-
if(LLVM_BUILD_LLVM_DYLIB AND NOT LLVM_DYLIB_EXPORT_INLINES AND
658+
if(LLVM_BUILD_LLVM_DYLIB AND NOT LLVM_DYLIB_EXPORT_INLINES AND
653659
MSVC AND CMAKE_CXX_COMPILER_ID MATCHES Clang)
654660
target_compile_options(${name} PUBLIC /Zc:dllexportInlines-)
655661
if(TARGET ${obj_name})
@@ -1500,8 +1506,8 @@ macro(llvm_add_tool project name)
15001506
RUNTIME DESTINATION ${${project}_TOOLS_INSTALL_DIR}
15011507
COMPONENT ${name})
15021508
if (LLVM_ENABLE_PDB)
1503-
install(FILES $<TARGET_PDB_FILE:${name}>
1504-
DESTINATION "${${project}_TOOLS_INSTALL_DIR}" COMPONENT ${name}
1509+
install(FILES $<TARGET_PDB_FILE:${name}>
1510+
DESTINATION "${${project}_TOOLS_INSTALL_DIR}" COMPONENT ${name}
15051511
OPTIONAL)
15061512
endif()
15071513

@@ -1535,8 +1541,8 @@ macro(add_llvm_example name)
15351541
if( LLVM_BUILD_EXAMPLES )
15361542
install(TARGETS ${name} RUNTIME DESTINATION "${LLVM_EXAMPLES_INSTALL_DIR}")
15371543
if (LLVM_ENABLE_PDB)
1538-
install(FILES $<TARGET_PDB_FILE:${name}>
1539-
DESTINATION "${LLVM_EXAMPLES_INSTALL_DIR}" COMPONENT ${name}
1544+
install(FILES $<TARGET_PDB_FILE:${name}>
1545+
DESTINATION "${LLVM_EXAMPLES_INSTALL_DIR}" COMPONENT ${name}
15401546
OPTIONAL)
15411547
endif()
15421548
endif()
@@ -1574,8 +1580,8 @@ macro(add_llvm_utility name)
15741580
RUNTIME DESTINATION ${LLVM_UTILS_INSTALL_DIR}
15751581
COMPONENT ${name})
15761582
if (LLVM_ENABLE_PDB)
1577-
install(FILES $<TARGET_PDB_FILE:${name}>
1578-
DESTINATION "${LLVM_UTILS_INSTALL_DIR}" COMPONENT ${name}
1583+
install(FILES $<TARGET_PDB_FILE:${name}>
1584+
DESTINATION "${LLVM_UTILS_INSTALL_DIR}" COMPONENT ${name}
15791585
OPTIONAL)
15801586
endif()
15811587

@@ -2192,6 +2198,9 @@ function(add_lit_testsuite target comment)
21922198
endfunction()
21932199

21942200
function(add_lit_testsuites project directory)
2201+
if(NOT LLVM_ENABLE_LIT_CONVENIENCE_TARGETS)
2202+
return()
2203+
endif()
21952204
if (NOT LLVM_ENABLE_IDE)
21962205
cmake_parse_arguments(ARG
21972206
"EXCLUDE_FROM_CHECK_ALL"
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Example usage
2+
# llvm_get_cache_vars(before)
3+
# include(SomeModule)
4+
# llvm_diff_cache_vars("${before}" new_vars new_pairs)
5+
6+
# message(STATUS "New cache variables: ${new_vars}")
7+
# message(STATUS "New cache vars and values:\n${new_pairs}")
8+
9+
# get_list_of_existing_cache_variables(existing)
10+
function(llvm_get_list_of_existing_cache_variables out_var)
11+
get_cmake_property(_all CACHE_VARIABLES)
12+
if(NOT _all)
13+
set(_all "")
14+
endif()
15+
set(${out_var} "${_all}" PARENT_SCOPE)
16+
endfunction()
17+
18+
# list_of_new_cache_variables_and_values(existing new_vars_and_values)
19+
# - `existing` is the name of the var returned by the first helper
20+
# - `new_vars_and_values` will be a list like: NAME=VALUE (TYPE=...);NAME2=VALUE2 (TYPE=...)
21+
function(llvm_list_of_new_cache_variables_and_values existing_list_var out_var)
22+
# Existing (pre-include) snapshot
23+
set(_before "${${existing_list_var}}")
24+
25+
# Current (post-include) snapshot
26+
get_cmake_property(_after CACHE_VARIABLES)
27+
28+
# Compute new names
29+
set(_new "${_after}")
30+
if(_before)
31+
list(REMOVE_ITEM _new ${_before})
32+
endif()
33+
34+
# Pack "NAME=VALUE (TYPE=...)" for each new cache entry
35+
set(_pairs "")
36+
foreach(_k IN LISTS _new)
37+
if(NOT "${_k}" MATCHES "^((C|CXX)_SUPPORTS|HAVE_|GLIBCXX_USE|SUPPORTS_FVISI)")
38+
continue()
39+
endif()
40+
# Cache VALUE: dereference is fine here because cache entries read like normal vars
41+
set(_val "${${_k}}")
42+
# Cache TYPE (e.g., STRING, BOOL, PATH, FILEPATH, INTERNAL, UNINITIALIZED)
43+
get_property(_type CACHE "${_k}" PROPERTY TYPE)
44+
if(NOT _type)
45+
set(_type "UNINITIALIZED")
46+
endif()
47+
list(APPEND _pairs "set(${_k} \"${_val}\" CACHE ${_type} \"\")")
48+
endforeach()
49+
50+
set(${out_var} "${_pairs}" PARENT_SCOPE)
51+
endfunction()

llvm/cmake/modules/LLVMProcessSources.cmake

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,25 @@ endfunction(find_all_header_files)
5656
function(llvm_process_sources OUT_VAR)
5757
cmake_parse_arguments(ARG "PARTIAL_SOURCES_INTENDED" "" "ADDITIONAL_HEADERS;ADDITIONAL_HEADER_DIRS" ${ARGN})
5858
set(sources ${ARG_UNPARSED_ARGUMENTS})
59-
llvm_check_source_file_list(${sources})
6059

61-
# This adds .td and .h files to the Visual Studio solution:
62-
add_td_sources(sources)
63-
find_all_header_files(hdrs "${ARG_ADDITIONAL_HEADER_DIRS}")
64-
if (hdrs)
65-
set_source_files_properties(${hdrs} PROPERTIES HEADER_FILE_ONLY ON)
60+
if(LLVM_ENABLE_EXPENSIVE_CMAKE_CHECKS)
61+
llvm_check_source_file_list(${sources})
62+
endif()
63+
64+
if(ARG_ADDITIONAL_HEADERS)
65+
set_source_files_properties(${ARG_ADDITIONAL_HEADERS} PROPERTIES HEADER_FILE_ONLY ON)
66+
list(APPEND sources ${ARG_ADDITIONAL_HEADERS})
6667
endif()
67-
set_source_files_properties(${ARG_ADDITIONAL_HEADERS} PROPERTIES HEADER_FILE_ONLY ON)
68-
list(APPEND sources ${ARG_ADDITIONAL_HEADERS} ${hdrs})
6968

69+
# This adds .td and .h files to the Visual Studio solution:
70+
if(MSVC OR LLVM_ENABLE_EXPENSIVE_CMAKE_CHECKS)
71+
add_td_sources(sources)
72+
find_all_header_files(hdrs "${ARG_ADDITIONAL_HEADER_DIRS}")
73+
if (hdrs)
74+
set_source_files_properties(${hdrs} PROPERTIES HEADER_FILE_ONLY ON)
75+
endif()
76+
list(APPEND sources ${hdrs})
77+
endif()
7078
set( ${OUT_VAR} ${sources} PARENT_SCOPE )
7179
endfunction(llvm_process_sources)
7280

third-party/benchmark/CMakeLists.txt

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,15 @@ endif()
147147
set(CMAKE_CXX_STANDARD ${BENCHMARK_CXX_STANDARD})
148148
set(CMAKE_CXX_STANDARD_REQUIRED YES)
149149
set(CMAKE_CXX_EXTENSIONS OFF)
150+
option(BENCHMARK_ENABLE_EXPENSIVE_CMAKE_CHECKS "Enable use of expensive CMake checks for unused source files" ON)
151+
152+
macro(handle_flag flag)
153+
if(LLVM_COMPILER_IS_GCC_COMPATIBLE AND NOT BENCHMARK_ENABLE_EXPENSIVE_CMAKE_CHECKS)
154+
list(APPEND CMAKE_CXX_FLAGS ${flag})
155+
else()
156+
add_cxx_compiler_flag(${flag})
157+
endif()
158+
endmacro()
150159

151160
if (MSVC)
152161
# Turn compiler warnings up to 11
@@ -185,49 +194,49 @@ else()
185194
add_definitions(-D_LARGEFILE64_SOURCE)
186195
add_definitions(-D_LARGEFILE_SOURCE)
187196
# Turn compiler warnings up to 11
188-
add_cxx_compiler_flag(-Wall)
189-
add_cxx_compiler_flag(-Wextra)
190-
add_cxx_compiler_flag(-Wshadow)
191-
add_cxx_compiler_flag(-Wfloat-equal)
192-
add_cxx_compiler_flag(-Wold-style-cast)
197+
handle_flag(-Wall)
198+
handle_flag(-Wextra)
199+
handle_flag(-Wshadow)
200+
handle_flag(-Wfloat-equal)
201+
handle_flag(-Wold-style-cast)
193202
if(BENCHMARK_ENABLE_WERROR)
194-
add_cxx_compiler_flag(-Werror)
203+
handle_flag(-Werror)
195204
endif()
196205
if (NOT BENCHMARK_ENABLE_TESTING)
197206
# Disable warning when compiling tests as gtest does not use 'override'.
198-
add_cxx_compiler_flag(-Wsuggest-override)
207+
handle_flag(-Wsuggest-override)
199208
endif()
200-
add_cxx_compiler_flag(-pedantic)
201-
add_cxx_compiler_flag(-pedantic-errors)
202-
add_cxx_compiler_flag(-Wshorten-64-to-32)
203-
add_cxx_compiler_flag(-fstrict-aliasing)
209+
handle_flag(-pedantic)
210+
handle_flag(-pedantic-errors)
211+
handle_flag(-Wshorten-64-to-32)
212+
handle_flag(-fstrict-aliasing)
204213
# Disable warnings regarding deprecated parts of the library while building
205214
# and testing those parts of the library.
206-
add_cxx_compiler_flag(-Wno-deprecated-declarations)
215+
handle_flag(-Wno-deprecated-declarations)
207216
if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" OR CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")
208217
# Intel silently ignores '-Wno-deprecated-declarations',
209218
# warning no. 1786 must be explicitly disabled.
210219
# See #631 for rationale.
211-
add_cxx_compiler_flag(-wd1786)
212-
add_cxx_compiler_flag(-fno-finite-math-only)
220+
handle_flag(-wd1786)
221+
handle_flag(-fno-finite-math-only)
213222
endif()
214223
# Disable deprecation warnings for release builds (when -Werror is enabled).
215224
if(BENCHMARK_ENABLE_WERROR)
216-
add_cxx_compiler_flag(-Wno-deprecated)
225+
handle_flag(-Wno-deprecated)
217226
endif()
218227
if (NOT BENCHMARK_ENABLE_EXCEPTIONS)
219-
add_cxx_compiler_flag(-fno-exceptions)
228+
handle_flag(-fno-exceptions)
220229
endif()
221230

222231
if (HAVE_CXX_FLAG_FSTRICT_ALIASING)
223232
if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM") #ICC17u2: Many false positives for Wstrict-aliasing
224-
add_cxx_compiler_flag(-Wstrict-aliasing)
233+
handle_flag(-Wstrict-aliasing)
225234
endif()
226235
endif()
227236
# ICC17u2: overloaded virtual function "benchmark::Fixture::SetUp" is only partially overridden
228237
# (because of deprecated overload)
229-
add_cxx_compiler_flag(-wd654)
230-
add_cxx_compiler_flag(-Wthread-safety)
238+
handle_flag(-wd654)
239+
handle_flag(-Wthread-safety)
231240
if (HAVE_CXX_FLAG_WTHREAD_SAFETY)
232241
cxx_feature_check(THREAD_SAFETY_ATTRIBUTES "-DINCLUDE_DIRECTORIES=${PROJECT_SOURCE_DIR}/include")
233242
endif()
@@ -246,8 +255,8 @@ else()
246255

247256
# Link time optimisation
248257
if (BENCHMARK_ENABLE_LTO)
249-
add_cxx_compiler_flag(-flto)
250-
add_cxx_compiler_flag(-Wno-lto-type-mismatch)
258+
handle_flag(-flto)
259+
handle_flag(-Wno-lto-type-mismatch)
251260
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
252261
find_program(GCC_AR gcc-ar)
253262
if (GCC_AR)
@@ -278,7 +287,7 @@ else()
278287
BENCHMARK_SHARED_LINKER_FLAGS_COVERAGE)
279288
set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING
280289
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Coverage.")
281-
add_cxx_compiler_flag(--coverage COVERAGE)
290+
handle_flag(--coverage COVERAGE)
282291
endif()
283292

284293
if (BENCHMARK_USE_LIBCXX)

0 commit comments

Comments
 (0)