Skip to content

Commit 6095dd1

Browse files
MJC598ddbaptiste
andauthored
[Feature] CMake Building and Packaging (#114)
* Updating the CMake build for cleaner interpretation * more updates for cmake in preparation for cpack * Updating for debian and tgz generator packaging * removing commented code * bumping version with build * Updating CMake to include the debian installation * Apply suggestions from code review Co-authored-by: Dimitri Baptiste <55843498+ddbaptiste@users.noreply.github.com> * Addressing test based PR comments * Addressing final PR comment * Hoping this fixes the weird comment? --------- Co-authored-by: Dimitri Baptiste <55843498+ddbaptiste@users.noreply.github.com>
1 parent d4bce9c commit 6095dd1

16 files changed

Lines changed: 214 additions & 232 deletions

CMakeLists.txt

Lines changed: 54 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,36 @@
11
cmake_minimum_required(VERSION 3.27)
2-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
3-
4-
include(utils)
2+
set(PRIVATE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
3+
include(${PRIVATE_MODULE_PATH}/utils.cmake)
54
respond_extract_version()
65

76
project(respond VERSION ${RESPOND_VERSION} LANGUAGES CXX)
87

98
message(STATUS "Build respond: ${RESPOND_VERSION}")
109

11-
include(GNUInstallDirs)
12-
13-
# ---------------------------------------------------------------------------------------
10+
#-------------------------------------------------------------------------------
1411
# Set default build to release
15-
# ---------------------------------------------------------------------------------------
12+
#-------------------------------------------------------------------------------
1613
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
1714
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose Release or Debug" FORCE)
1815
endif()
1916

20-
# ---------------------------------------------------------------------------------------
17+
#-------------------------------------------------------------------------------
2118
# Compiler config
22-
# ---------------------------------------------------------------------------------------
19+
#-------------------------------------------------------------------------------
2320
set(CMAKE_CXX_STANDARD 20)
2421
set(CMAKE_CXX_STANDARD_REQUIRED ON)
2522

26-
# ---------------------------------------------------------------------------------------
23+
#-------------------------------------------------------------------------------
2724
# Windows CXX Extensions
28-
# ---------------------------------------------------------------------------------------
25+
#-------------------------------------------------------------------------------
2926
set(CMAKE_CXX_EXTENSIONS OFF)
3027
if(CMAKE_SYSTEM_NAME MATCHES "CYGWIN" OR CMAKE_SYSTEM_NAME MATCHES "MSYS" OR CMAKE_SYSTEM_NAME MATCHES "MINGW")
3128
set(CMAKE_CXX_EXTENSIONS ON)
3229
endif()
3330

34-
# ---------------------------------------------------------------------------------------
31+
#-------------------------------------------------------------------------------
3532
# Set RESPOND_MASTER_PROJECT to ON if we are building respond directly
36-
# ---------------------------------------------------------------------------------------
33+
#-------------------------------------------------------------------------------
3734
if(NOT DEFINED RESPOND_MASTER_PROJECT)
3835
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
3936
set(RESPOND_MASTER_PROJECT ON)
@@ -42,82 +39,68 @@ if(NOT DEFINED RESPOND_MASTER_PROJECT)
4239
endif()
4340
endif()
4441

45-
# ---------------------------------------------------------------------------------------
42+
#-------------------------------------------------------------------------------
4643
# Set all default options
47-
# ---------------------------------------------------------------------------------------
48-
include(options)
44+
#-------------------------------------------------------------------------------
45+
include(${PRIVATE_MODULE_PATH}/options.cmake)
4946

50-
# ---------------------------------------------------------------------------------------
47+
#-------------------------------------------------------------------------------
5148
# Set position independent code
52-
# ---------------------------------------------------------------------------------------
49+
#-------------------------------------------------------------------------------
5350
if(RESPOND_BUILD_PIC)
5451
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
5552
endif()
5653

57-
# ---------------------------------------------------------------------------------------
54+
#-------------------------------------------------------------------------------
5855
# Building the Library
59-
# ---------------------------------------------------------------------------------------
60-
set(RESPOND_SRCS
61-
src/markov.cpp
62-
src/logging.cpp
63-
)
56+
#-------------------------------------------------------------------------------
57+
add_library(respond_model)
58+
add_library(respond::respond_model ALIAS respond_model)
6459

65-
if(RESPOND_BUILD_SHARED_LIBS)
66-
if(WIN32)
67-
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc @ONLY)
68-
list(APPEND RESPOND_SRCS ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
69-
endif()
70-
add_library(respond SHARED ${RESPOND_SRCS} ${RESPOND_ALL_HEADERS})
71-
target_compile_definitions(respond PUBLIC RESPOND_SHARED_LIB)
72-
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
73-
target_compile_options(respond PUBLIC $<$<AND:$<CXX_COMPILER_ID:MSVC>,$<NOT:$<COMPILE_LANGUAGE:CUDA>>>:/wd4251
74-
/wd4275>)
75-
endif()
76-
else()
77-
add_library(respond STATIC ${RESPOND_SRCS} ${RESPOND_ALL_HEADERS})
78-
endif()
79-
80-
# ---------------------------------------------------------------------------------------
81-
# Alias for importing
82-
# ---------------------------------------------------------------------------------------
83-
add_library(respond::respond ALIAS respond)
60+
target_sources(respond_model
61+
PRIVATE
62+
src/markov.cpp
63+
src/logging.cpp
64+
src/internals/logging_internals.hpp
65+
src/internals/markov_internals.hpp
8466

85-
set(RESPOND_INCLUDES_LEVEL "")
86-
if(RESPOND_SYSTEM_INCLUDES)
87-
set(RESPOND_INCLUDES_LEVEL "SYSTEM")
88-
endif()
67+
PUBLIC
68+
FILE_SET HEADERS
69+
BASE_DIRS
70+
include
71+
FILES
72+
include/respond/cost_effectiveness.hpp
73+
include/respond/helpers.hpp
74+
include/respond/logging.hpp
75+
include/respond/markov.hpp
76+
include/respond/respond.hpp
77+
include/respond/types.hpp
78+
include/respond/version.hpp
79+
)
8980

90-
target_compile_definitions(respond PUBLIC RESPOND_COMPILED_LIB)
91-
target_include_directories(respond ${RESPOND_INCLUDES_LEVEL} PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
92-
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>" PRIVATE
93-
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/src>")
81+
include(${PRIVATE_MODULE_PATH}/MakeDependenciesAvailable.cmake)
9482

95-
include(MakeDependenciesAvailable)
83+
set(private_deps spdlog::spdlog)
9684

9785
if (RESPOND_CALCULATE_COVERAGE)
98-
target_link_libraries(respond
99-
PUBLIC
100-
Eigen3::Eigen
101-
PRIVATE
102-
spdlog::spdlog
103-
gcov
104-
)
105-
else()
106-
target_link_libraries(respond
107-
PUBLIC
108-
Eigen3::Eigen
109-
PRIVATE
110-
spdlog::spdlog
111-
)
86+
list(APPEND private_deps gcov)
11287
endif()
11388

114-
set_target_properties(respond PROPERTIES VERSION ${RESPOND_VERSION} SOVERSION ${RESPOND_VERSION_MAJOR}.${RESPOND_VERSION_MINOR})
89+
target_link_libraries(respond_model
90+
PUBLIC
91+
Eigen3::Eigen
92+
PRIVATE
93+
${private_deps}
94+
)
11595

116-
include(BuildBinaries)
96+
set_target_properties(respond_model PROPERTIES VERSION ${RESPOND_VERSION} SOVERSION ${RESPOND_VERSION_MAJOR}.${RESPOND_VERSION_MINOR})
11797

118-
# ---------------------------------------------------------------------------------------
98+
include(${PRIVATE_MODULE_PATH}/BuildBinaries.cmake)
99+
100+
#-------------------------------------------------------------------------------
119101
# Install
120-
# ---------------------------------------------------------------------------------------
102+
#-------------------------------------------------------------------------------
103+
include(GNUInstallDirs)
121104
if(RESPOND_INSTALL)
122-
include(InstallRespond)
105+
include(${PRIVATE_MODULE_PATH}/InstallRespond.cmake)
123106
endif()

CMakePresets.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
"RESPOND_BUILD_TESTS": "ON",
4848
"RESPOND_CALCULATE_COVERAGE": "ON",
4949
"RESPOND_BUILD_BENCH": "OFF",
50-
"RESPOND_BUILD_SHARED_LIBS": "OFF",
5150
"RESPOND_BUILD_WARNINGS": "ON",
5251
"RESPOND_SYSTEM_INCLUDES": "OFF",
5352
"RESPOND_INSTALL": "OFF",
@@ -64,12 +63,10 @@
6463
"RESPOND_BUILD_TESTS": "OFF",
6564
"RESPOND_CALCULATE_COVERAGE": "OFF",
6665
"RESPOND_BUILD_BENCH": "OFF",
67-
"RESPOND_BUILD_SHARED_LIBS": "OFF",
6866
"RESPOND_BUILD_WARNINGS": "OFF",
6967
"RESPOND_SYSTEM_INCLUDES": "OFF",
7068
"RESPOND_INSTALL": "ON",
71-
"RESPOND_NO_EXCEPTIONS": "OFF",
72-
"RESPOND_RUN_OMP": "ON"
69+
"RESPOND_NO_EXCEPTIONS": "OFF"
7370
},
7471
"warnings": {
7572
"dev": false
@@ -169,7 +166,8 @@
169166
"name": "gcc-release",
170167
"configurePreset": "gcc-release",
171168
"generators": [
172-
"TGZ"
169+
"TGZ",
170+
"DEB"
173171
]
174172
}
175173
],

README.md

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# ⚠ NOTICE ⚠
1+
# :warning: NOTICE :warning:
2+
23
This repository is under active development and is not currently in a state for public use. If you wish to use RESPOND, please refer to release [v0.3.0](https://github.com/SyndemicsLab/respond/releases/tag/v0.3.0) for a functioning executable.
34

45
# RESPOND: An Opioid Use Disorder State Transition Model
@@ -9,7 +10,7 @@ This repository is under active development and is not currently in a state for
910
[![Tests](https://github.com/SyndemicsLab/respond/actions/workflows/test-ubuntu.yml/badge.svg)](https://github.com/SyndemicsLab/respond/actions/workflows/test-ubuntu.yml)
1011
[![Coverage](https://github.com/SyndemicsLab/respond/actions/workflows/coverage.yml/badge.svg)](https://github.com/SyndemicsLab/respond/actions/workflows/coverage.yml)
1112

12-
This is the home of the [RESPOND model](https://syndemicslab.github.io/respond)[1], first created by the [Syndemics Lab](https://www.syndemicslab.org) in 2018, now rewritten with a focus on four primary goals:
13+
This is the home of the [RESPOND model](https://syndemicslab.github.io/respond) [1], first created by the [Syndemics Lab](https://www.syndemicslab.org) in 2018, now rewritten with a focus on four primary goals:
1314

1415
1. Improve the Maintainability/Scalability of the Model
1516
2. Improve the Overall Efficiency of the Model
@@ -46,6 +47,7 @@ The required dependencies are:
4647
- [spdlog](https://github.com/gabime/spdlog)
4748

4849
Building tests is optional, but when doing so it requires:
50+
4951
- [GoogleTest](https://github.com/google/googletest)
5052

5153
### Local
@@ -60,6 +62,22 @@ cmake --workflow --preset gcc-release
6062

6163
And then the model is build and installed. Our default location is a build directory in the repository, but the CMake Install Directory can be pointed to wherever the user desires.
6264

65+
## Installation
66+
67+
As this is a library, we are currently working on expanding the ability to install and work with RESPOND. If building a new project using CMake we encourage the use of `FetchContent`. However, we do also provide debian and tarball installations as well. We are currently working on building a Windows executable as well.
68+
69+
### Debian
70+
71+
To access our Debian installer, please navigate to the [release](https://github.com/SyndemicsLab/respond/releases) you wish to install and download the Debian package (`.deb`).
72+
73+
From there, a simple
74+
75+
```bash
76+
sudo dpkg -i respond-xxx.deb
77+
```
78+
79+
command will result in the appropriate installation. The only files added are the public headers, the compiled static library, and the CMake configuration files.
80+
6381
### FetchContent
6482

6583
If you would like to make use of Fetch Content to extract the library:
@@ -69,16 +87,21 @@ include(FetchContent)
6987
FetchContent_Declare(
7088
respond
7189
GIT_REPOSITORY https://github.com/SyndemicsLab/respond.git
72-
GIT_TAG main
90+
GIT_TAG 5d4dde64b2e1f4ca4cea26851b82000379dbf7cb
91+
OVERRIDE_FIND_PACKAGE
92+
)
93+
set(RESPOND_INSTALL ON)
94+
find_package(respond REQUIRED)
95+
96+
target_link_libraries(${PROJECT_NAME}
97+
PRIVATE
98+
respond::respond_model
7399
)
74-
option(RESPOND_INSTALL "Enable install for respond project" ON)
75-
option(RESPOND_BUILD_TESTS "Disable testing for RESPOND" OFF)
76-
FetchContent_MakeAvailable(respond)
77100
```
78101

79102
### Script
80103

81-
If you would prefer a single, all in one, script. Our team has developed a script that works on any Linux environment and finds packages wherever available. As such, the user need simply run:
104+
If you would prefer a single bash script to add the project to the build tree, run:
82105

83106
```shell
84107
./tools/build.sh

cmake/InstallRespond.cmake

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,58 @@
1-
message(STATUS "Installing respond")
2-
set(project_config_in "${CMAKE_CURRENT_LIST_DIR}/respondConfig.cmake.in")
3-
set(project_config_out "${CMAKE_CURRENT_BINARY_DIR}/respondConfig.cmake")
4-
set(config_targets_file "respondConfigTargets.cmake")
1+
message(STATUS "Installing respond version ${RESPOND_VERSION}...")
2+
3+
set(export_dest_dir "${CMAKE_INSTALL_LIBDIR}/respond")
4+
set(export_cmake_dir "${CMAKE_INSTALL_LIBDIR}/cmake/respond")
55
set(version_config_file "${CMAKE_CURRENT_BINARY_DIR}/respondConfigVersion.cmake")
6-
set(export_dest_dir "${CMAKE_INSTALL_LIBDIR}/cmake/respond")
7-
set(pkgconfig_install_dir "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
8-
set(pkg_config "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc")
96

10-
# ---------------------------------------------------------------------------------------
7+
#-------------------------------------------------------------------------------
118
# Include files
12-
# ---------------------------------------------------------------------------------------
13-
install(DIRECTORY include/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
9+
#-------------------------------------------------------------------------------
10+
message("Installing respond to ${CMAKE_INSTALL_FULL_LIBDIR} and ${CMAKE_INSTALL_FULL_INCLUDEDIR}...")
11+
12+
install(
13+
TARGETS respond_model
14+
EXPORT respondTargets
15+
FILE_SET HEADERS
16+
)
17+
1418
install(
15-
TARGETS respond
16-
EXPORT respond
17-
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
18-
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
19-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
20-
21-
# ---------------------------------------------------------------------------------------
22-
# Install pkg-config file
23-
# ---------------------------------------------------------------------------------------
24-
if(IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}")
25-
set(PKG_CONFIG_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}")
26-
else()
27-
set(PKG_CONFIG_INCLUDEDIR "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
28-
endif()
29-
if(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}")
30-
set(PKG_CONFIG_LIBDIR "${CMAKE_INSTALL_LIBDIR}")
31-
else()
32-
set(PKG_CONFIG_LIBDIR "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
33-
endif()
34-
get_target_property(PKG_CONFIG_DEFINES respond INTERFACE_COMPILE_DEFINITIONS)
35-
string(REPLACE ";" " -D" PKG_CONFIG_DEFINES "${PKG_CONFIG_DEFINES}")
36-
string(CONCAT PKG_CONFIG_DEFINES "-D" "${PKG_CONFIG_DEFINES}")
37-
configure_file("cmake/${PROJECT_NAME}.pc.in" "${pkg_config}" @ONLY)
38-
install(FILES "${pkg_config}" DESTINATION "${pkgconfig_install_dir}")
39-
40-
# ---------------------------------------------------------------------------------------
41-
# Install CMake config files
42-
# ---------------------------------------------------------------------------------------
43-
export(TARGETS respond NAMESPACE respond::
44-
FILE "${CMAKE_CURRENT_BINARY_DIR}/${config_targets_file}")
45-
install(EXPORT respond DESTINATION ${export_dest_dir} NAMESPACE respond:: FILE ${config_targets_file})
19+
EXPORT respondTargets
20+
DESTINATION ${export_cmake_dir}
21+
NAMESPACE respond::
22+
)
4623

4724
include(CMakePackageConfigHelpers)
48-
configure_package_config_file("${project_config_in}" "${project_config_out}" INSTALL_DESTINATION ${export_dest_dir})
4925

50-
write_basic_package_version_file("${version_config_file}" COMPATIBILITY SameMajorVersion)
51-
install(FILES "${project_config_out}" "${version_config_file}" DESTINATION "${export_dest_dir}")
26+
configure_file(
27+
"${PROJECT_SOURCE_DIR}/cmake/respondConfig.cmake.in"
28+
"${PROJECT_BINARY_DIR}/respondConfig.cmake"
29+
@ONLY
30+
)
31+
set(project_config "${PROJECT_BINARY_DIR}/respondConfig.cmake")
32+
33+
write_basic_package_version_file(
34+
${version_config_file}
35+
COMPATIBILITY ExactVersion
36+
)
37+
38+
install(
39+
FILES
40+
${project_config}
41+
${version_config_file}
42+
DESTINATION ${export_cmake_dir}
43+
)
44+
45+
#-------------------------------------------------------------------------------
46+
# CPack Options for RESPOND
47+
#-------------------------------------------------------------------------------
48+
configure_file(
49+
"${PROJECT_SOURCE_DIR}/cmake/respondCPackOptions.cmake.in"
50+
"${PROJECT_BINARY_DIR}/respondCPackOptions.cmake"
51+
@ONLY
52+
)
53+
set(CPACK_PROJECT_CONFIG_FILE "${PROJECT_BINARY_DIR}/respondCPackOptions.cmake")
5254

53-
# ---------------------------------------------------------------------------------------
55+
#-------------------------------------------------------------------------------
5456
# Support creation of installable packages
55-
# ---------------------------------------------------------------------------------------
56-
include(cmake/respondCPack.cmake)
57+
#-------------------------------------------------------------------------------
58+
include(CPack)

0 commit comments

Comments
 (0)