From dec27c05ed656b37ef75744688529b67c6f60dcc Mon Sep 17 00:00:00 2001 From: Luke Street Date: Wed, 27 May 2020 21:37:03 -0400 Subject: [PATCH] Use CMake MSVC_RUNTIME_LIBRARY to control MSVC flags --- CMakeLists.txt | 2 ++ atdna/CMakeLists.txt | 11 +++-------- extern/zlib/CMakeLists.txt | 4 +--- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a199a9a..60b1c0e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,6 @@ cmake_minimum_required(VERSION 3.10 FATAL_ERROR) # because of c++17 +# Set MSVC runtime library flags from CMAKE_MSVC_RUNTIME_LIBRARY +cmake_policy(SET CMP0091 NEW) project(athena) if (NOT MSVC) set(CMAKE_CXX_STANDARD 20) diff --git a/atdna/CMakeLists.txt b/atdna/CMakeLists.txt index 3730956..15194b8 100644 --- a/atdna/CMakeLists.txt +++ b/atdna/CMakeLists.txt @@ -10,13 +10,6 @@ get_directory_property(ATDNA_DEFINES COMPILE_DEFINITIONS) list(REMOVE_ITEM ATDNA_DEFINES _GLIBCXX_DEBUG=1) set_directory_properties(PROPERTIES COMPILE_DEFINITIONS "${ATDNA_DEFINES}") -# Force this binary to /MD flags (to make MSVC happy) -if(MSVC) - set(CMAKE_CXX_FLAGS_DEBUG "/MD /Zi /Ob0 /Od /RTC1") - set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MD /O2 /Ob2 /DNDEBUG") - set(CMAKE_CXX_FLAGS_RELEASE "/MD /Zi /O2 /Ob1 /DNDEBUG") -endif() - # Find dependencies include(FindLLVM.cmake) if(NOT LLVM_FOUND) @@ -147,7 +140,9 @@ set_source_files_properties(main.cpp PROPERTIES COMPILE_DEFINITIONS target_include_directories(atdna PRIVATE ${LLVM_INCLUDE_DIRS}) target_link_directories(atdna PRIVATE ${LLVM_LIBRARY_DIRS}) if(MSVC) - target_compile_options(atdna PRIVATE /GR-) + # Allow linking against release-built LLVM libraries + target_compile_options(atdna PRIVATE /GR- /D_ITERATOR_DEBUG_LEVEL=0) + set_property(TARGET atdna PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreadedDLL") else() target_compile_options(atdna PRIVATE -fno-rtti -Wno-error) set_property(TARGET atdna PROPERTY CXX_STANDARD 17) diff --git a/extern/zlib/CMakeLists.txt b/extern/zlib/CMakeLists.txt index 87b820e..a09ce94 100644 --- a/extern/zlib/CMakeLists.txt +++ b/extern/zlib/CMakeLists.txt @@ -1,7 +1,5 @@ -if(NOT WIN32) find_package(ZLIB) -endif() -if(WIN32 OR NOT ZLIB_FOUND) +if(NOT ZLIB_FOUND) message(STATUS "Using Athena's built-in zlib") add_library(z adler32.c