forked from ros2/yaml_cpp_vendor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
100 lines (86 loc) · 3.36 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
cmake_minimum_required(VERSION 3.5)
project(yaml_cpp_vendor)
option(FORCE_BUILD_VENDOR_PKG
"Build yaml-cpp from source, even if system-installed package is available"
OFF)
find_package(ament_cmake REQUIRED)
set(PACKAGE_VERSION "1.0.0")
macro(build_yaml_cpp)
set(extra_cmake_args)
set(YAML_C_FLAGS ${CMAKE_C_FLAGS})
set(YAML_CXX_FLAGS ${CMAKE_CXX_FLAGS})
if(DEFINED CMAKE_BUILD_TYPE)
list(APPEND extra_cmake_args -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})
endif()
if(NOT WIN32)
list(APPEND YAML_C_FLAGS "-w")
list(APPEND YAML_CXX_FLAGS "-std=c++14 -w")
endif()
list(APPEND extra_cmake_args "-DYAML_CPP_BUILD_TESTS=OFF")
list(APPEND extra_cmake_args "-DYAML_CPP_BUILD_TOOLS=OFF")
list(APPEND extra_cmake_args "-DYAML_CPP_BUILD_CONTRIB=OFF")
list(APPEND extra_cmake_args "-DBUILD_SHARED_LIBS=ON")
list(APPEND extra_cmake_args "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}")
list(APPEND extra_cmake_args "-DCMAKE_C_FLAGS=${YAML_C_FLAGS}")
list(APPEND extra_cmake_args "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}")
list(APPEND extra_cmake_args "-DCMAKE_CXX_FLAGS=${YAML_CXX_FLAGS}")
if(WIN32 AND NOT ${CMAKE_VERBOSE_MAKEFILE})
set(should_log ON) # prevent warnings in Windows CI
else()
set(should_log OFF)
endif()
if(DEFINED CMAKE_TOOLCHAIN_FILE)
list(APPEND extra_cmake_args "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}")
endif()
include(ExternalProject)
# This specific version (past the current latest release of 0.5.3) is required to make
# yaml-cpp relocatable, hopefully it is released again soon.
# See: https://github.com/jbeder/yaml-cpp/pull/538
# Latest release fails to compile on recent visual studio (VS2017 v15.8.1)
# See: https://github.com/jbeder/yaml-cpp/pull/597
ExternalProject_Add(yaml_cpp-0f9a586
URL https://github.com/jbeder/yaml-cpp/archive/0f9a586ca1dc29c2ecb8dd715a315b93e3f40f79.zip
URL_MD5 ec76c27ebd07d5178cbe85b773df8e62
TIMEOUT 600
LOG_CONFIGURE ${should_log}
LOG_BUILD ${should_log}
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/yaml_cpp_install
${extra_cmake_args}
-Wno-dev
)
# The external project will install to the build folder, but we'll install that on make install.
install(
DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/yaml_cpp_install/
DESTINATION
${CMAKE_INSTALL_PREFIX}/opt/yaml_cpp_vendor
USE_SOURCE_PERMISSIONS
)
endmacro()
# NO_CMAKE_PACKAGE_REGISTRY used to avoid finding the library downloaded in WORKSPACE B
# when building workspace A.
# This should only find a system installed yaml-cpp and thus the environment hook isn't needed.
find_package(yaml-cpp 0.6 QUIET NO_CMAKE_PACKAGE_REGISTRY)
if(FORCE_BUILD_VENDOR_PKG OR NOT yaml-cpp_FOUND)
build_yaml_cpp()
if(WIN32)
ament_environment_hooks(env_hook/yaml_cpp_vendor_library_path.bat)
set(ENV_VAR_NAME "PATH")
set(ENV_VAR_VALUE "opt\\yaml_cpp_vendor\\bin")
else()
ament_environment_hooks(env_hook/yaml_cpp_vendor_library_path.sh)
if(APPLE)
set(ENV_VAR_NAME "DYLD_LIBRARY_PATH")
else()
set(ENV_VAR_NAME "LD_LIBRARY_PATH")
endif()
set(ENV_VAR_VALUE "opt/yaml_cpp_vendor/lib")
endif()
ament_environment_hooks(env_hook/yaml_cpp_vendor_library_path.dsv.in)
else()
message(STATUS "Found yaml-cpp ${yaml-cpp_VERSION} in path ${yaml-cpp_CONFIG}")
endif()
ament_package(
CONFIG_EXTRAS "yaml_cpp_vendor-extras.cmake.in"
)