Skip to content

Commit aa6500a

Browse files
authored
fixed #13147 - some CMake cleanups (danmar#7260)
- use `VERSION_GREATER_EQUAL` in CMake it was introduced in CMake 3.7 - removed CMake option `ANALYZE_DATAFLOW` it cannot be used on its own - it generates data which can be leveraged by tools - fixed #13147 - deprecated `WARNINGS_ARE_ERRORS` in favor of `CMAKE_COMPILE_WARNING_AS_ERROR` - cmake/options.cmake: added some messages and bailouts instead of modifying/ignoring options silently
1 parent 69c0cbf commit aa6500a

File tree

5 files changed

+30
-26
lines changed

5 files changed

+30
-26
lines changed

cmake/compilerDefinitions.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ endif()
1616
if(CPPCHK_GLIBCXX_DEBUG AND UNIX AND CMAKE_BUILD_TYPE STREQUAL "Debug")
1717
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
1818
if(USE_LIBCXX)
19-
if(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 18 OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 18)
19+
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 18)
2020
add_definitions(-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG)
2121
else()
2222
add_definitions(-D_LIBCPP_ENABLE_ASSERTIONS=1)

cmake/compileroptions.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang"
3333
# "Release" uses -O3 by default
3434
add_compile_options(-O2)
3535
endif()
36-
if(WARNINGS_ARE_ERRORS)
36+
if(CMAKE_COMPILE_WARNING_AS_ERROR)
3737
add_compile_options(-Werror)
3838
endif()
3939
add_compile_options(-pedantic) # TODO: is this implied by -Weverything?
@@ -86,7 +86,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
8686
#add_compile_options_safe(-Wunused-macros)
8787
#add_compile_options_safe(-Wpedantic)
8888
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
89-
if(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 14 OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 14)
89+
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 14)
9090
# TODO: verify this regression still exists in clang-15
9191
if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
9292
# work around performance regression - see https://github.com/llvm/llvm-project/issues/53555
@@ -158,7 +158,7 @@ if(MSVC)
158158
# General
159159
add_compile_options(/W4) # Warning Level
160160
add_compile_options(/Zi) # Debug Information Format - Program Database
161-
if(WARNINGS_ARE_ERRORS)
161+
if(CMAKE_COMPILE_WARNING_AS_ERROR)
162162
add_compile_options(/WX) # Treat Warning As Errors
163163
endif()
164164
add_compile_options(/MP) # Multi-processor Compilation

cmake/dynamic_analyzer_options.cmake

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,3 @@ if(ANALYZE_UNDEFINED)
3131
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=nullability")
3232
endif()
3333
endif()
34-
35-
if(ANALYZE_DATAFLOW)
36-
add_compile_options(-fsanitize=dataflow)
37-
38-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=dataflow")
39-
endif()

cmake/options.cmake

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,28 @@ if(DEFINED CMAKE_BUILD_TYPE)
66
endif()
77

88
if(NOT CMAKE_BUILD_TYPE)
9+
message(STATUS "No build type set - defaulting to Debug")
910
set(CMAKE_BUILD_TYPE "Debug")
1011
endif()
1112

1213
# ----------------------------------------------------------------------------
1314
# PROJECT CONFIGURATION
1415
# ----------------------------------------------------------------------------
15-
option(ANALYZE_MEMORY "Clang dynamic analyzer: detector of uninitialized reads." OFF)
16-
option(ANALYZE_ADDRESS "Clang dynamic analyzer: fast memory error detector. " OFF)
17-
option(ANALYZE_THREAD "Clang dynamic analyzer: tool that detects data races. " OFF)
18-
option(ANALYZE_UNDEFINED "Clang dynamic analyzer: undefined behavior checker. " OFF)
19-
option(ANALYZE_DATAFLOW "Clang dynamic analyzer: general dynamic dataflow analysis." OFF)
16+
option(ANALYZE_MEMORY "Build with MemorySanitizer to detect usage of uninitialized memory" OFF)
17+
if(ANALYZE_MEMORY)
18+
message(STATUS "MemorySanitzer requires an instrumented libc++")
19+
endif()
20+
option(ANALYZE_ADDRESS "Build with AddressSanitzer to detect memory error" OFF)
21+
option(ANALYZE_THREAD "Build with ThreadSanitizer to detect data races" OFF)
22+
option(ANALYZE_UNDEFINED "Build with UndefinedBehaviorSanitizer to detect undefined behavior" OFF)
2023

2124
option(WARNINGS_ARE_ERRORS "Treat warnings as errors" OFF)
25+
if(WARNINGS_ARE_ERRORS)
26+
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24")
27+
message(WARNING "WARNINGS_ARE_ERRORS is deprecated - please use CMAKE_COMPILE_WARNING_AS_ERROR instead")
28+
endif()
29+
set(CMAKE_COMPILE_WARNING_AS_ERROR On)
30+
endif()
2231
option(EXTERNALS_AS_SYSTEM "Treat externals as system includes" OFF)
2332

