From 870a3e9b5ba960557c187c6e65200c63c85f81ef Mon Sep 17 00:00:00 2001 From: Matej Kenda Date: Wed, 18 Dec 2024 09:34:55 +0100 Subject: [PATCH 1/3] fix(CMake): Select MSVC runtime library with variable CMAKE_MSVC_RUNTIME_LIBRARY instead of modifying compiler flags. --- cmake/DefinePlatformSpecific.cmake | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/cmake/DefinePlatformSpecific.cmake b/cmake/DefinePlatformSpecific.cmake index e71f7abd81..7d7e51e3cd 100644 --- a/cmake/DefinePlatformSpecific.cmake +++ b/cmake/DefinePlatformSpecific.cmake @@ -9,6 +9,7 @@ # * MinSizeRel (CMAKE_C_FLAGS_MINSIZEREL or CMAKE_CXX_FLAGS_MINSIZEREL) # Setting CXX Flag /MD or /MT and POSTFIX values i.e MDd / MD / MTd / MT / d +# using CMake variable CMAKE_MSVC_RUNTIME_LIBRARY. # # For visual studio the library naming is as following: # Dynamic libraries: @@ -30,24 +31,10 @@ endif() if(MSVC) if(POCO_MT) - set(CompilerFlags - CMAKE_CXX_FLAGS - CMAKE_CXX_FLAGS_DEBUG - CMAKE_CXX_FLAGS_RELEASE - CMAKE_CXX_FLAGS_RELWITHDEBINFO - CMAKE_CXX_FLAGS_MINSIZEREL - CMAKE_C_FLAGS - CMAKE_C_FLAGS_DEBUG - CMAKE_C_FLAGS_RELEASE - CMAKE_C_FLAGS_RELWITHDEBINFO - CMAKE_C_FLAGS_MINSIZEREL - ) - foreach(CompilerFlag ${CompilerFlags}) - string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}") - endforeach() - + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") set(STATIC_POSTFIX "mt" CACHE STRING "Set static library postfix" FORCE) else(POCO_MT) + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") set(STATIC_POSTFIX "md" CACHE STRING "Set static library postfix" FORCE) endif(POCO_MT) From 17d5ca15916596b47696aa5038346701da42af20 Mon Sep 17 00:00:00 2001 From: Matej Kenda Date: Wed, 18 Dec 2024 13:54:24 +0100 Subject: [PATCH 2/3] enh(CI): Add static and MT MSVC builds. --- .github/workflows/ci.yml | 52 ++++++++++++++++++++++++++++++++++++++++ CMakeLists.txt | 2 +- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 761a41d946..8bb5a96574 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -607,6 +607,58 @@ jobs: cd cmake-build; ctest --output-on-failure -E "(DataMySQL)|(DataODBC)|(Redis)|(MongoDB)" -C Release + windows-2022-msvc-cmake-static-mt: + runs-on: windows-2022 + env: + CPPUNIT_IGNORE: >- + class CppUnit::TestCaller.testFind, + class CppUnit::TestCaller.testSendToReceiveFrom, + class CppUnit::TestCaller.testPing, + class CppUnit::TestCaller.testBigPing, + class CppUnit::TestCaller.testMTU, + class CppUnit::TestCaller.testProxy, + class CppUnit::TestCaller.testProxy, + class CppUnit::TestCaller.testExists, + class CppUnit::TestCaller.testProcessRunner + steps: + - uses: actions/checkout@v4 + - run: cmake -S. -Bcmake-build -DBUILD_SHARED_LIBS=OFF -DPOCO_MT=ON -DENABLE_NETSSL_WIN=ON -DENABLE_NETSSL=OFF -DENABLE_CRYPTO=OFF -DENABLE_JWT=OFF -DENABLE_DATA=ON -DENABLE_DATA_ODBC=ON -DENABLE_DATA_MYSQL=OFF -DENABLE_DATA_POSTGRESQL=OFF -DENABLE_TESTS=ON + - run: cmake --build cmake-build --config Release + - uses: ./.github/actions/retry-action + with: + timeout_minutes: 90 + max_attempts: 3 + retry_on: any + command: >- + cd cmake-build; + ctest --output-on-failure -E "(DataMySQL)|(DataODBC)|(Redis)|(MongoDB)" -C Release + + windows-2022-msvc-cmake-static: + runs-on: windows-2022 + env: + CPPUNIT_IGNORE: >- + class CppUnit::TestCaller.testFind, + class CppUnit::TestCaller.testSendToReceiveFrom, + class CppUnit::TestCaller.testPing, + class CppUnit::TestCaller.testBigPing, + class CppUnit::TestCaller.testMTU, + class CppUnit::TestCaller.testProxy, + class CppUnit::TestCaller.testProxy, + class CppUnit::TestCaller.testExists, + class CppUnit::TestCaller.testProcessRunner + steps: + - uses: actions/checkout@v4 + - run: cmake -S. -Bcmake-build -DBUILD_SHARED_LIBS=OFF -DENABLE_NETSSL_WIN=ON -DENABLE_NETSSL=OFF -DENABLE_CRYPTO=OFF -DENABLE_JWT=OFF -DENABLE_DATA=ON -DENABLE_DATA_ODBC=ON -DENABLE_DATA_MYSQL=OFF -DENABLE_DATA_POSTGRESQL=OFF -DENABLE_TESTS=ON + - run: cmake --build cmake-build --config Release + - uses: ./.github/actions/retry-action + with: + timeout_minutes: 90 + max_attempts: 3 + retry_on: any + command: >- + cd cmake-build; + ctest --output-on-failure -E "(DataMySQL)|(DataODBC)|(Redis)|(MongoDB)" -C Release + # missing asan dll path # windows-2022-msvc-cmake-asan: # runs-on: windows-2022 diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d120e68fb..303d75fc50 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,7 +63,7 @@ option(BUILD_SHARED_LIBS "Build using shared libraries" ON) set(POCO_SANITIZEFLAGS CACHE STRING "Compiler-dependent sanitizer flags (like -fsanitize=address or /fsanitize=address") if(MSVC) - option(POCO_MT "Set to OFF|ON (default is OFF) to control build of POCO as /MT instead of /MD" OFF) + option(POCO_MT "Set to OFF|ON (default is OFF) to control static build of POCO as /MT instead of /MD" OFF) if(BUILD_SHARED_LIBS AND POCO_MT) message(FATAL_ERROR "Cannot have both BUILD_SHARED_LIBS and POCO_MT") From 59f2048f96da0b05967a7ac03350522658dd5212 Mon Sep 17 00:00:00 2001 From: Matej Kenda Date: Fri, 20 Dec 2024 10:10:24 +0100 Subject: [PATCH 3/3] fix(CMake): Correct TestLibrary DLL name when building with MSVC --- CMakeLists.txt | 2 +- Foundation/testsuite/CMakeLists.txt | 8 +++++++- cmake/DefinePlatformSpecific.cmake | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 303d75fc50..c82ae3c820 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,7 +58,7 @@ include(GNUInstallDirs) # Include some common macros to simpilfy the Poco CMake files include(PocoMacros) -option(BUILD_SHARED_LIBS "Build using shared libraries" ON) +option(BUILD_SHARED_LIBS "Build shared libraries" ON) set(POCO_SANITIZEFLAGS CACHE STRING "Compiler-dependent sanitizer flags (like -fsanitize=address or /fsanitize=address") diff --git a/Foundation/testsuite/CMakeLists.txt b/Foundation/testsuite/CMakeLists.txt index 25429709d2..389f6137b4 100644 --- a/Foundation/testsuite/CMakeLists.txt +++ b/Foundation/testsuite/CMakeLists.txt @@ -59,7 +59,13 @@ target_link_libraries(TestApp PUBLIC Poco::Foundation) # TestLibrary add_library(TestLibrary SHARED src/TestLibrary.cpp src/TestPlugin.cpp src/TestPlugin.h) -set_target_properties(TestLibrary PROPERTIES PREFIX "" DEBUG_POSTFIX "d") # The test requires the library named TestLibrary. By default it is prefixed with lib. +set_target_properties(TestLibrary PROPERTIES DEBUG_POSTFIX "d") +set_target_properties(TestLibrary PROPERTIES RELEASE_POSTFIX "") +set_target_properties(TestLibrary PROPERTIES CMAKE_MINSIZEREL_POSTFIX "") +set_target_properties(TestLibrary PROPERTIES CMAKE_RELWITHDEBINFO_POSTFIX "") +# The test requires the library named TestLibrary. By default it is prefixed with lib. +set_target_properties(TestLibrary PROPERTIES PREFIX "") + # The test is run in the runtime directory. So the TestLibrary is built there too because it is used by the tests set_target_properties(TestLibrary PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) target_link_libraries(TestLibrary PUBLIC Poco::Foundation) diff --git a/cmake/DefinePlatformSpecific.cmake b/cmake/DefinePlatformSpecific.cmake index 7d7e51e3cd..b8d864cc19 100644 --- a/cmake/DefinePlatformSpecific.cmake +++ b/cmake/DefinePlatformSpecific.cmake @@ -38,6 +38,8 @@ if(MSVC) set(STATIC_POSTFIX "md" CACHE STRING "Set static library postfix" FORCE) endif(POCO_MT) + message(STATUS "MSVC runtime library: ${CMAKE_MSVC_RUNTIME_LIBRARY}") + if(POCO_SANITIZE_ASAN) message(WARNING "Use POCO_SANITIZEFLAGS instead of POCO_SANITIZE_ASAN") add_compile_options("/fsanitize=address")