Skip to content

Commit

Permalink
add CMake package config
Browse files Browse the repository at this point in the history
  • Loading branch information
KedoKudo committed Aug 26, 2024
1 parent 1324c38 commit 8ca0a0e
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 14 deletions.
39 changes: 29 additions & 10 deletions sophiread/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

include(GNUInstallDirs)

set(CMAKE_CXX_STANDARD 20)
# set(CMAKE_AUTOMOC ON) # for meta object compiler, needed for Qt5
set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib")
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

# Dependencies
find_package(Eigen3 REQUIRED)
Expand All @@ -35,7 +39,6 @@ find_package(TBB REQUIRED)
find_package(TIFF REQUIRED)
find_package(spdlog 1.8.0 REQUIRED)
find_package(fmt 7.0.0 REQUIRED)
# find_package(Qt5 COMPONENTS Widgets REQUIRED)

# Testing setup
enable_testing()
Expand All @@ -54,19 +57,35 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
add_compile_options(-march=native -ffast-math -pthread -Wall -Wextra)
endif()

# Add Sophiread library NOTE: this will take care of the testing as well
# add_subdirectory(SophireadLib)

# Add FastSophiread library
add_subdirectory(FastSophiread)

# Add Sophiread command line interface
add_subdirectory(SophireadCLI)

# Add Sophiread stream command line interface
# add_subdirectory(SophireadStreamCLI)
# ----------------- PACKAGE CONFIGURATION ----------------- #

# Export targets from subdirectories
install(
EXPORT sophireadTargets
FILE sophireadTargets.cmake
NAMESPACE sophiread::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/sophiread)

# Generate and install the sophireadConfig.cmake and
# sophireadConfigVersion.cmake files
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/sophireadConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion)

configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/sophireadConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/sophireadConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/sophiread)

# Add Sophiread GUI application add_subdirectory(SophireadGUI)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/sophireadConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/sophireadConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/sophiread)

# ----------------- DOXYGEN ----------------- #
find_package(Doxygen)
Expand Down
17 changes: 16 additions & 1 deletion sophiread/FastSophiread/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,25 @@ set(SRC_FAST_FILES src/abs.cpp src/centroid.cpp src/disk_io.cpp
add_library(FastSophiread ${SRC_FAST_FILES})
target_include_directories(
FastSophiread
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include $ENV{CONDA_PREFIX}/include
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include> $ENV{CONDA_PREFIX}/include
${EIGEN3_INCLUDE_DIR} ${HDF5_INCLUDE_DIRS})
target_link_directories(FastSophiread PRIVATE $ENV{CONDA_PREFIX}/lib)

# Install the library
install(
TARGETS FastSophiread
EXPORT sophireadTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

# Install the headers
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

# ----------------- TESTS ----------------- #
function(add_sophiread_test test_name)
add_executable(${test_name} tests/test_${test_name}.cpp)
Expand Down
13 changes: 12 additions & 1 deletion sophiread/SophireadCLI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
"/usr/local"
CACHE PATH "Default install prefix" FORCE)
endif()
install(TARGETS Sophiread RUNTIME DESTINATION bin)

# Install executables
install(
TARGETS Sophiread venus_auto_reducer
EXPORT sophireadTargets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

# Install the headers
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

# Set up packaging (optional)
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
include(CPack)
7 changes: 7 additions & 0 deletions sophiread/cmake/sophireadConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/sophireadTargets.cmake")

# Optionally, include additional paths or variables
set(SOPHIREAD_INCLUDE_DIRS "@CMAKE_INSTALL_FULL_INCLUDEDIR@")
set(SOPHIREAD_LIBRARIES sophiread::FastSophiread)
4 changes: 2 additions & 2 deletions sophiread/include/version.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**version.h
*
* Copyright 2023.
* Copyright 2024.
*/

#ifndef VERSION_H
Expand All @@ -12,7 +12,7 @@

// Version number
#define VERSION_MAJOR 2
#define VERSION_MINOR 0
#define VERSION_MINOR 3
#define VERSION_PATCH 0

// Version number final
Expand Down

0 comments on commit 8ca0a0e

Please sign in to comment.