2433
set(USE_MATCHCOMPILER "Auto" CACHE STRING "Usage of match compiler")
@@ -42,8 +51,8 @@ else()
4251
endif()
4352

4453
option(BUILD_CORE_DLL "Build lib as cppcheck-core.dll with Visual Studio" OFF)
45-
if(NOT MSVC)
46-
set(BUILD_CORE_DLL OFF)
54+
if(BUILD_CORE_DLL AND NOT MSVC)
55+
message(FATAL_ERROR "Building of lib as DLL is only supported with Visual Studio")
4756
endif()
4857
option(BUILD_TESTS "Build tests" OFF)
4958
option(REGISTER_TESTS "Register tests in CTest" ON)
@@ -60,19 +69,21 @@ option(REGISTER_GUI_TESTS "Register GUI tests in CTest"
6069
option(BUILD_ONLINE_HELP "Build online help" OFF)
6170

6271
option(HAVE_RULES "Usage of rules (needs PCRE library and headers)" OFF)
63-
option(USE_BUNDLED_TINYXML2 "Usage of bundled tinyxml2 library" ON)
64-
if(BUILD_CORE_DLL)
65-
set(USE_BUNDLED_TINYXML2 ON)
72+
option(USE_BUNDLED_TINYXML2 "Usage of bundled TinyXML2 library" ON)
73+
if(BUILD_CORE_DLL AND NOT USE_BUNDLED_TINYXML2)
74+
message(FATAL_ERROR "Cannot use external TinyXML2 library when building lib as DLL")
6675
endif()
6776
option(CPPCHK_GLIBCXX_DEBUG "Usage of STL debug checks in Debug build" ON)
6877
option(DISALLOW_THREAD_EXECUTOR "Disallow usage of ThreadExecutor for -j" OFF)
69-
option(USE_BOOST "Usage of Boost" OFF)
70-
option(USE_BOOST_INT128 "Usage of Boost.Multiprecision 128-bit integer for Mathlib" OFF)
71-
option(USE_LIBCXX "Use libc++ instead of libstdc++" OFF)
72-
7378
if(DISALLOW_THREAD_EXECUTOR AND WIN32)
7479
message(FATAL_ERROR "Cannot disable usage of ThreadExecutor on Windows as no other executor implementation is currently available")
7580
endif()
81+
option(USE_BOOST "Usage of Boost" OFF)
82+
option(USE_BOOST_INT128 "Usage of Boost.Multiprecision 128-bit integer for Mathlib" OFF)
83+
if (NOT USE_BOOST AND USE_BOOST_INT128)
84+
message(FATAL_ERROR "USE_BOOST_INT128 requires USE_BOOST to be enabled")
85+
endif()
86+
option(USE_LIBCXX "Use libc++ instead of libstdc++" OFF)
7687

7788
option(DISABLE_CRTDBG_MAP_ALLOC "Disable usage of Visual Studio C++ memory leak detection in Debug build" OFF)
7889
option(NO_UNIX_SIGNAL_HANDLING "Disable usage of Unix Signal Handling" OFF)
@@ -82,7 +93,7 @@ option(NO_WINDOWS_SEH "Disable usage of Windows SEH"
8293
# TODO: disable by default like make build?
8394
option(FILESDIR "Hard-coded directory for files to load from" OFF)
8495

85-
if(CMAKE_VERSION VERSION_EQUAL "3.16" OR CMAKE_VERSION VERSION_GREATER "3.16")
96+
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.16")
8697
set(CMAKE_DISABLE_PRECOMPILE_HEADERS Off CACHE BOOL "Disable precompiled headers")
8798
# need to disable the prologue or it will be treated like a system header and not emit any warnings
8899
# see https://gitlab.kitware.com/cmake/cmake/-/issues/21219

cmake/printInfo.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ message(STATUS "ANALYZE_MEMORY = ${ANALYZE_MEMORY}")
3030
message(STATUS "ANALYZE_ADDRESS = ${ANALYZE_ADDRESS}")
3131
message(STATUS "ANALYZE_THREAD = ${ANALYZE_THREAD}")
3232
message(STATUS "ANALYZE_UNDEFINED = ${ANALYZE_UNDEFINED}")
33-
message(STATUS "ANALYZE_DATAFLOW = ${ANALYZE_DATAFLOW}")
3433
message(STATUS)
3534
message(STATUS "WARNINGS_ARE_ERRORS = ${WARNINGS_ARE_ERRORS}")
3635
message(STATUS "EXTERNALS_AS_SYSTEM = ${EXTERNALS_AS_SYSTEM}")

0 commit comments

Comments
 (0)