Skip to content

Commit

Permalink
CMake: Modifiy CMAKE_CXX_FLAGS* after enable_language(CXX)
Browse files Browse the repository at this point in the history
Brought to the surface by link errors in AppVeyor:
error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease'
  • Loading branch information
hartwork committed Jun 10, 2019
1 parent e105417 commit cb0001d
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions CMakeLists.txt
Expand Up @@ -76,20 +76,17 @@ if(URIPARSER_BUILD_TOOLS AND NOT URIPARSER_BUILD_CHAR)
message(SEND_ERROR "URIPARSER_BUILD_TOOLS=ON requires URIPARSER_BUILD_CHAR=ON.")
endif()

macro(uriparser_apply_msvc_runtime_to ref)
string(REGEX REPLACE "/M[DT]d?" ${URIPARSER_MSVC_RUNTIME} ${ref} "${${ref}}")
endmacro()

if(MSVC AND URIPARSER_MSVC_RUNTIME)
set(_refs
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
)
foreach(_ref ${_refs})
string(REGEX REPLACE "/M[DT]d?" ${URIPARSER_MSVC_RUNTIME} ${_ref} "${${_ref}}")
endforeach()
uriparser_apply_msvc_runtime_to(CMAKE_C_FLAGS)
uriparser_apply_msvc_runtime_to(CMAKE_C_FLAGS_DEBUG)
uriparser_apply_msvc_runtime_to(CMAKE_C_FLAGS_RELEASE)
endif()


#
# Compiler checks
#
Expand Down Expand Up @@ -246,6 +243,12 @@ endif()
if(URIPARSER_BUILD_TESTS)
enable_language(CXX)

if(MSVC AND URIPARSER_MSVC_RUNTIME)
uriparser_apply_msvc_runtime_to(CMAKE_CXX_FLAGS)
uriparser_apply_msvc_runtime_to(CMAKE_CXX_FLAGS_DEBUG)
uriparser_apply_msvc_runtime_to(CMAKE_CXX_FLAGS_RELEASE)
endif()

enable_testing()

find_package(GTest 1.8.0 REQUIRED)
Expand Down

0 comments on commit cb0001d

Please sign in to comment.