@@ -20,19 +20,23 @@ else()
2020 message (STATUS "Build type: ${CMAKE_BUILD_TYPE} " )
2121endif ()
2222
23- # Warning flags (always enabled)
24- add_compile_options (
25- -Wall # Enable most warnings
26- -Wextra # Extra warnings
27- -Wpedantic # Strict ISO C compliance
28- -Wshadow # Warn about variable shadowing
29- -Wformat=2 # Extra format string checks
30- -Wcast-qual # Warn about cast that removes qualifiers
31- -Wcast-align # Warn about pointer cast alignment issues
32- -Wunused # Warn about unused variables/functions
33- -Wdouble-promotion # Warn about float->double promotion
34- -Wnull-dereference # Warn about null pointer dereference
35- )
23+ # Warning flags (compiler-specific)
24+ if (MSVC )
25+ add_compile_options (/W4 /WX )
26+ else ()
27+ add_compile_options (
28+ -Wall # Enable most warnings
29+ -Wextra # Extra warnings
30+ -Wpedantic # Strict ISO C compliance
31+ -Wshadow # Warn about variable shadowing
32+ -Wformat=2 # Extra format string checks
33+ -Wcast-qual # Warn about cast that removes qualifiers
34+ -Wcast-align # Warn about pointer cast alignment issues
35+ -Wunused # Warn about unused variables/functions
36+ -Wdouble-promotion # Warn about float to double promotion
37+ -Wnull-dereference # Warn about null pointer dereference
38+ )
39+ endif ()
3640
3741# Include directories
3842include_directories (${PROJECT_SOURCE_DIR} /include )
@@ -43,15 +47,28 @@ file(GLOB_RECURSE SOURCES "src/*.c")
4347
4448# Create core library
4549add_library (dnlp_diff ${SOURCES} )
46- target_link_libraries (dnlp_diff m )
4750
48- # Config-specific compile options
49- target_compile_options (dnlp_diff PRIVATE
50- $<$<CONFIG :Debug >:-g -O0 >
51- $<$<CONFIG :Release >:-O3 -DNDEBUG >
52- $<$<CONFIG :RelWithDebInfo >:-O2 -g -DNDEBUG >
53- $<$<CONFIG :MinSizeRel >:-Os -DNDEBUG >
54- )
51+ # Link math library (Unix/Linux only)
52+ if (NOT MSVC )
53+ target_link_libraries (dnlp_diff m )
54+ endif ()
55+
56+ # Config-specific compile options (compiler-specific)
57+ if (MSVC )
58+ target_compile_options (dnlp_diff PRIVATE
59+ $<$<CONFIG :Debug >:/Od /Zi >
60+ $<$<CONFIG :Release >:/O2 /DNDEBUG >
61+ $<$<CONFIG :RelWithDebInfo >:/O2 /Zi /DNDEBUG >
62+ $<$<CONFIG :MinSizeRel >:/Os /DNDEBUG >
63+ )
64+ else ()
65+ target_compile_options (dnlp_diff PRIVATE
66+ $<$<CONFIG :Debug >:-g -O0 >
67+ $<$<CONFIG :Release >:-O3 -DNDEBUG >
68+ $<$<CONFIG :RelWithDebInfo >:-O2 -g -DNDEBUG >
69+ $<$<CONFIG :MinSizeRel >:-Os -DNDEBUG >
70+ )
71+ endif ()
5572
5673# This is needed for clock_gettime on Linux without compiler extensions
5774if (CMAKE_SYSTEM_NAME STREQUAL "Linux" )
0 commit comments