-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
129 lines (107 loc) · 4.07 KB
/
Copy pathCMakeLists.txt
File metadata and controls
129 lines (107 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# Require (i.e. demand) an out-of-source build
if ( ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR} )
message("")
message(STATUS "Please use an out-of-source build, it's neater.")
message(STATUS "Don't forget to clean up ${CMAKE_BINARY_DIR} by removing:")
message(STATUS "\tCMakeCache.txt")
message(STATUS "\tCMakeFiles")
message(STATUS "Then you can create a separate directory and re-run cmake from there.\n")
message(FATAL_ERROR "In-source build attempt detected")
endif()
# Reporting checks arrived in 3.17
# https://cmake.org/cmake/help/latest/command/message.html#reporting-checks
cmake_minimum_required(VERSION 3.17 FATAL_ERROR)
message(STATUS "CMake version: ${CMAKE_VERSION}")
# Put all binaries in a their standard locations
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
# Project name, along with language type
project(
nuclear-data-reader
HOMEPAGE_URL "https://github.com/php1ic/nuclear-data-reader"
LANGUAGES CXX
VERSION 0.0.1
)
# Add the 'cmake' folder to the list of paths to check for modules
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
# Set some global project settings
include(GeneralProjectSettings)
# Configure static analysers, this was done via scripts, but cmake can now do it
include(StaticAnalyzers)
# Link this 'library' to set the c++ standard / compile-time options requested
add_library(project_options INTERFACE)
target_compile_features(project_options INTERFACE)
# Link this 'library' to use the warnings specified in CompilerWarnings.cmake
add_library(project_warnings INTERFACE)
# Which compiler flags should we use
include(CompilerWarnings)
set_project_warnings(project_warnings)
# Doxygen configuration
include(Doxygen)
enable_doxygen()
# Code Coverage Configuration
include(CodeCoverage)
enable_codecoverage(project_options)
# Allow the various santizers to be toggled ON/OFF
include(Sanitizers)
enable_sanitizers(project_options)
# Make sure any and all external libraries are linked
include(ExternalLibraries)
add_external_libraries(project_options)
# Configurable header file to store project version number
add_subdirectory(include/${PROJECT_NAME})
# Keep list alphabetical
set(SOURCE_DIR ${PROJECT_SOURCE_DIR}/src)
set(SOURCES
${SOURCE_DIR}/ame_data.cpp
${SOURCE_DIR}/converter.cpp
${SOURCE_DIR}/massTable.cpp
${SOURCE_DIR}/nubase_data.cpp
${SOURCE_DIR}/isotope.cpp
)
# While I try and work out how to create a shared library
# on windows that can actually be linked to, lets make a static one
if(MSVC)
add_library(${PROJECT_NAME} STATIC ${SOURCES})
else()
add_library(${PROJECT_NAME} SHARED ${SOURCES})
endif()
# Use a compile time definition to set the path to the data files
add_compile_definitions(NDR_DATA_PATH=\"${PROJECT_SOURCE_DIR}/data/\")
message(STATUS "Setting the data path as: ${PROJECT_SOURCE_DIR}/data")
# Where are the header files
target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/include/)
# Allow the use of pre-compiled headers
# Get a list of the most used headers with the following command, run from the root of the dir,
# grep -h "^#include <" ./{src,include/nuclear-data-reader}/* | sort | uniq -c | sort -nr
# Somewhat randomly pick the top 6 headers used in the project. Top 6 are used at least 4 times
option(NDR_PCH "Enable pre-compiled headers" OFF)
if(NDR_PCH)
message(STATUS "[Precompiled Headers] Enabling precompiled headers")
target_precompile_headers(project_options INTERFACE
<cstdint>
<limits>
<algorithm>
<string>
<vector>
<string_view>
)
else()
message(STATUS "[Precompiled Headers] Not using precompiled headers")
endif()
target_link_libraries(
${PROJECT_NAME}
PRIVATE
project_warnings
project_options
)
# Unit testing with Catch2
option(NDR_UNIT_TESTS "Build unit tests" OFF)
if(NDR_UNIT_TESTS)
enable_testing()
add_subdirectory(external/Catch2)
add_subdirectory(tests)
endif()
# Setup an install target
install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION lib)
install(DIRECTORY include/${PROJECT_NAME} DESTINATION include FILES_MATCHING PATTERN "*.hpp")