Skip to content

Commit

Permalink
fix /usr/local/lib hack in CMakeLists
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzziqersoftware committed Aug 17, 2024
1 parent edffb78 commit 7b77cc0
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ Makefile
CTestTestFile.cmake
Testing
cmake_install.cmake
phosgConfig.cmake
phosgConfigVersion.cmake
install_manifest.txt
87 changes: 65 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.10)
cmake_minimum_required(VERSION 3.27)




Expand All @@ -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)
Expand All @@ -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
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)

# 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
Expand Down Expand Up @@ -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)
2 changes: 0 additions & 2 deletions phosg-config.cmake

This file was deleted.

3 changes: 3 additions & 0 deletions phosgConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/phosg.cmake")
check_required_components(phosg)

0 comments on commit 7b77cc0

Please sign in to comment.