Skip to content

Commit

Permalink
Add generation of pkgconfig file
Browse files Browse the repository at this point in the history
  • Loading branch information
Naoki Shibata committed Sep 21, 2024
1 parent 8e2bd7d commit 4bd5398
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 7 deletions.
33 changes: 30 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ if (NOT EXISTS ${CMAKE_BINARY_DIR}/CMakeCache.txt)
endif()
endif()

include(GNUInstallDirs)

# Include packages

if (NOT CMAKE_CROSSCOMPILING)
Expand Down Expand Up @@ -86,9 +88,6 @@ endif()

find_package(OpenMP)

set(INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/")
set(INSTALL_BINDIR "${INSTALL_PREFIX}bin")

# Detect compiler capabilities

include(CheckCXXSourceCompiles)
Expand Down Expand Up @@ -310,6 +309,34 @@ configure_file("${PROJECT_SOURCE_DIR}/src/include/tlfloat/tlfloatconfig.hpp.in"
configure_file("${PROJECT_SOURCE_DIR}/src/include/detect.h.in"
"${PROJECT_BINARY_DIR}/include/detect.h" @ONLY)

# Install CMake package config

if (FALSE)
# Currently disabled because I still don't fully understand how this works

include(CMakePackageConfigHelpers)

write_basic_package_version_file(
tlfloatConfigVersion.cmake
VERSION "${TLFLOAT_VERSION}"
COMPATIBILITY SameMajorVersion
)

install(
EXPORT tlfloatTargets
FILE tlfloatConfigVersion.cmake
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/tlfloat"
COMPONENT tlfloat_Development
)

install(
EXPORT tlfloatTargets
NAMESPACE tlfloat::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/tlfloat"
COMPONENT tlfloat_Development
)
endif()

#

add_subdirectory("src")
Expand Down
30 changes: 26 additions & 4 deletions src/tlfloat/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if (BUILD_LIBS)

add_library(tlfloat printf.cpp)
target_compile_options(tlfloat PRIVATE ${NOEXCEPT_CXX_FLAGS})
target_link_libraries(tlfloat tlfloat_inline)
target_link_libraries(tlfloat PRIVATE tlfloat_inline)

set(INCLUDEDIR "${PROJECT_SOURCE_DIR}/src/include")
set(VERFILE "${PROJECT_BINARY_DIR}/include/tlfloat/tlfloatconfig.hpp")
Expand All @@ -18,9 +18,10 @@ if (BUILD_LIBS)
PUBLIC_HEADER "${INCLUDEDIR}/tlfloat/bigint.hpp;${INCLUDEDIR}/tlfloat/rpitab.hpp;${INCLUDEDIR}/tlfloat/tlfloat.hpp;${INCLUDEDIR}/tlfloat/tlmath.hpp;${INCLUDEDIR}/tlfloat/tlmathcoef.hpp;${INCLUDEDIR}/tlfloat/tlfloat.h;${VERFILE}"
)
install(
TARGETS tlfloat
TARGETS tlfloat tlfloat_inline
EXPORT tlfloatTargets
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_PREFIX}/include/tlfloat"
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/tlfloat"
COMPONENT tlfloat_Development
)

Expand All @@ -30,9 +31,30 @@ else(BUILD_LIBS)
set(VERFILE "${PROJECT_BINARY_DIR}/include/tlfloat/tlfloatconfig.hpp")
install(
FILES "${INCLUDEDIR}/tlfloat/bigint.hpp" "${INCLUDEDIR}/tlfloat/rpitab.hpp" "${INCLUDEDIR}/tlfloat/tlfloat.hpp" "${INCLUDEDIR}/tlfloat/tlmath.hpp" "${INCLUDEDIR}/tlfloat/tlmathcoef.hpp" "${INCLUDEDIR}/tlfloat/tlfloat.h" "${VERFILE}"
DESTINATION "${CMAKE_INSTALL_PREFIX}/include/tlfloat"
EXPORT tlfloatTargets
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/tlfloat"
)

endif(BUILD_LIBS)

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tlfloat.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/tlfloat.pc" @ONLY)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/tlfloat.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
COMPONENT tlfloat_Development
)

if (FALSE)
# Currently disabled because I still don't fully understand how this works

configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/tlfloatConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/tlfloatConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/tlfloat"
)

install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/tlfloatConfig.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/tlfloat"
COMPONENT tlfloat_Development
)
endif()
9 changes: 9 additions & 0 deletions src/tlfloat/tlfloat.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
prefix=@CMAKE_INSTALL_PREFIX@
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@

Name: TLFloat
Description: C++ template library for floating point operations
Version: @TLFLOAT_VERSION@
Cflags: -I${includedir}
Libs: -L${libdir} -ltlfloat
3 changes: 3 additions & 0 deletions src/tlfloat/tlfloatConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@PACKAGE_INIT@
set(TLFLOAT_INCLUDE_DIR "@CMAKE_INSTALL_PREFIX@/include")
set(TLFLOAT_LIB_DIR "@CMAKE_INSTALL_PREFIX@/lib")

0 comments on commit 4bd5398

Please sign in to comment.