Fixes improperly generated cmake config files, RHBZ#1558637.

This commit is contained in:
Richard Shaw 2018-04-09 07:16:06 -05:00
parent ac7b8cfffb
commit 5be39b2a2f
3 changed files with 73 additions and 77 deletions

View File

@ -0,0 +1,12 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -335,8 +335,7 @@ else()
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}")
+set(CONFIG_INCLUDE_DIRS "${CMAKE_INSTALL_PREFIX}/${INCLUDE_INSTALL_DIR}")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/yaml-cpp-config.cmake.in
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${YAML_TARGET}-config.cmake" @ONLY)

View File

@ -1,18 +1,6 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -47,6 +47,11 @@ option(YAML_CPP_BUILD_CONTRIB "Enable co
# see http://www.cmake.org/cmake/help/cmake2.6docs.html#variable:BUILD_SHARED_LIBS
# http://www.cmake.org/cmake/help/cmake2.6docs.html#command:add_library
option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF)
+option(BUILD_STATIC_LIBS "Build Static Libraries" ON)
+
+if(NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS)
+ message(FATAL_ERROR "At least one library must be built.")
+endif()
# --> Apple
option(APPLE_UNIVERSAL_BIN "Apple: Build universal binary" OFF)
@@ -274,16 +279,24 @@ set(_INSTALL_DESTINATIONS
@@ -274,16 +274,20 @@ set(_INSTALL_DESTINATIONS
###
### Library
###
@ -20,30 +8,26 @@
-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
+ COMPILE_FLAGS "${yaml_c_flags} ${yaml_cxx_flags}"
+ )
-set_target_properties(yaml-cpp PROPERTIES
+ 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}"
-)
+ )
+endif()
+if(BUILD_STATIC_LIBS)
+ add_library(yaml-cpp-static STATIC ${library_sources})
+ set_target_properties(yaml-cpp-static PROPERTIES
+ COMPILE_FLAGS "${yaml_c_flags} ${yaml_cxx_flags}"
+ OUTPUT_NAME yaml-cpp)
)
+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 +316,70 @@ if(MSVC)
@@ -303,48 +307,56 @@ if(MSVC)
endif()
endif()
@ -59,30 +43,20 @@
- FILE "${PROJECT_BINARY_DIR}/yaml-cpp-targets.cmake")
-export(PACKAGE yaml-cpp)
-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)
+if(BUILD_SHARED_LIBS)
+ install(TARGETS yaml-cpp EXPORT yaml-cpp-targets ${_INSTALL_DESTINATIONS})
+ list(APPEND YAML_TARGETS "yaml-cpp")
+ list(APPEND EXPORT_TARGETS "yaml-cpp-targets")
+ set(YAML_TARGET "yaml-cpp")
+else()
+ set(YAML_TARGET "yaml-cpp-static")
+endif()
+if(BUILD_STATIC_LIBS)
+ install(TARGETS yaml-cpp-static EXPORT yaml-cpp-static-targets ${_INSTALL_DESTINATIONS})
+ list(APPEND YAML_TARGETS "yaml-cpp-static")
+ list(APPEND EXPORT_TARGETS "yaml-cpp-static-targets")
+endif()
+
+foreach(YAML_TARGET ${YAML_TARGETS})
+ export(TARGETS ${YAML_TARGET}
+ FILE "${PROJECT_BINARY_DIR}/${YAML_TARGET}-targets.cmake")
+ export(PACKAGE yaml-cpp)
+ set(EXPORT_TARGETS ${YAML_TARGET} 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_TARGET}-config.cmake" @ONLY)
+endforeach()
+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)
@ -98,41 +72,33 @@
-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-version.cmake.in
+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)
-
-install(FILES
+ "${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})
+foreach(YAML_TARGET ${YAML_TARGETS})
+ 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_TARGET}-config-version.cmake" @ONLY)
+
+ install(FILES
+ "${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})
+endforeach()
+ "${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)
+ list(APPEND PC_FILES ${CMAKE_BINARY_DIR}/yaml-cpp.pc)
+endif()
+if(BUILD_STATIC_LIBS)
+ list(APPEND PC_FILES ${CMAKE_BINARY_DIR}/yaml-cpp-static.pc)
+endif()
+foreach(PC_FILE ${PC_FILES})
configure_file("yaml-cpp.pc.cmake" ${PC_FILE} @ONLY)
install(FILES ${PC_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
-endif()
+endforeach()
+ 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)

View File

@ -2,7 +2,7 @@
Name: yaml-cpp
Version: 0.6.1
Release: 1%{?dist}
Release: 2%{?dist}
Summary: A YAML parser and emitter for C++
Group: Development/Libraries
License: MIT
@ -10,6 +10,7 @@ URL: https://github.com/jbeder/yaml-cpp
Source0: https://github.com/jbeder/yaml-cpp/archive/%{name}-%{version}.tar.gz
Patch0: yaml-cpp-static.patch
Patch1: yaml-cpp-include_dir.patch
BuildRequires: cmake gcc gcc-c++
@ -45,17 +46,31 @@ The %{name}-static package contains the static library for %{name}.
%build
# ask cmake to not strip binaries
rm -rf build_shared && mkdir build_shared
rm -rf build_static && mkdir build_static
pushd build_shared
%cmake -DYAML_CPP_BUILD_TOOLS=OFF \
-DBUILD_SHARED_LIBS=ON \
-DBUILD_STATIC_LIBS=ON \
-DYAML_CPP_BUILD_TESTS=OFF \
./
../
%make_build
popd
pushd build_static
%cmake -DYAML_CPP_BUILD_TOOLS=OFF \
-DBUILD_SHARED_LIBS=OFF \
-DYAML_CPP_BUILD_TESTS=OFF \
../
%make_build
%install
pushd build_shared
%make_install
popd
pushd build_static
%make_install yaml-cpp
%post -p /sbin/ldconfig
@ -82,6 +97,9 @@ The %{name}-static package contains the static library for %{name}.
%changelog
* Mon Apr 09 2018 Richard Shaw <hobbes1069@gmail.com> - 0.6.1-2
- Fixes improperly generated cmake config files, RHBZ#1558637.
* Sun Feb 18 2018 Richard Shaw <hobbes1069@gmail.com> - 0.6.1-1
- Update to 0.6.1.