From 7b77cc0df7e1c6197c9f83bc31956a2bfbd19aef Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Sat, 17 Aug 2024 15:05:40 -0700 Subject: [PATCH] fix /usr/local/lib hack in CMakeLists --- .gitignore | 2 + CMakeLists.txt | 87 +++++++++++++++++++++++++++++++++----------- phosg-config.cmake | 2 - phosgConfig.cmake.in | 3 ++ 4 files changed, 70 insertions(+), 24 deletions(-) delete mode 100644 phosg-config.cmake create mode 100644 phosgConfig.cmake.in diff --git a/.gitignore b/.gitignore index 8a6949f..7dfc74d 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,6 @@ Makefile CTestTestFile.cmake Testing cmake_install.cmake +phosgConfig.cmake +phosgConfigVersion.cmake install_manifest.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 1769f84..1428990 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,5 @@ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.27) + @@ -7,6 +8,8 @@ cmake_minimum_required(VERSION 3.10) set(CMAKE_OSX_ARCHITECTURES arm64;x86_64) project(phosg) +include(GNUInstallDirs) +include(CMakePackageConfigHelpers) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED True) @@ -22,30 +25,32 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_BUILD_TYPE Debug) set(CTEST_OUTPUT_ON_FAILURE ON) -include_directories("/usr/local/include") -link_directories("/usr/local/lib") - # Library and executable definitions add_library( - phosg - src/Arguments.cc - src/Encoding.cc - src/Filesystem.cc - src/Hash.cc - src/Image.cc - src/JSON.cc - src/Network.cc - src/Process.cc - src/Random.cc - src/Strings.cc - src/Time.cc - src/Tools.cc - src/UnitTest.cc + phosg + src/Arguments.cc + src/Encoding.cc + src/Filesystem.cc + src/Hash.cc + src/Image.cc + src/JSON.cc + src/Network.cc + src/Process.cc + src/Random.cc + src/Strings.cc + src/Time.cc + src/Tools.cc + src/UnitTest.cc ) target_link_libraries(phosg pthread z) +target_include_directories( + phosg PUBLIC + "$" + "$" +) # It seems that on some Linux variants (e.g. Raspbian) we also need -latomic, # but this library does not exist on others (e.g. Ubuntu) nor on macOS @@ -89,12 +94,50 @@ endforeach() # Installation configuration +# Package setup +install( + TARGETS phosg + EXPORT phosg + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +) + +# Header files file(GLOB Headers ${CMAKE_SOURCE_DIR}/src/*.hh) -install(TARGETS phosg EXPORT phosg DESTINATION lib) +install(FILES ${Headers} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/phosg) + +# Export definition +install( + EXPORT phosg + FILE phosg.cmake + NAMESPACE phosg:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/phosg +) + +# CMake config files +configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/phosgConfig.cmake.in + "${CMAKE_CURRENT_BINARY_DIR}/phosgConfig.cmake" + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/phosg +) +set(version 0.1) +set_property(TARGET phosg PROPERTY VERSION ${version}) +set_property(TARGET phosg PROPERTY SOVERSION 0) +set_property(TARGET phosg PROPERTY INTERFACE_phosg_MAJOR_VERSION 0) +set_property(TARGET phosg APPEND PROPERTY COMPATIBLE_INTERFACE_STRING phosg_MAJOR_VERSION) +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/phosgConfigVersion.cmake" + VERSION "${version}" + COMPATIBILITY AnyNewerVersion +) +install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/phosgConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/phosgConfigVersion.cmake" + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/phosg +) + +# Executables (separate from package definition) install(TARGETS bindiff DESTINATION bin) install(TARGETS jsonformat DESTINATION bin) install(TARGETS parse-data DESTINATION bin) install(TARGETS phosg-png-conv DESTINATION bin) -install(FILES ${Headers} DESTINATION include/phosg) -install(FILES phosg-config.cmake DESTINATION lib) -install(EXPORT phosg DESTINATION lib) diff --git a/phosg-config.cmake b/phosg-config.cmake deleted file mode 100644 index 148520d..0000000 --- a/phosg-config.cmake +++ /dev/null @@ -1,2 +0,0 @@ -get_filename_component(SELF_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) -include(${SELF_DIR}/phosg.cmake) diff --git a/phosgConfig.cmake.in b/phosgConfig.cmake.in new file mode 100644 index 0000000..b486edc --- /dev/null +++ b/phosgConfig.cmake.in @@ -0,0 +1,3 @@ +@PACKAGE_INIT@ +include("${CMAKE_CURRENT_LIST_DIR}/phosg.cmake") +check_required_components(phosg)