From d0b5fda4a292018ad6c2e492e6ac385fc6795322 Mon Sep 17 00:00:00 2001 From: maz-1 Date: Sun, 13 Mar 2022 09:56:58 +0800 Subject: [PATCH 1/2] export package to cmake build system --- sources/CMakeLists.txt | 42 ++++++++++++++++++++++++++++++++-- sources/citygmlConfig.cmake.in | 9 ++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 sources/citygmlConfig.cmake.in diff --git a/sources/CMakeLists.txt b/sources/CMakeLists.txt index e97fa531..f9a1c9ad 100644 --- a/sources/CMakeLists.txt +++ b/sources/CMakeLists.txt @@ -205,7 +205,10 @@ generate_export_header(citygml EXPORT_MACRO_NAME LIBCITYGML_EXPORT EXPORT_FILE_NAME ${EXPORT_HEADER_FILE_NAME}) -TARGET_LINK_LIBRARIES( ${target} ${XERCESC_LIBRARIES} ${OPENGL_LIBRARIES} ${GDAL_LIBRARY} ) +TARGET_LINK_LIBRARIES( ${target} PUBLIC ${XERCESC_LIBRARIES} ${OPENGL_LIBRARIES} ) +if(GDAL_LIBRARY) + TARGET_LINK_LIBRARIES( ${target} PUBLIC ${GDAL_LIBRARY} ) +endif(GDAL_LIBRARY) set_target_properties( ${target} PROPERTIES VERSION ${META_VERSION} @@ -222,19 +225,49 @@ if(NOT DEFINED INCLUDE_INSTALL_DIR) set(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include/citygml") endif(NOT DEFINED INCLUDE_INSTALL_DIR) +if(WIN32) + set(CONFIG_INSTALL_DIR "cmake") +else() + set(CONFIG_INSTALL_DIR "${LIB_INSTALL_DIR}/cmake/citygml") +endif() + INSTALL( TARGETS ${target} + EXPORT citygmlConfigInternal RUNTIME DESTINATION ${BIN_INSTALL_DIR} LIBRARY DESTINATION ${LIB_INSTALL_DIR} ARCHIVE DESTINATION ${LIB_INSTALL_DIR} + COMPONENT "runtime" +) +INSTALL( + EXPORT citygmlConfigInternal + DESTINATION "${CONFIG_INSTALL_DIR}" + NAMESPACE "citygml::" + COMPONENT "development" ) +include(CMakePackageConfigHelpers) +configure_package_config_file( + "${CMAKE_CURRENT_SOURCE_DIR}/citygmlConfig.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/citygmlConfig.cmake" + INSTALL_DESTINATION "${CONFIG_INSTALL_DIR}") +write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/citygmlConfigVersion.cmake + VERSION "${META_VERSION}" + COMPATIBILITY SameMajorVersion) +INSTALL( + FILES ${CMAKE_CURRENT_BINARY_DIR}/citygmlConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/citygmlConfigVersion.cmake + DESTINATION "${CONFIG_INSTALL_DIR}" + COMPONENT "development" +) # FIXME: Do not run for OS X framework INSTALL( FILES ${PUBLIC_HEADER} DESTINATION ${INCLUDE_INSTALL_DIR} + COMPONENT "development" ) INSTALL( @@ -242,6 +275,7 @@ INSTALL( ${EXPORT_HEADER_FILE_NAME} DESTINATION ${INCLUDE_INSTALL_DIR} + COMPONENT "development" ) if (LIBCITYGML_DEBUG_POSTFIX AND CMAKE_BUILD_TYPE STREQUAL "Debug") @@ -252,5 +286,9 @@ endif() configure_file(citygml.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/citygml.pc) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/citygml.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) +INSTALL( + FILES ${CMAKE_CURRENT_BINARY_DIR}/citygml.pc + DESTINATION ${LIB_INSTALL_DIR}/pkgconfig + COMPONENT "development" +) diff --git a/sources/citygmlConfig.cmake.in b/sources/citygmlConfig.cmake.in new file mode 100644 index 00000000..8bd31331 --- /dev/null +++ b/sources/citygmlConfig.cmake.in @@ -0,0 +1,9 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/citygmlConfigInternal.cmake") + +set(CITYGML_ROOT_DIR ${PACKAGE_PREFIX_DIR}) +set(CITYGML_LIBRARIES citygml::citygml) +set(CITYGML_DYNAMIC @LIBCITYGML_DYNAMIC@) +get_property(CITYGML_INCLUDE_DIRS TARGET citygml::citygml PROPERTY INTERFACE_INCLUDE_DIRECTORIES) +set(CITYGML_LIBRARY_DIRS "") From 0d7337f2a4f7c233be830455da60048dcc747150 Mon Sep 17 00:00:00 2001 From: maz-1 Date: Sun, 13 Mar 2022 20:48:06 +0800 Subject: [PATCH 2/2] fix pkg-config requires --- sources/CMakeLists.txt | 10 ++++++++-- sources/citygml.pc.cmake | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/sources/CMakeLists.txt b/sources/CMakeLists.txt index f9a1c9ad..520afe4f 100644 --- a/sources/CMakeLists.txt +++ b/sources/CMakeLists.txt @@ -206,9 +206,9 @@ generate_export_header(citygml EXPORT_FILE_NAME ${EXPORT_HEADER_FILE_NAME}) TARGET_LINK_LIBRARIES( ${target} PUBLIC ${XERCESC_LIBRARIES} ${OPENGL_LIBRARIES} ) -if(GDAL_LIBRARY) +if(LIBCITYGML_USE_GDAL) TARGET_LINK_LIBRARIES( ${target} PUBLIC ${GDAL_LIBRARY} ) -endif(GDAL_LIBRARY) +endif(LIBCITYGML_USE_GDAL) set_target_properties( ${target} PROPERTIES VERSION ${META_VERSION} @@ -284,6 +284,12 @@ else() set(LIBCITYGML_POSTFIX "") endif() +set(PKG_CONFIG_REQUIRES "xerces-c glu") + +if (LIBCITYGML_USE_GDAL) + set(PKG_CONFIG_REQUIRES "${PKG_CONFIG_REQUIRES} gdal") +endif() + configure_file(citygml.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/citygml.pc) INSTALL( diff --git a/sources/citygml.pc.cmake b/sources/citygml.pc.cmake index bedc052a..0859b276 100644 --- a/sources/citygml.pc.cmake +++ b/sources/citygml.pc.cmake @@ -5,7 +5,7 @@ includedir=${INCLUDE_INSTALL_DIR} Name: citygml Description: Read and Write CityGML files -Requires: libxml-2.0 glu +Requires: ${PKG_CONFIG_REQUIRES} Version: ${META_VERSION} Libs: -L${LIB_INSTALL_DIR} -lcitygml${LIBCITYGML_POSTFIX} Cflags: -I${INCLUDE_INSTALL_DIR}