Skip to content

Commit 3b0346c

Browse files
committed
CMake: support RelWithDebInfo builds
Adapt open-simh PR 475 by B. Scott Michel by allowing RelWithDebInfo in the CMake helper scripts and documenting it as an optimized build with debugger information. Apply the existing optimized GNU/Clang flag handling to RelWithDebInfo, but do not import unrelated warning suppressions or change MSVC LTO behavior.
1 parent 37f6fb0 commit 3b0346c

5 files changed

Lines changed: 27 additions & 15 deletions

File tree

BUILDING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ cmake --build build/release --target integration-tests
287287

288288
Some useful CMake options:
289289

290+
- `-DCMAKE_BUILD_TYPE=RelWithDebInfo`
291+
Build optimized binaries while retaining debugger information. This is
292+
useful for profiling, debugger sessions, and tools such as Valgrind.
290293
- `-DWITH_VIDEO=Off`
291294
Disable SDL-based graphics support. Default: `On`.
292295
- `-DWITH_NETWORK=Off`

README-CMake.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ The most commonly used options are:
9999

100100
- `CMAKE_BUILD_TYPE`
101101
Default: generator-dependent.
102-
Use `Release` or `Debug` for single-config generators such as Ninja.
102+
Use `Release`, `Debug`, or `RelWithDebInfo` for single-config
103+
generators such as Ninja. `RelWithDebInfo` is optimized like a release
104+
build while retaining debugger information.
103105
- `WITH_VIDEO`
104106
Default: `On`.
105107
Enable SDL-based graphics and display support.

cmake/cmake-builder.ps1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ simulators using the CMake meta-build tool. The phases are:
1414
2. Build missing runtime dependencies and the simulator suite with the compiler
1515
configuration selected by the '-config' option. The "Release" configuration
1616
generates optimized executables; the "Debug" configuration generates
17-
development executables with debugger information.
17+
development executables with debugger information; and "RelWithDebInfo"
18+
generates optimized executables with debugger information.
1819
3. Test the simulators
1920
2021
There is an install phase that can be invoked separately as part of the SIMH
@@ -86,7 +87,8 @@ param (
8687
[Parameter(Mandatory=$false)]
8788
[string] $flavor = "vs2022",
8889

89-
## The target build configuration. Valid values: "Release" and "Debug"
90+
## The target build configuration. Valid values are "Release", "Debug",
91+
## and "RelWithDebInfo"
9092
[Parameter(Mandatory=$false)]
9193
[string] $config = "Release",
9294

@@ -294,7 +296,7 @@ if (!$testonly)
294296
}
295297

296298
## Validate the requested configuration.
297-
if (!@("Release", "Debug").Contains($config))
299+
if (!@("Release", "Debug", "RelWithDebInfo").Contains($config))
298300
{
299301
@"
300302
${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-400"
@@ -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: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")
136136
## LIST(APPEND EXTRA_TARGET_CFLAGS "-Wall" "-fno-inline" "-fstrict-overflow" "-Wstrict-overflow=3")
137137
LIST(APPEND EXTRA_TARGET_CFLAGS
138138
"$<$<CONFIG:Debug>:$<$<OR:$<BOOL:${DEBUG_WALL}>,$<BOOL:${DEBUG_WARNINGS}>>:-Wall>>"
139-
"$<$<CONFIG:Release>:-Wall>"
139+
"$<$<CONFIG:Release,RelWithDebInfo>:-Wall>"
140140
"$<$<CONFIG:Debug>:$<$<BOOL:${DEBUG_WARNINGS}>:-Wextra>>"
141141
# Keep this warning disabled for now; legacy aggregate
142142
# initializers produce too much noise during warning sweeps.
@@ -198,22 +198,26 @@ if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang")
198198
endif ()
199199
endif ()
200200
201-
message(STATUS "Adding GNU-specific optimizations to CMAKE_C_FLAGS_RELEASE")
201+
message(STATUS "Adding GNU-specific optimizations to optimized build flags")
202202
list(APPEND opt_flags "-finline-functions" "-fgcse-after-reload" "-fpredictive-commoning"
203203
"-fipa-cp-clone" "-fno-unsafe-loop-optimizations")
204204
elseif (CMAKE_C_COMPILER_ID MATCHES ".*Clang")
205-
message(STATUS "Adding Clang-specific optimizations to CMAKE_C_FLAGS_RELEASE")
205+
message(STATUS "Adding Clang-specific optimizations to optimized build flags")
206206
endif()
207207
208208
foreach (opt_flag ${opt_flags})
209209
message(STATUS " ${opt_flag}")
210-
string(REGEX REPLACE "${opt_flag}[ \t\r\n]*" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
211-
string(APPEND CMAKE_C_FLAGS_RELEASE " ${opt_flag}")
212-
string(REGEX REPLACE "${opt_flag}[ \t\r\n]*" "" CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL}")
213-
string(APPEND CMAKE_C_FLAGS_MINSIZEREL " ${opt_flag}")
210+
foreach (optimized_c_flags_var
211+
CMAKE_C_FLAGS_RELEASE
212+
CMAKE_C_FLAGS_RELWITHDEBINFO
213+
CMAKE_C_FLAGS_MINSIZEREL)
214+
string(REGEX REPLACE "${opt_flag}[ \t\r\n]*" ""
215+
${optimized_c_flags_var} "${${optimized_c_flags_var}}")
216+
string(APPEND ${optimized_c_flags_var} " ${opt_flag}")
217+
endforeach ()
214218
endforeach ()
215219
else ()
216-
message(STATUS "Not changing CMAKE_C_FLAGS_RELEASE on ${CMAKE_C_COMPILER_ID}")
220+
message(STATUS "Not changing optimized build flags on ${CMAKE_C_COMPILER_ID}")
217221
endif ()
218222
219223

0 commit comments

Comments
 (0)