Commit 5e9cb012 by Isabella Muerte Committed by Jesse Beder

Refactor CMake to use more modern paradigms (#741)

Remove 2.6-isms
Remove 2.8-isms
Bump CMake minimum version to 3.4

Disable some options when used as a subdirectory

Use `CONFIGURE_DEPENDS` with `file(GLOB)` when possible

Backport CMake 3.15's MSVC_RUNTIME_LIBRARY setting.
Set all compile options as generator expressions.
Set all find-package files to be installed to the correct file.

Remove `export(PACKAGE)`, as this has been deprecated.
Remove fat binary support
Remove manual setting of iPhone settings. These should be set by parent
projects.
Remove use of ExternalProject for a local use
Conditionally remove format target unless clang-format is found
parent 9a362420
...@@ -18,10 +18,10 @@ before_script: ...@@ -18,10 +18,10 @@ before_script:
- mkdir build - mkdir build
- cd build - cd build
- cmake .. - cmake ..
- cd ..
script: script:
- make - cmake --build build
- test/run-tests - cmake --build build --target test
matrix: matrix:
exclude: exclude:
- os: linux - os: linux
......
include(ExternalProject) find_package(Threads REQUIRED)
if(MSVC) set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
# MS Visual Studio expects lib prefix on static libraries, set(BUILD_MOCK ON CACHE BOOL "" FORCE)
# but CMake compiles them without prefix set(CMAKE_POLICY_DEFAULT_CMP0048 NEW)
# See https://gitlab.kitware.com/cmake/cmake/issues/17338
set(CMAKE_STATIC_LIBRARY_PREFIX "")
endif()
ExternalProject_Add(
googletest_project
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/gtest-1.8.0"
INSTALL_DIR "${CMAKE_CURRENT_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}/test/prefix/lib/${CMAKE_STATIC_LIBRARY_PREFIX}gmock${CMAKE_STATIC_LIBRARY_SUFFIX}
)
find_package(Threads) add_subdirectory(
"${CMAKE_CURRENT_SOURCE_DIR}/gtest-1.8.0"
"${CMAKE_CURRENT_BINARY_DIR}/prefix")
include_directories(SYSTEM "${PROJECT_BINARY_DIR}/test/prefix/include") include_directories(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/gtest-1.8.0/googletest/include")
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR set(test-new-api-pattern "new-api/*.cpp")
CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(test-source-pattern "*.cpp" "integration/*.cpp" "node/*.cpp")
set(yaml_test_flags "-Wno-variadic-macros -Wno-sign-compare") if (CMAKE_VERSION VERSION_GREATER 3.11)
list(INSERT test-new-api-pattern 0 CONFIGURE_DEPENDS)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") list(INSERT test-source-pattern 0 CONFIGURE_DEPENDS)
set(yaml_test_flags "${yaml_test_flags} -Wno-c99-extensions")
endif()
endif() endif()
file(GLOB test_headers [a-z_]*.h) file(GLOB test-new-api-sources ${test-new-api-pattern})
file(GLOB test_sources [a-z_]*.cpp integration/[a-z_]*.cpp node/[a-z_]*.cpp) file(GLOB test-sources ${test-source-pattern})
file(GLOB test_new_api_sources new-api/[a-z]*.cpp)
add_executable(yaml-cpp-tests)
list(APPEND test_sources ${test_new_api_sources}) target_sources(yaml-cpp-tests
add_sources(${test_sources} ${test_headers}) PRIVATE
${test-new-api-sources}
include_directories(${YAML_CPP_SOURCE_DIR}/src) ${test-sources})
include_directories(${YAML_CPP_SOURCE_DIR}/test) target_include_directories(yaml-cpp-tests
PRIVATE
add_executable(run-tests ${CMAKE_CURRENT_SOURCE_DIR}/integration
${test_sources} ${CMAKE_CURRENT_SOURCE_DIR}
${test_headers} ${PROJECT_SOURCE_DIR}/src)
) target_compile_options(yaml-cpp-tests
PRIVATE
set_target_properties(run-tests PROPERTIES $<$<CXX_COMPILER_ID:Clang>:-Wno-c99-extensions -Wno-variadic-macros -Wno-sign-compare>
CXX_STANDARD 11 $<$<CXX_COMPILER_ID:GNU>:-Wno-variadic-macros -Wno-sign-compare>)
CXX_STANDARD_REQUIRED ON target_link_libraries(yaml-cpp-tests
) PRIVATE
Threads::Threads
yaml-cpp
gmock)
add_dependencies(run-tests googletest_project) set_property(TARGET yaml-cpp-tests PROPERTY CXX_STANDARD_REQUIRED ON)
if (NOT DEFINED CMAKE_CXX_STANDARD)
set_target_properties(yaml-cpp-tests PROPERTIES CXX_STANDARD 11)
endif()
set_target_properties(run-tests PROPERTIES
COMPILE_FLAGS "${yaml_c_flags} ${yaml_cxx_flags} ${yaml_test_flags}"
)
target_link_libraries(run-tests
yaml-cpp
gmock
${CMAKE_THREAD_LIBS_INIT})
add_test(yaml-test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/run-tests) add_test(yaml-cpp::test yaml-cpp-tests)
#include <stddef.h>
#include <sstream> #include <sstream>
#include <cstddef>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "yaml-cpp/ostream_wrapper.h" #include "yaml-cpp/ostream_wrapper.h"
......
cmake_minimum_required(VERSION 3.5) add_executable(yaml-cpp-sandbox sandbox.cpp)
add_executable(yaml-cpp-parse parse.cpp)
add_executable(yaml-cpp-read read.cpp)
add_sources(parse.cpp) target_link_libraries(yaml-cpp-sandbox PRIVATE yaml-cpp)
add_executable(parse parse.cpp) target_link_libraries(yaml-cpp-parse PRIVATE yaml-cpp)
set_target_properties(parse PROPERTIES target_link_libraries(yaml-cpp-read PRIVATE yaml-cpp)
CXX_STANDARD 11
set_property(TARGET yaml-cpp-sandbox PROPERTY OUTPUT_NAME sandbox)
set_property(TARGET yaml-cpp-parse PROPERTY OUTPUT_NAME parse)
set_property(TARGET yaml-cpp-read PROPERTY OUTPUT_NAME read)
set_target_properties(yaml-cpp-sandbox
PROPERTIES
CXX_STANDARD_REQUIRED ON CXX_STANDARD_REQUIRED ON
) OUTPUT_NAME sandbox)
target_link_libraries(parse yaml-cpp)
add_sources(sandbox.cpp) set_target_properties(yaml-cpp-parse
add_executable(sandbox sandbox.cpp) PROPERTIES
set_target_properties(sandbox PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED ON CXX_STANDARD_REQUIRED ON
) OUTPUT_NAME parse)
target_link_libraries(sandbox yaml-cpp)
add_sources(read.cpp) set_target_properties(yaml-cpp-read
add_executable(read read.cpp) PROPERTIES
set_target_properties(read PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED ON CXX_STANDARD_REQUIRED ON
) OUTPUT_NAME read)
target_link_libraries(read yaml-cpp)
if (NOT DEFINED CMAKE_CXX_STANDARD)
set_target_properties(yaml-cpp-sandbox yaml-cpp-parse yaml-cpp-read
PROPERTIES
CXX_STANDARD 11)
endif()
set(PACKAGE_VERSION "@YAML_CPP_VERSION@")
# Check whether the requested PACKAGE_FIND_VERSION is compatible
if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}")
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()
set(PACKAGE_VERSION_COMPATIBLE TRUE)
if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}")
set(PACKAGE_VERSION_EXACT TRUE)
endif()
endif()
prefix=@CMAKE_INSTALL_PREFIX@ prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix} exec_prefix=${prefix}
includedir=${prefix}/@INCLUDE_INSTALL_ROOT_DIR@ includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
libdir=${exec_prefix}/@LIB_INSTALL_DIR@ libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
Name: Yaml-cpp Name: Yaml-cpp
Description: A YAML parser and emitter for C++ Description: A YAML parser and emitter for C++
......
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