Skip to content

Commit 391f44a

Browse files
committed
CMake: add debug options to windows builds
gcc and clang always build with '-g', enabling easier debugging, so catch MSVC to the same. This will create seperate program database (.pdb) files, which map identifiers and statements in the project's source code to corresponding identifiers and instructions in compiled apps. These mapping files link the debugger to your source code, which enables debugging. Hopefully this will put a stop to those who want to build in windows in debug mode (which is not possible, see #772) This does not include the pdb files in the installers, so the only way to get them is build locally. Signed-off-by: Robin Getz <[email protected]>
1 parent 29ca7fd commit 391f44a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ if (NOT LOG_LEVEL)
6767
endif()
6868

6969
if (MSVC)
70-
add_compile_options(/W4 /wd4200 /wd4127 /wd4100)
70+
add_compile_options(/Zi /W4 /wd4200 /wd4127 /wd4100)
71+
# Zi produces a separate PDB file that contains all the symbolic debugging information
72+
# W4 displays level 1, 2, 3, and 4 (informational) warnings that aren't off by default
7173
# C4200: nonstandard extension used : zero-sized array in struct (usb.h)
7274
# C4127: conditional expression is constant (IIO_ERROR and IIO_DEBUG macros)
7375
# C4100: unreferenced parameter; same as -Wno-unused-parameter
@@ -474,6 +476,8 @@ target_link_libraries(iio LINK_PRIVATE ${LIBS_TO_LINK})
474476

475477
if (MSVC)
476478
set_target_properties(iio PROPERTIES OUTPUT_NAME libiio)
479+
target_link_options(iio PUBLIC /DEBUG)
480+
# The linker puts debugging information into a program database (PDB) file
477481
endif()
478482

479483
if(NOT SKIP_INSTALL_ALL)

tests/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ add_executable(iio_readdev iio_readdev.c ${GETOPT_C_FILE} ${LIBIIO_RC})
3737
add_executable(iio_reg iio_reg.c ${GETOPT_C_FILE} ${LIBIIO_RC})
3838
add_executable(iio_writedev iio_writedev.c ${GETOPT_C_FILE} ${LIBIIO_RC})
3939

40+
if (MSVC)
41+
target_link_options(iio_tests_helper PUBLIC /DEBUG)
42+
target_link_options(iio_genxml PUBLIC /DEBUG)
43+
target_link_options(iio_info PUBLIC /DEBUG)
44+
target_link_options(iio_attr PUBLIC /DEBUG)
45+
target_link_options(iio_readdev PUBLIC /DEBUG)
46+
target_link_options(iio_reg PUBLIC /DEBUG)
47+
target_link_options(iio_writedev PUBLIC /DEBUG)
48+
endif()
49+
4050
target_link_libraries(iio_genxml iio iio_tests_helper)
4151
target_link_libraries(iio_info iio iio_tests_helper)
4252
target_link_libraries(iio_attr iio iio_tests_helper)

0 commit comments

Comments
 (0)