Skip to content

Commit c12e617

Browse files
committed
CMake: Support RelWithDebInfo configuration
Support optimized compiles with debugging info (e.g., "-O2 -g" for GCC/Clang.) Useful with 'valgrind' to produce intelligible output.
1 parent c20b391 commit c12e617

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

README-CMake.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,11 @@ simh # Top-level SIMH source directory
398398
+-- BIN # Simulator executables (note 1)
399399
| +-- Debug
400400
| +-- Release
401+
| +-- RelWithDebInfo
401402
| +-- Win32
402403
| +-- Debug
403404
| +-- Release
405+
| +-- RelWithDebInfo
404406
+-- cmake # CMake modules and build subdirectories
405407
| +-- build-vs2022 # Build directory for VS-2022 (note 2)
406408
| +-- build-vs2019 # Build directory for VS-2019 (note 2)
@@ -434,7 +436,7 @@ Notes:
434436
will appear directly underneath the `BIN` directory.
435437
- Multi-configuration builders (`msbuild`, `xcodebuild`): The simulator
436438
executables will appear underneath individual configuration subdirectories
437-
("Debug" and "Release").
439+
("Debug", "Release" and "RelWithDebInfo").
438440
- The Windows platform has its `Win32` subdirectory.
439441
2. The `cmake-builder.ps1` and `cmake-builder.sh` scripts create the
440442
`cmake/build-*` subdirectories as needed.

cmake/cmake-builder.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ param (
8787
[Parameter(Mandatory=$false)]
8888
[string] $flavor = "vs2022",
8989

90-
## The target build configuration. Valid values: "Release" and "Debug"
90+
## The target build configuration. Valid values: "Release", "Debug" and
91+
## "RelWithDebInfo"
9192
[Parameter(Mandatory=$false)]
9293
[string] $config = "Release",
9394

@@ -297,7 +298,7 @@ if (!$testonly)
297298
}
298299

299300
## Validate the requested configuration.
300-
if (!@("Release", "Debug").Contains($config))
301+
if (!@("Release", "Debug", "RelWithDebInfo").Contains($config))
301302
{
302303
@"
303304
${scriptName}: Invalid configuration: "${config}".

cmake/cmake-builder.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Configure and build simh simulators on Linux and *nix-like platforms.
1212
--clean (-x) Remove the build subdirectory
1313
--generate (-g) Generate the build environment, don't compile/build
1414
--cache '--generate' and show CMake's variable cache
15-
--parallel (-p) Enable build parallelism (parallel builds)
15+
--parallel (-p) Enable parallel builds
1616
--notest Do not execute 'ctest' test cases
1717
--noinstall Do not install SIMH simulators.
1818
--testonly Do not build, execute the 'ctest' test cases
@@ -27,7 +27,8 @@ Configure and build simh simulators on Linux and *nix-like platforms.
2727
msys2
2828
mingw
2929
ucrt
30-
--config (-c) Specifies the build configuration: 'Release' or 'Debug'
30+
--config (-c) Specifies the build configuration: 'Release', 'Debug' or
31+
'RelWithDebInfo'
3132
3233
--target Build a specific simulator or simulators. Separate multiple
3334
targets with a comma, e.g. "--target pdp8,pdp11,vax750,altairz80,3b2"
@@ -211,7 +212,7 @@ while true; do
211212
;;
212213
-c | --config)
213214
case "$2" in
214-
Release|Debug)
215+
Release|Debug|RelWithDebInfo)
215216
buildConfig=$2
216217
shift 2
217218
;;

cmake/platform-quirks.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ if (WIN32)
8080
if (RELEASE_LTO)
8181
## /LTCG: Link-Time Code Generation. Pair with /GL at compile time.
8282
add_compile_options("$<$<CONFIG:Release>:/GL>")
83+
add_compile_options("$<$<CONFIG:RelWithDebInfo>:/GL>")
8384
add_link_options("$<$<CONFIG:Release>:/LTCG>")
8485
message(STATUS "Adding LTO to Release compiler and linker flags")
8586
endif ()
@@ -106,6 +107,9 @@ if (WIN32)
106107
list(APPEND EXTRA_TARGET_CFLAGS
107108
"$<$<CONFIG:Debug>:$<$<BOOL:${DEBUG_WALL}>:/W4>>"
108109
"$<$<CONFIG:Release>:/W3>"
110+
"$<$<CONFIG:RelWithDebInfo>:$<$<BOOL:${DEBUG_WALL}>:/W4>>"
111+
# 4100: Unused arg warning.
112+
"/wd4100"
109113
)
110114

111115
## Uncomment this line if you end up with /NODEFAULTLIB warninigs. You will also
@@ -137,6 +141,7 @@ if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")
137141
LIST(APPEND EXTRA_TARGET_CFLAGS
138142
"-U__STRICT_ANSI__"
139143
"$<$<CONFIG:Debug>:$<$<BOOL:${DEBUG_WALL}>:-Wall>>"
144+
"$<$<CONFIG:RelWithDebInfo>:$<$<BOOL:${DEBUG_WALL}>:-Wall>>"
140145
## Only add if WARNINGS_FATAL set; has undesirable consequences with LTO.
141146
"$<$<CONFIG:Release>:-Wall>"
142147
)
@@ -199,6 +204,8 @@ if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")
199204
message(STATUS " ${opt_flag}")
200205
string(REGEX REPLACE "${opt_flag}[ \t\r\n]*" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
201206
string(APPEND CMAKE_C_FLAGS_RELEASE " ${opt_flag}")
207+
string(REGEX REPLACE "${opt_flag}[ \t\r\n]*" "" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
208+
string(APPEND CMAKE_C_FLAGS_RELWITHDEBINFO " ${opt_flag}")
202209
string(REGEX REPLACE "${opt_flag}[ \t\r\n]*" "" CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL}")
203210
string(APPEND CMAKE_C_FLAGS_MINSIZEREL " ${opt_flag}")
204211
endforeach ()

0 commit comments

Comments
 (0)