From c7de8a8af33e096d55e279a325d074e3bcf9f471 Mon Sep 17 00:00:00 2001 From: Stefan Goetschi Date: Thu, 1 Aug 2024 09:26:15 +0200 Subject: [PATCH 1/5] Make xerces-c, opengl, and gdal private libraries. If these are public libraries a client build system needs to link to them again even libcitygml was compiled into a self-contained dynamic library. --- sources/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sources/CMakeLists.txt b/sources/CMakeLists.txt index 8a1c8f84..87bdd4eb 100644 --- a/sources/CMakeLists.txt +++ b/sources/CMakeLists.txt @@ -231,16 +231,16 @@ generate_export_header(citygml EXPORT_FILE_NAME ${EXPORT_HEADER_FILE_NAME}) if(XercesC_FOUND) - TARGET_LINK_LIBRARIES( ${target} PUBLIC XercesC::XercesC) + TARGET_LINK_LIBRARIES( ${target} PRIVATE XercesC::XercesC) else(XercesC_FOUND) - TARGET_LINK_LIBRARIES( ${target} PUBLIC ${XERCESC_LIBRARIES} ) + TARGET_LINK_LIBRARIES( ${target} PRIVATE ${XERCESC_LIBRARIES} ) endif(XercesC_FOUND) if(LIBCITYGML_USE_OPENGL) - TARGET_LINK_LIBRARIES( ${target} PUBLIC ${OPENGL_LIBRARIES} ) + TARGET_LINK_LIBRARIES( ${target} PRIVATE ${OPENGL_LIBRARIES} ) endif(LIBCITYGML_USE_OPENGL) if(LIBCITYGML_USE_GDAL) - TARGET_LINK_LIBRARIES( ${target} PUBLIC ${GDAL_LIBRARY} ) + TARGET_LINK_LIBRARIES( ${target} PRIVATE ${GDAL_LIBRARY} ) endif(LIBCITYGML_USE_GDAL) set_target_properties( ${target} PROPERTIES From 64061d1d297434aad4009e1fa711ea4f6bab7706 Mon Sep 17 00:00:00 2001 From: Stefan Goetschi Date: Thu, 1 Aug 2024 09:32:54 +0200 Subject: [PATCH 2/5] Use relative bin and lib install paths. CMake's install will combine the relative path with the absolute path passed via CMAKE_INSTALL_PREFIX. This shouldn't be handled in CMakeLists.txt files. The state before resulted in absolute paths being used in citygmlConfig.cmake. That prohibits prebuilding the library and deploying it on other machines/paths. --- CMakeLists.txt | 6 ------ sources/CMakeLists.txt | 16 +++++----------- sources/citygml.pc.cmake | 6 +++--- test/CMakeLists.txt | 6 +----- 4 files changed, 9 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b2c00581..1a93bbe5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,12 +87,6 @@ SET(OUTPUT_LIBDIR ${PROJECT_BINARY_DIR}/lib) MAKE_DIRECTORY(${OUTPUT_LIBDIR}) SET(LIBRARY_OUTPUT_PATH ${OUTPUT_LIBDIR}) -if(NOT DEFINED BIN_INSTALL_DIR) - set(BIN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/bin") -endif(NOT DEFINED BIN_INSTALL_DIR) -if(NOT DEFINED LIB_INSTALL_DIR) - set(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib") -endif(NOT DEFINED LIB_INSTALL_DIR) if(NOT DEFINED DATA_INSTALL_DIR) set(DATA_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share") endif(NOT DEFINED DATA_INSTALL_DIR) diff --git a/sources/CMakeLists.txt b/sources/CMakeLists.txt index 87bdd4eb..c9ff987b 100644 --- a/sources/CMakeLists.txt +++ b/sources/CMakeLists.txt @@ -248,12 +248,6 @@ set_target_properties( ${target} PROPERTIES SOVERSION ${META_VERSION_MAJOR} ) -if(NOT DEFINED BIN_INSTALL_DIR) - set(BIN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/bin") -endif(NOT DEFINED BIN_INSTALL_DIR) -if(NOT DEFINED LIB_INSTALL_DIR) - set(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib") -endif(NOT DEFINED LIB_INSTALL_DIR) if(NOT DEFINED INCLUDE_INSTALL_DIR) set(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include/citygml") endif(NOT DEFINED INCLUDE_INSTALL_DIR) @@ -261,15 +255,15 @@ endif(NOT DEFINED INCLUDE_INSTALL_DIR) if(WIN32) set(CONFIG_INSTALL_DIR "cmake") else() - set(CONFIG_INSTALL_DIR "${LIB_INSTALL_DIR}/cmake/citygml") + set(CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/citygml") endif() INSTALL( TARGETS ${target} EXPORT citygmlConfigInternal - RUNTIME DESTINATION ${BIN_INSTALL_DIR} - LIBRARY DESTINATION ${LIB_INSTALL_DIR} - ARCHIVE DESTINATION ${LIB_INSTALL_DIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT "runtime" ) INSTALL( @@ -331,7 +325,7 @@ configure_file(citygml.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/citygml.pc) INSTALL( FILES ${CMAKE_CURRENT_BINARY_DIR}/citygml.pc - DESTINATION ${LIB_INSTALL_DIR}/pkgconfig + DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/pkgconfig COMPONENT "development" ) diff --git a/sources/citygml.pc.cmake b/sources/citygml.pc.cmake index 0859b276..52e8d1b9 100644 --- a/sources/citygml.pc.cmake +++ b/sources/citygml.pc.cmake @@ -1,11 +1,11 @@ prefix=${CMAKE_INSTALL_PREFIX} -exec_prefix=${BIN_INSTALL_DIR} -libdir=${LIB_INSTALL_DIR} +exec_prefix=${CMAKE_INSTALL_BINDIR} +libdir=${CMAKE_INSTALL_LIBDIR} includedir=${INCLUDE_INSTALL_DIR} Name: citygml Description: Read and Write CityGML files Requires: ${PKG_CONFIG_REQUIRES} Version: ${META_VERSION} -Libs: -L${LIB_INSTALL_DIR} -lcitygml${LIBCITYGML_POSTFIX} +Libs: -L${CMAKE_INSTALL_LIBDIR} -lcitygml${LIBCITYGML_POSTFIX} Cflags: -I${INCLUDE_INSTALL_DIR} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a9b7aaf7..85ce5053 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -33,11 +33,7 @@ IF(LIBCITYGML_USE_OPENGL) TARGET_LINK_LIBRARIES( citygmltest citygml ${OPENGL_LIBRARIES} ) ENDIF(LIBCITYGML_USE_OPENGL) -if(NOT DEFINED BIN_INSTALL_DIR) - set(BIN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/bin") -endif(NOT DEFINED BIN_INSTALL_DIR) - -install(TARGETS citygmltest RUNTIME DESTINATION ${BIN_INSTALL_DIR}) +install(TARGETS citygmltest RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) add_test(NAME berlin_open_data_sample_data COMMAND citygmltest ../../data/berlin_open_data_sample_data.citygml) From 4af02e598cfcad022be405dfde4c4e8aeed449a7 Mon Sep 17 00:00:00 2001 From: Stefan Goetschi Date: Sun, 15 Sep 2024 15:30:02 +0200 Subject: [PATCH 3/5] Include gnu install dirs. It's unclear why the lib install folders worked without this before. But now the CMake files get correctly installed. --- sources/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/sources/CMakeLists.txt b/sources/CMakeLists.txt index c9ff987b..a3be7c79 100644 --- a/sources/CMakeLists.txt +++ b/sources/CMakeLists.txt @@ -1,4 +1,5 @@ include(GenerateExportHeader) +include(GNUInstallDirs) IF (NOT DEFINED CMAKE_MODULE_PATH) GET_FILENAME_COMPONENT(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../CMakeModules" ABSOLUTE) From abab5566f42dead14047ae65dbec46ea7dc3e452 Mon Sep 17 00:00:00 2001 From: Stefan Goetschi Date: Mon, 5 Aug 2024 23:21:58 +0200 Subject: [PATCH 4/5] Let citygmlConfig.cmake also define include dirs. With this a library user can just use target_link_libraries(citygml::citygml) and the include directories are set up automatically. --- CMakeLists.txt | 8 +++++--- sources/CMakeLists.txt | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a93bbe5..e38d4138 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,12 +87,14 @@ SET(OUTPUT_LIBDIR ${PROJECT_BINARY_DIR}/lib) MAKE_DIRECTORY(${OUTPUT_LIBDIR}) SET(LIBRARY_OUTPUT_PATH ${OUTPUT_LIBDIR}) +if(NOT DEFINED INCLUDE_INSTALL_DIR) + set(INCLUDE_INSTALL_DIR "include") +endif(NOT DEFINED INCLUDE_INSTALL_DIR) +set(INCLUDE_INSTALL_CITYGML_DIR "${CMAKE_INSTALL_PREFIX}/${INCLUDE_INSTALL_DIR}/citygml") + if(NOT DEFINED DATA_INSTALL_DIR) set(DATA_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share") endif(NOT DEFINED DATA_INSTALL_DIR) -if(NOT DEFINED INCLUDE_INSTALL_DIR) - set(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include/citygml") -endif(NOT DEFINED INCLUDE_INSTALL_DIR) if(NOT DEFINED MAN_INSTALL_DIR) set(MAN_INSTALL_DIR "${DATA_INSTALL_DIR}/man") endif(NOT DEFINED MAN_INSTALL_DIR) diff --git a/sources/CMakeLists.txt b/sources/CMakeLists.txt index a3be7c79..26365953 100644 --- a/sources/CMakeLists.txt +++ b/sources/CMakeLists.txt @@ -250,8 +250,9 @@ set_target_properties( ${target} PROPERTIES ) if(NOT DEFINED INCLUDE_INSTALL_DIR) - set(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include/citygml") + set(INCLUDE_INSTALL_DIR "include") endif(NOT DEFINED INCLUDE_INSTALL_DIR) +set(INCLUDE_INSTALL_CITYGML_DIR "${CMAKE_INSTALL_PREFIX}/${INCLUDE_INSTALL_DIR}/citygml") if(WIN32) set(CONFIG_INSTALL_DIR "cmake") @@ -265,6 +266,7 @@ INSTALL( RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + INCLUDES DESTINATION ${INCLUDE_INSTALL_DIR} COMPONENT "runtime" ) INSTALL( @@ -294,7 +296,7 @@ INSTALL( INSTALL( FILES ${PUBLIC_HEADER} - DESTINATION ${INCLUDE_INSTALL_DIR} + DESTINATION ${INCLUDE_INSTALL_CITYGML_DIR} COMPONENT "development" ) @@ -302,7 +304,7 @@ INSTALL( FILES ${EXPORT_HEADER_FILE_NAME} DESTINATION - ${INCLUDE_INSTALL_DIR} + ${INCLUDE_INSTALL_CITYGML_DIR} COMPONENT "development" ) From c657724e7a473c0c8f8dee2cf03a13344e68fcfc Mon Sep 17 00:00:00 2001 From: Stefan Goetschi Date: Wed, 7 Aug 2024 22:53:10 +0200 Subject: [PATCH 5/5] Move Component config before others to fix include folders. When it's at the end CMake treats and as additional include directories when generating the citygmlConfigInternal.cmake file. This is clearly wrong. --- sources/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/CMakeLists.txt b/sources/CMakeLists.txt index 26365953..7a7e158e 100644 --- a/sources/CMakeLists.txt +++ b/sources/CMakeLists.txt @@ -262,12 +262,12 @@ endif() INSTALL( TARGETS ${target} + COMPONENT "runtime" EXPORT citygmlConfigInternal RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} INCLUDES DESTINATION ${INCLUDE_INSTALL_DIR} - COMPONENT "runtime" ) INSTALL( EXPORT citygmlConfigInternal