File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -116,6 +116,11 @@ if(NOT MSVC)
116116 add_definitions (-D__STDC_FORMAT_MACROS )
117117
118118else () # MSVC
119+ # C sources (e.g. libscap) use C11 atomics (<stdatomic.h>). MSVC needs /std:c11 and
120+ # /experimental:c11atomics (see CMAKE_C_STANDARD and CMAKE_C_FLAGS below). Requires VS 2022
121+ # 17.5+.
122+ set (CMAKE_C_STANDARD 11)
123+
119124 set (FALCOSECURITY_LIBS_COMMON_FLAGS
120125 "-D_CRT_SECURE_NO_WARNINGS -DWIN32 /EHsc /W3 /Zi /std:c++17"
121126 )
@@ -129,6 +134,12 @@ else() # MSVC
129134
130135 set (CMAKE_C_FLAGS "${FALCOSECURITY_LIBS_COMMON_FLAGS} " )
131136 set (CMAKE_CXX_FLAGS "${FALCOSECURITY_LIBS_COMMON_FLAGS} " )
137+ # Enable C11 atomics for .c files (libscap uses <stdatomic.h>). Requires VS 2022 17.5+. Use
138+ # add_compile_options so the flag propagates to all C targets in subdirectories (e.g.
139+ # scap_engine_savefile); CMAKE_C_FLAGS alone is not reliably applied by the Visual Studio
140+ # generator to targets created in add_subdirectory().
141+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /experimental:c11atomics" )
142+ add_compile_options ($<$<COMPILE_LANGUAGE :C >:/experimental :c11atomics >)
132143
133144 set (CMAKE_C_FLAGS_DEBUG "${FALCOSECURITY_LIBS_DEBUG_FLAGS} " )
134145 set (CMAKE_CXX_FLAGS_DEBUG "${FALCOSECURITY_LIBS_DEBUG_FLAGS} " )
Original file line number Diff line number Diff line change @@ -71,6 +71,10 @@ target_include_directories(scap_buffer PUBLIC $<BUILD_INTERFACE:${LIBS_DIR}/user
7171
7272add_library (scap scap.c scap_api_version.c scap_savefile.c scap_platform_api.c )
7373
74+ if (MSVC )
75+ target_compile_options (scap PRIVATE $<$<COMPILE_LANGUAGE :C >:/experimental :c11atomics >)
76+ endif ()
77+
7478target_include_directories (
7579 scap
7680 PUBLIC $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} >
Original file line number Diff line number Diff line change @@ -22,3 +22,9 @@ target_link_libraries(
2222 scap_engine_savefile PRIVATE scap_engine_noop scap_platform_util scap_savefile_converter
2323 ${ZLIB_LIB} scap_error
2424)
25+
26+ if (MSVC )
27+ target_compile_options (
28+ scap_engine_savefile PRIVATE $<$<COMPILE_LANGUAGE :C >:/experimental :c11atomics >
29+ )
30+ endif ()
Original file line number Diff line number Diff line change @@ -16,5 +16,9 @@ add_library(scap_engine_source_plugin source_plugin.c)
1616target_link_libraries (
1717 scap_engine_source_plugin PRIVATE scap_event_schema scap_engine_noop scap_error
1818)
19-
19+ if (MSVC )
20+ target_compile_options (
21+ scap_engine_source_plugin PRIVATE $<$<COMPILE_LANGUAGE :C >:/experimental :c11atomics >
22+ )
23+ endif ()
2024set_scap_target_properties (scap_engine_source_plugin )
You can’t perform that action at this time.
0 commit comments