From dc086d2ebbb04817458b214708c5038600e96095 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20D=C3=ADaz=20M=C3=A1s?= Date: Wed, 17 Oct 2018 09:27:45 +0200 Subject: [PATCH] Default to /MD(d) even for STATIC builds. We had issues to compile exiv2 due to a undefined symbol referenced in expat.lib (Explained in #487). Static builds in Windows need to use msvcrt.lib where the missing symbol ("__imp__mbspbrk") was defined. We can still decide to use the STATIC CRT library by using: cmake -DBUILD_SHARED_LIBS=OFF -DEXIV2_ENABLE_DYNAMIC_RUNTIME=OFF --- CMakeLists.txt | 2 +- cmake/compilerFlags.cmake | 33 +++++++++------------------------ 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c5e70c73..f4ed27af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ option( EXIV2_ENABLE_NLS "Build native language support (requires g option( EXIV2_ENABLE_PRINTUCS2 "Build with Printucs2" ON ) option( EXIV2_ENABLE_LENSDATA "Build including lens data" ON ) option( EXIV2_ENABLE_VIDEO "Build video support into library" OFF ) -option( EXIV2_ENABLE_DYNAMIC_RUNTIME "Use dynamic runtime (used for static libs)" OFF ) +option( EXIV2_ENABLE_DYNAMIC_RUNTIME "Use dynamic runtime (used for static libs)" ON ) option( EXIV2_ENABLE_WIN_UNICODE "Use Unicode paths (wstring) on Windows" OFF ) option( EXIV2_ENABLE_WEBREADY "Build webready support into library" OFF ) option( EXIV2_ENABLE_CURL "USE Libcurl for HttpIo (WEBREADY)" OFF ) diff --git a/cmake/compilerFlags.cmake b/cmake/compilerFlags.cmake index 0dd1fc39..6519eff8 100644 --- a/cmake/compilerFlags.cmake +++ b/cmake/compilerFlags.cmake @@ -164,22 +164,15 @@ if(MSVC) CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELWITHDEBINFO ) - if ( ${BUILD_SHARED_LIBS} OR ${EXIV2_ENABLE_DYNAMIC_RUNTIME} ) - message(STATUS "MSVC -> forcing use of dynamically-linked runtime." ) - foreach(variable ${variables}) - if(${variable} MATCHES "/MT") - string(REGEX REPLACE "/MT" "/MD" ${variable} "${${variable}}") - endif() - endforeach() - else() - message(STATUS "MSVC -> forcing use of statically-linked runtime." ) - foreach(variable ${variables}) - if(${variable} MATCHES "/MD") - string(REGEX REPLACE "/MD" "/MT" ${variable} "${${variable}}") - endif() - set(${variable} "${${variable}} /DXML_STATIC /D_LIB") - endforeach() - endif() + + if (NOT BUILD_SHARED_LIBS AND NOT EXIV2_ENABLE_DYNAMIC_RUNTIME) + message(STATUS "MSVC -> forcing use of statically-linked runtime." ) + foreach(variable ${variables}) + if(${variable} MATCHES "/MD") + string(REGEX REPLACE "/MD" "/MT" ${variable} "${${variable}}") + endif() + endforeach() + endif() # remove /Ob2 and /Ob1 - they cause linker issues set(obs /Ob2 /Ob1) @@ -191,14 +184,6 @@ if(MSVC) endforeach() endforeach() - # don't link msvcrt for .exe which use shared libraries (use default libcmt) - if ( NOT ${BUILD_SHARED_LIBS} AND NOT ${EXIV2_ENABLE_DYNAMIC_RUNTIME}) - set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/NODEFAULTLIB:MSVCRTD") - set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/NODEFAULTLIB:MSVCRT") - set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "/NODEFAULTLIB:MSVCRT") - set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "/NODEFAULTLIB:MSVCRT") - endif() - if ( EXIV2_EXTRA_WARNINGS ) string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") endif ()