You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

116 lines
4.2 KiB

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -274,16 +274,20 @@ set(_INSTALL_DESTINATIONS
###
### Library
###
-add_library(yaml-cpp ${library_sources})
-set_target_properties(yaml-cpp PROPERTIES
- COMPILE_FLAGS "${yaml_c_flags} ${yaml_cxx_flags}"
-)
-
-set_target_properties(yaml-cpp PROPERTIES
+if(BUILD_SHARED_LIBS)
+ add_library(yaml-cpp SHARED ${library_sources})
+ set_target_properties(yaml-cpp PROPERTIES
VERSION "${YAML_CPP_VERSION}"
SOVERSION "${YAML_CPP_VERSION_MAJOR}.${YAML_CPP_VERSION_MINOR}"
PROJECT_LABEL "yaml-cpp ${LABEL_SUFFIX}"
+ COMPILE_FLAGS "${yaml_c_flags} ${yaml_cxx_flags}"
)
+else()
+ add_library(yaml-cpp STATIC ${library_sources})
+ set_target_properties(yaml-cpp PROPERTIES
+ COMPILE_FLAGS "${yaml_c_flags} ${yaml_cxx_flags}"
+ )
+endif()
if(IPHONE)
set_target_properties(yaml-cpp PROPERTIES
@@ -303,48 +307,56 @@ if(MSVC)
endif()
endif()
-install(TARGETS yaml-cpp EXPORT yaml-cpp-targets ${_INSTALL_DESTINATIONS})
install(
DIRECTORY ${header_directory}
DESTINATION ${INCLUDE_INSTALL_DIR}
FILES_MATCHING PATTERN "*.h"
)
-export(
- TARGETS yaml-cpp
- FILE "${PROJECT_BINARY_DIR}/yaml-cpp-targets.cmake")
-export(PACKAGE yaml-cpp)
-set(EXPORT_TARGETS yaml-cpp CACHE INTERNAL "export targets")
+if(BUILD_SHARED_LIBS)
+ set(YAML_TARGET "yaml-cpp")
+else()
+ set(YAML_TARGET "yaml-cpp-static")
+endif()
+install(TARGETS yaml-cpp EXPORT ${YAML_TARGET}-targets ${_INSTALL_DESTINATIONS})
+export(TARGETS yaml-cpp
+ FILE "${PROJECT_BINARY_DIR}/${YAML_TARGET}-targets.cmake")
+set(EXPORT_TARGETS yaml-cpp CACHE INTERNAL "export targets")
set(CONFIG_INCLUDE_DIRS "${YAML_CPP_SOURCE_DIR}/include")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/yaml-cpp-config.cmake.in
- "${PROJECT_BINARY_DIR}/yaml-cpp-config.cmake" @ONLY)
+ "${PROJECT_BINARY_DIR}/${YAML_TARGET}-config.cmake" @ONLY)
+if(NOT INSTALL_CMAKE_DIR)
if(WIN32 AND NOT CYGWIN)
set(INSTALL_CMAKE_DIR CMake)
else()
- set(INSTALL_CMAKE_DIR ${LIB_INSTALL_DIR}/cmake/yaml-cpp)
+ set(INSTALL_CMAKE_DIR ${LIB_INSTALL_DIR}/cmake/)
+endif()
endif()
file(RELATIVE_PATH REL_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/${INSTALL_CMAKE_DIR}" "${CMAKE_INSTALL_PREFIX}/${INCLUDE_INSTALL_ROOT_DIR}")
set(CONFIG_INCLUDE_DIRS "\${YAML_CPP_CMAKE_DIR}/${REL_INCLUDE_DIR}")
-configure_file(${CMAKE_CURRENT_SOURCE_DIR}/yaml-cpp-config.cmake.in
- "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/yaml-cpp-config.cmake" @ONLY)
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/yaml-cpp-config.cmake.in
+ "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${YAML_TARGET}-config.cmake" @ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/yaml-cpp-config-version.cmake.in
- "${PROJECT_BINARY_DIR}/yaml-cpp-config-version.cmake" @ONLY)
-
+ "${PROJECT_BINARY_DIR}/${YAML_TARGET}-config-version.cmake" @ONLY)
install(FILES
- "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/yaml-cpp-config.cmake"
- "${PROJECT_BINARY_DIR}/yaml-cpp-config-version.cmake"
- DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev)
-install(EXPORT yaml-cpp-targets DESTINATION ${INSTALL_CMAKE_DIR})
+ "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${YAML_TARGET}-config.cmake"
+ "${PROJECT_BINARY_DIR}/${YAML_TARGET}-config-version.cmake"
+ DESTINATION "${INSTALL_CMAKE_DIR}${YAML_TARGET}" COMPONENT dev)
+install(EXPORT ${YAML_TARGET}-targets DESTINATION ${INSTALL_CMAKE_DIR}${YAML_TARGET})
if(UNIX)
- set(PC_FILE ${CMAKE_BINARY_DIR}/yaml-cpp.pc)
- configure_file("yaml-cpp.pc.cmake" ${PC_FILE} @ONLY)
- install(FILES ${PC_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+if(BUILD_SHARED_LIBS)
+ set(PC_FILE ${CMAKE_BINARY_DIR}/yaml-cpp.pc)
+else()
+ set(PC_FILE ${CMAKE_BINARY_DIR}/yaml-cpp-static.pc)
endif()
+configure_file("yaml-cpp.pc.cmake" ${PC_FILE} @ONLY)
+install(FILES ${PC_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+endif(UNIX)
###
--- a/yaml-cpp-config.cmake.in
+++ b/yaml-cpp-config.cmake.in
@@ -8,7 +8,7 @@ get_filename_component(YAML_CPP_CMAKE_DI
set(YAML_CPP_INCLUDE_DIR "@CONFIG_INCLUDE_DIRS@")
# Our library dependencies (contains definitions for IMPORTED targets)
-include("${YAML_CPP_CMAKE_DIR}/yaml-cpp-targets.cmake")
+include("${YAML_CPP_CMAKE_DIR}/@YAML_TARGET@-targets.cmake")
# These are IMPORTED targets created by yaml-cpp-targets.cmake
set(YAML_CPP_LIBRARIES "@EXPORT_TARGETS@")