mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-22 02:19:50 +01:00
fix(CMake): Select MSVC runtime library with variable CMAKE_MSVC_RUNTIME_LIBRARY (fixes #4817) (#4823)
* fix(CMake): Select MSVC runtime library with variable CMAKE_MSVC_RUNTIME_LIBRARY instead of modifying compiler flags. * enh(CI): Add static and MT MSVC builds. * fix(CMake): Correct TestLibrary DLL name when building with MSVC
This commit is contained in:
parent
a8bac051c3
commit
c9dc1f9d3c
52
.github/workflows/ci.yml
vendored
52
.github/workflows/ci.yml
vendored
@ -607,6 +607,58 @@ jobs:
|
|||||||
cd cmake-build;
|
cd cmake-build;
|
||||||
ctest --output-on-failure -E "(DataMySQL)|(DataODBC)|(Redis)|(MongoDB)" -C Release
|
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<class PathTest>.testFind,
|
||||||
|
class CppUnit::TestCaller<class ICMPSocketTest>.testSendToReceiveFrom,
|
||||||
|
class CppUnit::TestCaller<class ICMPClientTest>.testPing,
|
||||||
|
class CppUnit::TestCaller<class ICMPClientTest>.testBigPing,
|
||||||
|
class CppUnit::TestCaller<class ICMPSocketTest>.testMTU,
|
||||||
|
class CppUnit::TestCaller<class HTTPSClientSessionTest>.testProxy,
|
||||||
|
class CppUnit::TestCaller<class HTTPSStreamFactoryTest>.testProxy,
|
||||||
|
class CppUnit::TestCaller<class FileTest>.testExists,
|
||||||
|
class CppUnit::TestCaller<class ProcessRunnerTest>.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<class PathTest>.testFind,
|
||||||
|
class CppUnit::TestCaller<class ICMPSocketTest>.testSendToReceiveFrom,
|
||||||
|
class CppUnit::TestCaller<class ICMPClientTest>.testPing,
|
||||||
|
class CppUnit::TestCaller<class ICMPClientTest>.testBigPing,
|
||||||
|
class CppUnit::TestCaller<class ICMPSocketTest>.testMTU,
|
||||||
|
class CppUnit::TestCaller<class HTTPSClientSessionTest>.testProxy,
|
||||||
|
class CppUnit::TestCaller<class HTTPSStreamFactoryTest>.testProxy,
|
||||||
|
class CppUnit::TestCaller<class FileTest>.testExists,
|
||||||
|
class CppUnit::TestCaller<class ProcessRunnerTest>.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
|
# missing asan dll path
|
||||||
# windows-2022-msvc-cmake-asan:
|
# windows-2022-msvc-cmake-asan:
|
||||||
# runs-on: windows-2022
|
# runs-on: windows-2022
|
||||||
|
@ -58,12 +58,12 @@ include(GNUInstallDirs)
|
|||||||
# Include some common macros to simpilfy the Poco CMake files
|
# Include some common macros to simpilfy the Poco CMake files
|
||||||
include(PocoMacros)
|
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")
|
set(POCO_SANITIZEFLAGS CACHE STRING "Compiler-dependent sanitizer flags (like -fsanitize=address or /fsanitize=address")
|
||||||
|
|
||||||
if(MSVC)
|
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)
|
if(BUILD_SHARED_LIBS AND POCO_MT)
|
||||||
message(FATAL_ERROR "Cannot have both BUILD_SHARED_LIBS and POCO_MT")
|
message(FATAL_ERROR "Cannot have both BUILD_SHARED_LIBS and POCO_MT")
|
||||||
|
@ -59,7 +59,13 @@ target_link_libraries(TestApp PUBLIC Poco::Foundation)
|
|||||||
|
|
||||||
# TestLibrary
|
# TestLibrary
|
||||||
add_library(TestLibrary SHARED src/TestLibrary.cpp src/TestPlugin.cpp src/TestPlugin.h)
|
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
|
# 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})
|
set_target_properties(TestLibrary PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||||
target_link_libraries(TestLibrary PUBLIC Poco::Foundation)
|
target_link_libraries(TestLibrary PUBLIC Poco::Foundation)
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
# * MinSizeRel (CMAKE_C_FLAGS_MINSIZEREL or CMAKE_CXX_FLAGS_MINSIZEREL)
|
# * 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
|
# 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:
|
# For visual studio the library naming is as following:
|
||||||
# Dynamic libraries:
|
# Dynamic libraries:
|
||||||
@ -30,27 +31,15 @@ endif()
|
|||||||
|
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
if(POCO_MT)
|
if(POCO_MT)
|
||||||
set(CompilerFlags
|
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
||||||
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(STATIC_POSTFIX "mt" CACHE STRING "Set static library postfix" FORCE)
|
set(STATIC_POSTFIX "mt" CACHE STRING "Set static library postfix" FORCE)
|
||||||
else(POCO_MT)
|
else(POCO_MT)
|
||||||
|
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
||||||
set(STATIC_POSTFIX "md" CACHE STRING "Set static library postfix" FORCE)
|
set(STATIC_POSTFIX "md" CACHE STRING "Set static library postfix" FORCE)
|
||||||
endif(POCO_MT)
|
endif(POCO_MT)
|
||||||
|
|
||||||
|
message(STATUS "MSVC runtime library: ${CMAKE_MSVC_RUNTIME_LIBRARY}")
|
||||||
|
|
||||||
if(POCO_SANITIZE_ASAN)
|
if(POCO_SANITIZE_ASAN)
|
||||||
message(WARNING "Use POCO_SANITIZEFLAGS instead of POCO_SANITIZE_ASAN")
|
message(WARNING "Use POCO_SANITIZEFLAGS instead of POCO_SANITIZE_ASAN")
|
||||||
add_compile_options("/fsanitize=address")
|
add_compile_options("/fsanitize=address")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user