Revert "Improvements to CMake buildsystem (#563)"

This reverts commit 3e33bb3166.

The original commit broke the build (#612) when yaml-cpp is used as a git submodule.
This commit is contained in:
Jesse Beder
2018-08-09 10:05:07 -05:00
parent 3e33bb3166
commit c90c08ccc9
3 changed files with 44 additions and 49 deletions

View File

@@ -1,39 +1,26 @@
include(ExternalProject)
set(gtest_force_shared_crt ${MSVC_SHARED_RT} CACHE BOOL
"Use shared (DLL) run-time lib even when Google Test built as a static lib.")
add_subdirectory(gtest-1.8.0)
include_directories(SYSTEM gtest-1.8.0/googlemock/include)
include_directories(SYSTEM gtest-1.8.0/googletest/include)
if(MSVC)
# MS Visual Studio expects lib prefix on static libraries,
# but CMake compiles them without prefix
# See https://gitlab.kitware.com/cmake/cmake/issues/17338
set(CMAKE_STATIC_LIBRARY_PREFIX "")
if(WIN32 AND BUILD_SHARED_LIBS)
add_definitions("-DGTEST_LINKED_AS_SHARED_LIBRARY")
endif()
ExternalProject_Add(
googletest_project
SOURCE_DIR "${CMAKE_SOURCE_DIR}/test/gtest-1.8.0"
INSTALL_DIR "${CMAKE_BINARY_DIR}/prefix"
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DBUILD_GMOCK=ON
-Dgtest_force_shared_crt=ON
)
add_library(gmock UNKNOWN IMPORTED)
set_target_properties(gmock PROPERTIES
IMPORTED_LOCATION
${PROJECT_BINARY_DIR}/prefix/lib/${CMAKE_STATIC_LIBRARY_PREFIX}gmock${CMAKE_STATIC_LIBRARY_SUFFIX}
)
find_package(Threads)
include_directories(SYSTEM "${PROJECT_BINARY_DIR}/prefix/include")
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(yaml_test_flags "-Wno-variadic-macros -Wno-sign-compare")
CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(yaml_test_flags "-Wno-variadic-macros -Wno-sign-compare")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(yaml_test_flags "${yaml_test_flags} -Wno-c99-extensions")
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(yaml_test_flags "${yaml_test_flags} -Wno-c99-extensions")
endif()
if(CMAKE_COMPILER_IS_GNUCXX)
set(yaml_test_flags "${yaml_test_flags} -std=gnu++11")
else()
set(yaml_test_flags "${yaml_test_flags} -std=c++11")
endif()
endif()
file(GLOB test_headers [a-z_]*.h)
@@ -47,18 +34,12 @@ include_directories(${YAML_CPP_SOURCE_DIR}/src)
include_directories(${YAML_CPP_SOURCE_DIR}/test)
add_executable(run-tests
${test_sources}
${test_headers}
${test_sources}
${test_headers}
)
add_dependencies(run-tests googletest_project)
set_target_properties(run-tests PROPERTIES
COMPILE_FLAGS "${yaml_c_flags} ${yaml_cxx_flags} ${yaml_test_flags}"
COMPILE_FLAGS "${yaml_c_flags} ${yaml_cxx_flags} ${yaml_test_flags}"
)
target_link_libraries(run-tests
yaml-cpp
gmock
${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(run-tests yaml-cpp gmock)
add_test(yaml-test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/run-tests)