Skip to content

Commit

Permalink
update(cmake): Set our preferred Visual C++ runtime the same way ever…
Browse files Browse the repository at this point in the history
…ywhere

If we're using CMake 3.15 or later, select our Visual C++ runtime using
CMAKE_MSVC_RUNTIME_LIBRARY. Otherwise use FALCOSECURITY_LIBS_DEBUG_FLAGS
and FALCOSECURITY_LIBS_RELEASE_FLAGS.

Signed-off-by: Gerald Combs <[email protected]>
  • Loading branch information
geraldcombs authored and poiana committed Feb 6, 2024
1 parent b753fe8 commit a89fd5d
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ jobs:
- name: Build and test 🏗️🧪
run: |
mkdir -p build
cd build && cmake -DUSE_BUNDLED_DEPS=ON -DCMAKE_BUILD_TYPE=Release -DCREATE_TEST_TARGETS=ON -DMINIMAL_BUILD=ON ..
cd build && cmake -DUSE_BUNDLED_DEPS=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DCREATE_TEST_TARGETS=ON -DMINIMAL_BUILD=ON ..
cmake --build . --config Release && make run-unit-tests || libsinsp\test\Release\unit-test-libsinsp.exe
build-shared-libs-macos-amd64:
Expand Down
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ if(POLICY CMP0042)
cmake_policy(SET CMP0042 NEW)
endif()

# Enable CMAKE_MSVC_RUNTIME_LIBRARY on Windows + CMake >= 3.15
if(POLICY CMP0091)
cmake_policy(SET CMP0091 NEW)
endif()

if(POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif()
Expand Down
9 changes: 7 additions & 2 deletions cmake/modules/CompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,13 @@ else() # MSVC
set(MINIMAL_BUILD ON)

set(FALCOSECURITY_LIBS_COMMON_FLAGS "-D_CRT_SECURE_NO_WARNINGS -DWIN32 -DMINIMAL_BUILD /EHsc /W3 /Zi /std:c++17")
set(FALCOSECURITY_LIBS_DEBUG_FLAGS "/MTd /Od")
set(FALCOSECURITY_LIBS_RELEASE_FLAGS "/MT")
if(CMAKE_VERSION VERSION_LESS 3.15.0)
set(FALCOSECURITY_LIBS_DEBUG_FLAGS "/MTd /Od")
set(FALCOSECURITY_LIBS_RELEASE_FLAGS "/MT")
else()
# /MT vs /MD should be determined via CMAKE_MSVC_RUNTIME_LIBRARY
set(FALCOSECURITY_LIBS_DEBUG_FLAGS "/Od")
endif()

set(CMAKE_C_FLAGS "${FALCOSECURITY_LIBS_COMMON_FLAGS}")
set(CMAKE_CXX_FLAGS "${FALCOSECURITY_LIBS_COMMON_FLAGS}")
Expand Down
6 changes: 3 additions & 3 deletions cmake/modules/jsoncpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ else()
URL_HASH
"SHA256=f409856e5920c18d0c2fb85276e24ee607d2a09b5e7d5f0a371368903c275da2"
CMAKE_ARGS
-DCMAKE_CXX_FLAGS_DEBUG="/MTd /Od"
-DCMAKE_CXX_FLAGS_RELEASE="/MT"
-DCMAKE_CXX_FLAGS_DEBUG=${FALCOSECURITY_LIBS_DEBUG_FLAGS}
-DCMAKE_CXX_FLAGS_RELEASE=${FALCOSECURITY_LIBS_RELEASE_FLAGS}
-DBUILD_OBJECT_LIBS=Off
${JSONCPP_STATIC_OPTION}
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
Expand All @@ -88,7 +88,7 @@ else()
"SHA256=f409856e5920c18d0c2fb85276e24ee607d2a09b5e7d5f0a371368903c275da2"
CMAKE_ARGS
-DCMAKE_POLICY_DEFAULT_CMP0091:STRING=NEW
-DCMAKE_MSVC_RUNTIME_LIBRARY:STRING=MultiThreaded$<$<CONFIG:Debug>:Debug>
-DCMAKE_MSVC_RUNTIME_LIBRARY=${CMAKE_MSVC_RUNTIME_LIBRARY}
-DBUILD_OBJECT_LIBS=Off
${JSONCPP_STATIC_OPTION}
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
Expand Down
6 changes: 3 additions & 3 deletions cmake/modules/re2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ else()
BINARY_DIR "${PROJECT_BINARY_DIR}/re2-prefix/build"
BUILD_BYPRODUCTS ${RE2_LIB}
CMAKE_ARGS
-DCMAKE_CXX_FLAGS_DEBUG="/MTd /Od"
-DCMAKE_CXX_FLAGS_RELEASE="/MT"
-DCMAKE_CXX_FLAGS_DEBUG=${FALCOSECURITY_LIBS_DEBUG_FLAGS}
-DCMAKE_CXX_FLAGS_RELEASE=${FALCOSECURITY_LIBS_RELEASE_FLAGS}
-DCMAKE_INSTALL_LIBDIR=lib
-DRE2_BUILD_TESTING=OFF
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
Expand All @@ -79,7 +79,7 @@ else()
BUILD_BYPRODUCTS ${RE2_LIB}
CMAKE_ARGS
-DCMAKE_POLICY_DEFAULT_CMP0091:STRING=NEW
-DCMAKE_MSVC_RUNTIME_LIBRARY:STRING=MultiThreaded$<$<CONFIG:Debug>:Debug>
-DCMAKE_MSVC_RUNTIME_LIBRARY=${CMAKE_MSVC_RUNTIME_LIBRARY}
-DCMAKE_INSTALL_LIBDIR=lib
-DRE2_BUILD_TESTING=OFF
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
Expand Down
6 changes: 3 additions & 3 deletions cmake/modules/tbb.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ else()
BUILD_IN_SOURCE 1
BUILD_COMMAND ${CMAKE_COMMAND} --build . --target tbb --config ${CMAKE_BUILD_TYPE}
CMAKE_ARGS
-DCMAKE_CXX_FLAGS_DEBUG="/MTd /Od"
-DCMAKE_CXX_FLAGS_RELEASE="/MT"
-DCMAKE_CXX_FLAGS_DEBUG=${FALCOSECURITY_LIBS_DEBUG_FLAGS}
-DCMAKE_CXX_FLAGS_RELEASE=${FALCOSECURITY_LIBS_RELEASE_FLAGS}
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DTBB_OUTPUT_DIR_BASE=lib
Expand All @@ -107,7 +107,7 @@ else()
BUILD_COMMAND ${CMAKE_COMMAND} --build . --target tbb --config ${CMAKE_BUILD_TYPE}
CMAKE_ARGS
-DCMAKE_POLICY_DEFAULT_CMP0091:STRING=NEW
-DCMAKE_MSVC_RUNTIME_LIBRARY:STRING=MultiThreaded$<$<CONFIG:Debug>:Debug>
-DCMAKE_MSVC_RUNTIME_LIBRARY=${CMAKE_MSVC_RUNTIME_LIBRARY}
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DTBB_OUTPUT_DIR_BASE=lib
Expand Down
2 changes: 1 addition & 1 deletion userspace/libsinsp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ include(zlib)

if(WIN32)
set(CMAKE_CXX_FLAGS "-D_CRT_SECURE_NO_WARNINGS -DWIN32 -DMINIMAL_BUILD /EHsc /W3 /Zi /std:c++17")
set(CMAKE_CXX_FLAGS_DEBUG "/MTd /Od")
set(CMAKE_CXX_FLAGS_DEBUG ${FALCOSECURITY_LIBS_DEBUG_FLAGS})
set(CMAKE_CXX_STANDARD 17)
endif()

Expand Down

0 comments on commit a89fd5d

Please sign in to comment.