Commit 9ec588a2 authored by Philip Quinn's avatar Philip Quinn

CMake: Simplify gtest library paths and use the default MSVC CRT flags.

parent aa47edcc
......@@ -34,11 +34,6 @@ endif()
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 ${CAPNP_LITE_FLAG}")
# Statically link with the runtime libraries.
# TODO: This should depend on whether or not Cap'n Proto is being built as a static or shared library.
# When building the tests, this needs to match with how gtest is built as well.
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter -std=c++11 -pthread ${CAPNP_LITE_FLAG}")
endif()
......
......@@ -15,34 +15,37 @@ if(BUILD_TESTING)
ExternalProject_Add(gtest_build
URL http://googletest.googlecode.com/files/gtest-1.7.0.zip
URL_MD5 2d6ec8ccdf5c46b05ba54a9fd1d130d7
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -Dgtest_force_shared_crt=1
INSTALL_COMMAND "" # Disable install
)
ExternalProject_Get_Property(gtest_build binary_dir)
# Set platform-specific library prefix/extensions.
if(MSVC)
set(gtest_prefix)
set(gtest_suffix ".lib")
else()
set(gtest_prefix "lib")
set(gtest_suffix ".a")
endif()
add_library(gtest UNKNOWN IMPORTED)
if(CMAKE_GENERATOR MATCHES "Visual Studio.*")
set_target_properties(gtest PROPERTIES IMPORTED_LOCATION_DEBUG "${binary_dir}/Debug/gtest.lib")
set_target_properties(gtest PROPERTIES IMPORTED_LOCATION_RELEASE "${binary_dir}/Release/gtest.lib")
elseif(CMAKE_GENERATOR STREQUAL Xcode)
set_target_properties(gtest PROPERTIES IMPORTED_LOCATION_DEBUG "${binary_dir}/Debug/libgtest.a")
set_target_properties(gtest PROPERTIES IMPORTED_LOCATION_RELEASE "${binary_dir}/Release/libgtest.a")
if(CMAKE_GENERATOR MATCHES "Visual Studio.*" OR CMAKE_GENERATOR STREQUAL Xcode)
set_target_properties(gtest PROPERTIES IMPORTED_LOCATION_DEBUG "${binary_dir}/Debug/${gtest_prefix}gtest${gtest_suffix}")
set_target_properties(gtest PROPERTIES IMPORTED_LOCATION_RELEASE "${binary_dir}/Release/${gtest_prefix}gtest${gtest_suffix}")
else()
set_target_properties(gtest PROPERTIES IMPORTED_LOCATION "${binary_dir}/libgtest.a")
set_target_properties(gtest PROPERTIES IMPORTED_LOCATION "${binary_dir}/${gtest_prefix}gtest${gtest_suffix}")
endif()
add_dependencies(gtest gtest_build)
add_library(gtest_main UNKNOWN IMPORTED)
if(CMAKE_GENERATOR MATCHES "Visual Studio.*")
set_target_properties(gtest_main PROPERTIES IMPORTED_LOCATION_DEBUG "${binary_dir}/Debug/gtest_main.lib")
set_target_properties(gtest_main PROPERTIES IMPORTED_LOCATION_RELEASE "${binary_dir}/Release/gtest_main.lib")
elseif(CMAKE_GENERATOR STREQUAL Xcode)
set_target_properties(gtest_main PROPERTIES IMPORTED_LOCATION_DEBUG "${binary_dir}/Debug/libgtest_main.a")
set_target_properties(gtest_main PROPERTIES IMPORTED_LOCATION_RELEASE "${binary_dir}/Release/libgtest_main.a")
if(CMAKE_GENERATOR MATCHES "Visual Studio.*" OR CMAKE_GENERATOR STREQUAL Xcode)
set_target_properties(gtest_main PROPERTIES IMPORTED_LOCATION_DEBUG "${binary_dir}/Debug/${gtest_prefix}gtest_main${gtest_suffix}")
set_target_properties(gtest_main PROPERTIES IMPORTED_LOCATION_RELEASE "${binary_dir}/Release/${gtest_prefix}gtest_main${gtest_suffix}")
else()
set_target_properties(gtest_main PROPERTIES IMPORTED_LOCATION "${binary_dir}/libgtest_main.a")
set_target_properties(gtest_main PROPERTIES IMPORTED_LOCATION "${binary_dir}/${gtest_prefix}gtest_main${gtest_suffix}")
endif()
add_dependencies(gtest_main gtest)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment