diff --git a/cmake/compilerDefinitions.cmake b/cmake/compilerDefinitions.cmake index 5adad6b58..67454f0a4 100644 --- a/cmake/compilerDefinitions.cmake +++ b/cmake/compilerDefinitions.cmake @@ -1,8 +1,6 @@ if (MSVC) # Visual Studio only sets _DEBUG - if (CMAKE_BUILD_TYPE STREQUAL "Debug") - add_definitions(-DDEBUG) - endif() + add_compile_definitions($<$:-DDEBUG>) add_definitions(-DWIN32) add_definitions(-D_CRT_SECURE_NO_WARNINGS) diff --git a/cmake/compileroptions.cmake b/cmake/compileroptions.cmake index 8ebf5da18..74256f5ab 100644 --- a/cmake/compileroptions.cmake +++ b/cmake/compileroptions.cmake @@ -131,26 +131,20 @@ if (MSVC) # No Whole Program Optimization # C/C++ - Optimization - if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") - add_compile_options(/O2) # Optimization - Maximum Optimization (Favor Speed) - add_compile_options(/Ob2) # Inline Function Expansion - Any Suitable - add_compile_options(/Oi) # Enable Intrinsic Functions - add_compile_options(/Ot) # Favor fast code - add_compile_options(/Oy) # Omit Frame Pointers - else() - add_compile_options(/Od) # Optimization - Disabled - endif() + add_compile_options($<$>:/O2>) # Optimization - Maximum Optimization (Favor Speed) + add_compile_options($<$>:/Ob2>) # Inline Function Expansion - Any Suitable + add_compile_options($<$>:/Oi>) # Enable Intrinsic Functions + add_compile_options($<$>:/Ot>) # Favor fast code + add_compile_options($<$>:/Oy>) # Omit Frame Pointers + add_compile_options($<$:/Od>) # Optimization - Disabled # C/C++ - Code Generation - if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") - add_compile_options(/GF) # Enable String Pooling - add_compile_options(/MD) # Runtime Library - Multi-threaded DLL - add_compile_options(/GS-) # Disable Security Check - add_compile_options(/Gy) # Enable Function-Level Linking - else() - add_compile_options(/MDd) # Runtime Library - Multi-threaded Debug DLL - add_compile_options(/GS) # Enable Security Check - endif() + add_compile_options($<$>:/GF>) # Enable String Pooling + add_compile_options($<$>:/MD>) # Runtime Library - Multi-threaded DLL + add_compile_options($<$>:/GS->) # Disable Security Check + add_compile_options($<$>:/Gy>) # Enable Function-Level Linking + add_compile_options($<$:/MDd>) # Runtime Library - Multi-threaded Debug DLL + add_compile_options($<$:/GS>) # Enable Security Check # C/C++ - Language add_compile_options(/Zc:rvalueCast) # Enforce type conversion rules @@ -179,9 +173,8 @@ if (MSVC) add_compile_options(/Zc:throwingNew /Zc:__cplusplus) # Additional Options # Linker - General - if(CMAKE_BUILD_TYPE STREQUAL "Debug") - add_link_options(/INCREMENTAL) # Enable Incremental Linking - Yes - endif() + add_link_options($<$:/INCREMENTAL>) # Enable Incremental Linking - Yes + add_link_options(/NOLOGO) # SUppress Startup Banner - Yes # Ignore Import Library - Yes @@ -198,9 +191,7 @@ if (MSVC) add_link_options(/OPT:ICF) # Enable COMDAT Folding - Yes # Linker - Advanced - if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") - add_link_options(/RELEASE) # Set Checksum - Yes - endif() + add_link_options($<$>:/RELEASE>) # Set Checksum - Yes endif() # TODO: check if this can be enabled again - also done in Makefile diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt index 1759ace96..c646f15fd 100644 --- a/gui/CMakeLists.txt +++ b/gui/CMakeLists.txt @@ -9,13 +9,10 @@ CheckOptions: - { key: HeaderFileExtensions, value: 'x' } ") - if (CMAKE_BUILD_TYPE STREQUAL "Release") - add_definitions(-DQT_NO_DEBUG) - add_definitions(-DQT_NO_DEBUG_OUTPUT) - add_definitions(-DQT_NO_WARNING_OUTPUT) - else() - add_definitions(-DQT_DEBUG) - endif() + add_compile_definitions($<$>:-DQT_NO_DEBUG>) + add_compile_definitions($<$>:-DQT_NO_DEBUG_OUTPUT>) + add_compile_definitions($<$>:-DQT_NO_WARNING_OUTPUT>) + add_compile_definitions($<$:-DQT_DEBUG>) file(GLOB hdrs "*.h") file(GLOB srcs "*.cpp") @@ -61,6 +58,10 @@ CheckOptions: target_compile_definitions(cppcheck-gui PRIVATE CPPCHECKLIB_IMPORT TINYXML2_IMPORT) target_link_libraries(cppcheck-gui cppcheck-core) endif() + if(MSVC) + # compilation will fail as e.g. QList::realloc would be replaced by MSVC's macro definition + target_compile_definitions(cppcheck-gui PRIVATE $<$:DISABLE_CRTDBG_MAP_ALLOC>) + endif() if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") # Q_UNUSED() in generated code target_compile_options_safe(cppcheck-gui -Wno-extra-semi-stmt) diff --git a/readme.md b/readme.md index 9c411a756..ccb6ae17d 100644 --- a/readme.md +++ b/readme.md @@ -64,6 +64,26 @@ For release builds it is recommended that you use: Using cmake you can generate project files for Visual Studio,XCode,etc. +#### Building a specific configuration + +For single-configuration generators (like "Unix Makefiles") you can generate and build a specific configuration (e.g. "RelWithDebInfo") using: + +```shell +mkdir build_RelWithDebInfo +cd build_RelWithDebInfo +cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo .. +cmake --build . --config RelWithDebInfo +``` + +For multi-configuration generators (like "Visual Studio 17 2022") the same is achieved using: + +```shell +mkdir build +cd build +cmake .. +cmake --build . --config RelWithDebInfo +``` + ### qmake You can use the gui/gui.pro file to build the GUI. diff --git a/tools/triage/CMakeLists.txt b/tools/triage/CMakeLists.txt index c23b83ec7..73cf887ba 100644 --- a/tools/triage/CMakeLists.txt +++ b/tools/triage/CMakeLists.txt @@ -8,13 +8,10 @@ CheckOptions: - { key: HeaderFileExtensions, value: 'x' } ") - if (CMAKE_BUILD_TYPE STREQUAL "Release") - add_definitions(-DQT_NO_DEBUG) - add_definitions(-DQT_NO_DEBUG_OUTPUT) - add_definitions(-DQT_NO_WARNING_OUTPUT) - else() - add_definitions(-DQT_DEBUG) - endif() + add_compile_definitions($<$>:-DQT_NO_DEBUG>) + add_compile_definitions($<$>:-DQT_NO_DEBUG_OUTPUT>) + add_compile_definitions($<$>:-DQT_NO_WARNING_OUTPUT>) + add_compile_definitions($<$:-DQT_DEBUG>) file(GLOB hdrs "*.h") file(GLOB srcs "*.cpp")