Skip to content

Commit

Permalink
RelWithDebInfo configuration has been added (zproksi#34)
Browse files Browse the repository at this point in the history
Co-authored-by: zproski@mail.ru <zproski@mail.ru>
  • Loading branch information
zproksi and zproski@mail.ru authored Sep 15, 2024
1 parent 86e4d2c commit 1726a1f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# folders of rebuild
buildLinuxDebug/
buildLinuxRelease/
buildLinuxRelWithDebInfo/
buildWinDebug/
buildWinRelease/
buildWinRelWithDebInfo/
build/
.vscode/
x64/
Expand Down
36 changes: 27 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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 "$<$<CONFIG:Release>:-O3>"
COMPILE_OPTIONS "$<$<CONFIG:RelWithDebInfo>:-O3>"
COMPILE_OPTIONS "$<$<CONFIG:Debug>:-O0>"
)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# For MSVC, set the generator platform to x64
set_target_properties(${pname} PROPERTIES
COMPILE_OPTIONS "$<$<CONFIG:Release>:/Ox>"
COMPILE_OPTIONS "$<$<CONFIG:RelWithDebInfo>:/O2>"
COMPILE_OPTIONS "$<$<CONFIG:Debug>:/Od>"
)

Expand Down
2 changes: 1 addition & 1 deletion rebuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 1726a1f

Please sign in to comment.