From 1726a1f6c26c441c5fde7c1bc65900f02361eddd Mon Sep 17 00:00:00 2001 From: Alexey Zaytsev Date: Sun, 15 Sep 2024 16:05:54 +0200 Subject: [PATCH] RelWithDebInfo configuration has been added (#34) Co-authored-by: zproski@mail.ru --- .github/workflows/cmake-multi-platform.yml | 4 ++- .gitignore | 2 ++ CMakeLists.txt | 36 ++++++++++++++++------ rebuild.sh | 2 +- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index cc9904d..6653762 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -29,7 +29,7 @@ jobs: # To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list. matrix: os: [ubuntu-latest, windows-latest, macos-14] - build_type: [Release, Debug] + build_type: [Release, Debug, RelWithDebInfo] c_compiler: [gcc, cl, clang, clang-17] include: - os: windows-latest @@ -47,6 +47,8 @@ jobs: exclude: - os: windows-latest c_compiler: gcc + - os: windows-latest + build_type: RelWithDebInfo - os: windows-latest c_compiler: clang - os: windows-latest diff --git a/.gitignore b/.gitignore index 2772f88..5f8c301 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,10 @@ # folders of rebuild buildLinuxDebug/ buildLinuxRelease/ +buildLinuxRelWithDebInfo/ buildWinDebug/ buildWinRelease/ +buildWinRelWithDebInfo/ build/ .vscode/ x64/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d004b2..00540d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,9 @@ project(${pname}) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED True) +# Set configurations +set(CMAKE_CONFIGURATION_TYPES "Debug;Release;RelWithDebInfo;MinSizeRel" CACHE STRING "Configs" FORCE) + # Set the build type to Debug if not explicitly specified if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Debug) @@ -22,31 +25,47 @@ message(STATUS "Initial COMPILER_FLAGS:" ${CMAKE_CXX_FLAGS}) set(CMAKE_CXX_FLAGS "") message(STATUS "CMAKE_CXX_FLAGS:" ${CMAKE_CXX_FLAGS}) message(STATUS "CMAKE_CXX_COMPILER_ID:" ${CMAKE_CXX_COMPILER_ID}) +set(CMAKE_EXE_LINKER_FLAGS "") if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") # GCC (GNU Compiler) if (CMAKE_BUILD_TYPE STREQUAL "Debug") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEBUG -D_DEBUG -D_CONSOLE -Wno-unknown-pragmas -Wall -Werror -fno-rtti -pthread") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEBUG -D_DEBUG -g -D_CONSOLE -Wno-unknown-pragmas -Wall -Werror -fno-rtti -pthread") + set(CMAKE_EXE_LINKER_FLAGS "-g") elseif(CMAKE_BUILD_TYPE STREQUAL "Release") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG -D_CONSOLE -Wno-unknown-pragmas -Wall -Werror -fno-rtti -pthread") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG -D_CONSOLE -Wno-unknown-pragmas -Wall -Werror -fno-rtti -pthread") + set(CMAKE_EXE_LINKER_FLAGS "-O3 -flto") + elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG -g -D_CONSOLE -Wno-unknown-pragmas -Wall -Werror -fno-rtti -pthread") + set(CMAKE_EXE_LINKER_FLAGS "-g -O2 -flto") else() message(FATAL_ERROR "Unsupported compilation mode") endif() elseif(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang.*") #Clang or AppleClang or anything with Clang # clang (MAC Compiler) if (CMAKE_BUILD_TYPE STREQUAL "Debug") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEBUG -D_DEBUG -D_CONSOLE -Wno-unknown-pragmas -Wall -Werror -Wno-unqualified-std-cast-call -fno-rtti -pthread -stdlib=libc++") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEBUG -D_DEBUG -g -D_CONSOLE -Wno-unknown-pragmas -Wall -Werror -Wno-unqualified-std-cast-call -fno-rtti -pthread -stdlib=libc++") + set(CMAKE_EXE_LINKER_FLAGS "-g") elseif(CMAKE_BUILD_TYPE STREQUAL "Release") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG -D_CONSOLE -Wno-unknown-pragmas -Wall -Werror -Wno-unqualified-std-cast-call -fno-rtti -pthread -stdlib=libc++") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG -D_CONSOLE -Wno-unknown-pragmas -Wall -Werror -Wno-unqualified-std-cast-call -fno-rtti -pthread -stdlib=libc++") + set(CMAKE_EXE_LINKER_FLAGS "-O3 -flto") + elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG -g -D_CONSOLE -Wno-unknown-pragmas -Wall -Werror -Wno-unqualified-std-cast-call -fno-rtti -pthread -stdlib=libc++") + set(CMAKE_EXE_LINKER_FLAGS "-g -O2 -flto") else() message(FATAL_ERROR "Unsupported compilation mode") endif() elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") # MSVC (Microsoft Visual C++) if (CMAKE_BUILD_TYPE STREQUAL "Debug") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DWIN32 /D_WINDOWS /D_CONSOLE /DDEBUG /D_DEBUG /EHsc /W4 /WX /GR- /MDd") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DWIN32 /D_WINDOWS /D_CONSOLE /DDEBUG /D_DEBUG /Zi /EHsc /W4 /WX /GR- /MDd") + set(CMAKE_EXE_LINKER_FLAGS "/DEBUG:FULL /INCREMENTAL") elseif(CMAKE_BUILD_TYPE STREQUAL "Release") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DWIN32 /D_WINDOWS /D_CONSOLE /DNDEBUG /EHsc /W4 /WX /GR- /MD") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DWIN32 /D_WINDOWS /D_CONSOLE /DNDEBUG /Ob1 /EHsc /W4 /WX /GR- /MD") + set(CMAKE_EXE_LINKER_FLAGS " /OPT:REF /OPT:ICF /INCREMENTAL:NO /LTCG") + elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DWIN32 /D_WINDOWS /D_CONSOLE /DNDEBUG /Ob1 /Zi /EHsc /W4 /WX /GR- /MD") + set(CMAKE_EXE_LINKER_FLAGS "/DEBUG:FULL /OPT:REF /OPT:ICF /INCREMENTAL:NO") else() message(FATAL_ERROR "Unsupported compilation mode") endif() @@ -56,9 +75,6 @@ endif() message(STATUS "CMAKE_CXX_FLAGS:" ${CMAKE_CXX_FLAGS}) -# Set Release and Debug configurations -set(CMAKE_CONFIGURATION_TYPES "Release;Debug" CACHE STRING "Configurations" FORCE) - ##get google test include(FetchContent) FetchContent_Declare(googletest @@ -98,12 +114,14 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") # For GCC and Clang, use the -m64 flag to target 64-bit set_target_properties(${pname} PROPERTIES COMPILE_OPTIONS "$<$:-O3>" + COMPILE_OPTIONS "$<$:-O3>" COMPILE_OPTIONS "$<$:-O0>" ) elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") # For MSVC, set the generator platform to x64 set_target_properties(${pname} PROPERTIES COMPILE_OPTIONS "$<$:/Ox>" + COMPILE_OPTIONS "$<$:/O2>" COMPILE_OPTIONS "$<$:/Od>" ) diff --git a/rebuild.sh b/rebuild.sh index 7ce9af8..0fb991f 100644 --- a/rebuild.sh +++ b/rebuild.sh @@ -11,7 +11,7 @@ if [ "$1" != "" ]; then fi # Check if MODE is not Debug, if true set it to Release -if [ "$MODE" != "Debug" ]; then +if [ "$MODE" != "Debug" ] && [ "$MODE" != "RelWithDebInfo" ]; then MODE=Release fi