Skip to content

Commit

Permalink
Revert "Improvements to CMake buildsystem (jbeder#563)"
Browse files Browse the repository at this point in the history
This reverts commit 3e33bb3.

The original commit broke the build (jbeder#612) when yaml-cpp is used as a git submodule.
  • Loading branch information
jbeder committed Aug 9, 2018
1 parent 3e33bb3 commit c90c08c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 51 deletions.
26 changes: 19 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
###
### CMake settings
###
## Due to Mac OSX we need to keep compatibility with CMake 2.6
# see http://www.cmake.org/Wiki/CMake_Policies
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 2.6)
# see http://www.cmake.org/cmake/help/cmake-2-8-docs.html#policy:CMP0012
if(POLICY CMP0012)
cmake_policy(SET CMP0012 OLD)
endif()
# see http://www.cmake.org/cmake/help/cmake-2-8-docs.html#policy:CMP0015
if(POLICY CMP0015)
cmake_policy(SET CMP0015 OLD)
endif()
# see https://cmake.org/cmake/help/latest/policy/CMP0042.html
if(POLICY CMP0042)
# Enable MACOSX_RPATH by default.
cmake_policy(SET CMP0042 NEW)
endif()

include(CheckCXXCompilerFlag)


###
### Project settings
###
Expand All @@ -16,6 +31,8 @@ set(YAML_CPP_VERSION_MINOR "6")
set(YAML_CPP_VERSION_PATCH "2")
set(YAML_CPP_VERSION "${YAML_CPP_VERSION_MAJOR}.${YAML_CPP_VERSION_MINOR}.${YAML_CPP_VERSION_PATCH}")

enable_testing()


###
### Project options
Expand All @@ -31,10 +48,6 @@ option(YAML_CPP_BUILD_CONTRIB "Enable contrib stuff in library" ON)
# http://www.cmake.org/cmake/help/cmake2.6docs.html#command:add_library
option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF)

# Set minimum C++ to 2011 standards
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# --> Apple
option(APPLE_UNIVERSAL_BIN "Apple: Build universal binary" OFF)

Expand Down Expand Up @@ -175,7 +188,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR
set(GCC_EXTRA_OPTIONS "${GCC_EXTRA_OPTIONS} ${FLAG_TESTED}")
endif()
#
set(yaml_cxx_flags "-Wall ${GCC_EXTRA_OPTIONS} -pedantic -Wno-long-long ${yaml_cxx_flags}")
set(yaml_cxx_flags "-Wall ${GCC_EXTRA_OPTIONS} -pedantic -Wno-long-long -std=c++11 ${yaml_cxx_flags}")

### Make specific
if(${CMAKE_BUILD_TOOL} MATCHES make OR ${CMAKE_BUILD_TOOL} MATCHES gmake)
Expand Down Expand Up @@ -347,7 +360,6 @@ endif()
### Extras
###
if(YAML_CPP_BUILD_TESTS)
enable_testing()
add_subdirectory(test)
endif()
if(YAML_CPP_BUILD_TOOLS)
Expand Down
67 changes: 24 additions & 43 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,39 +1,26 @@
include(ExternalProject)

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 "")
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(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")

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(yaml_test_flags "${yaml_test_flags} -Wno-c99-extensions")
endif()
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_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)
Expand All @@ -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)
4 changes: 3 additions & 1 deletion util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ cmake_minimum_required(VERSION 3.5)
add_sources(parse.cpp)
add_executable(parse parse.cpp)
target_link_libraries(parse yaml-cpp)
set_target_properties(parse PROPERTIES COMPILE_FLAGS "-std=c++11")

add_sources(sandbox.cpp)
add_executable(sandbox sandbox.cpp)
target_link_libraries(sandbox yaml-cpp)
set_target_properties(sandbox PROPERTIES COMPILE_FLAGS "-std=c++11")

add_sources(read.cpp)
add_executable(read read.cpp)
target_link_libraries(read yaml-cpp)

set_target_properties(read PROPERTIES COMPILE_FLAGS "-std=c++11")

0 comments on commit c90c08c

Please sign in to comment.