-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
170 lines (141 loc) · 5.9 KB
/
CMakeLists.txt
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
cmake_minimum_required(VERSION 3.14.7 FATAL_ERROR)
# ##### Set policies
cmake_policy(SET CMP0048 NEW)
# ##### Set module path and import some macros
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(get_git_repo_version)
include(get_build_macros_and_functions)
include(CMakeDependentOption)
include(afni_cmake_build_options)
if(NOT DEFINED CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER "gcc")
endif()
# ##### Project info
project(
AFNI
VERSION ${GIT_REPO_VERSION}
DESCRIPTION "A package for the analysis of functional neuroimaging."
)
string(TIMESTAMP BUILD_DATE "%m %d %Y")
set(AFNI_VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/src/AFNI_version.h")
check_header_has_been_created("${AFNI_VERSION_HEADER}" "${GIT_REPO_VERSION}")
if("/usr/bin/cc" STREQUAL "${CMAKE_C_COMPILER}")
# This should never happen, compiler should be gcc or clang
message(FATAL_ERROR "wrong compiler: ${CMAKE_C_COMPILER}")
endif()
# set(CMAKE_LINK_WHAT_YOU_USE $<$<C_COMPILER_ID:GNU>:ON>)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# set(CMAKE_C_FLAGS_DEBUG
# "${CMAKE_C_FLAGS_DEBUG} -DAFNI_DEBUG -DIMSEQ_DEBUG -DDISPLAY_DEBUG -DTHD_DEBUG"
# )
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_TRACING") # XXX not in default cflags
# if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DREAD_WRITE_64 -DLINUX2")
# elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DREAD_WRITE_64 -DLINUX -DDARWIN")
# endif()
set_if_not_defined(INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
set_if_not_defined(AFNI_INSTALL_LIBRARY_DIR "${INSTALL_PREFIX}/lib")
set_if_not_defined(AFNI_INSTALL_RUNTIME_DIR "${INSTALL_PREFIX}/bin")
set_if_not_defined(AFNI_INSTALL_INCLUDE_DIR "${INSTALL_PREFIX}/include")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/src/targets)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/src/targets)
if(CONDA_BUILD)
get_filename_component(AFNI_INSTALL_LIBRARY_DIR ${AFNI_INSTALL_LIBRARY_DIR} DIRECTORY)
get_filename_component(AFNI_INSTALL_INCLUDE_DIR ${AFNI_INSTALL_INCLUDE_DIR} DIRECTORY)
endif()
# Other possible directories to set
set(AFNI_INSTALL_ATLAS_DIR "${INSTALL_PREFIX}/atlases")
set(AFNI_INSTALL_PICS_DIR "${INSTALL_PREFIX}/funstuff")
# Get mapping between each target name and it's installation component
set(COMPONENTS_MAPFILE ${CMAKE_CURRENT_SOURCE_DIR}/packaging/installation_components.txt )
file(READ
${COMPONENTS_MAPFILE}
CMPNT_MAPPING)
list(TRANSFORM CMPNT_MAPPING REPLACE "\n" ";")
# ##### Dependencies
include(afni_project_dependencies)
# Other details of dependencies and configuration
set(CMAKE_C_FLAGS_DEBUG
"${CMAKE_C_FLAGS_DEBUG} -DAFNI_DEBUG -DIMSEQ_DEBUG -DDISPLAY_DEBUG -DTHD_DEBUG"
)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_TRACING -DHAVE_ZLIB") # XXX not in default cflags
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DREAD_WRITE_64 -DLINUX2")
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DREAD_WRITE_64 -DLINUX -DDARWIN")
endif()
# ##### Docs, licence, and README
set(DOC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/doc)
if(EXISTS ${DOC_DIR})
quotize("${DOC_DIR}/README/README.copyright" license)
quotize("${DOC_DIR}/README/README.environment" readme_env)
quotize("${DOC_DIR}/README/README.afnigui" readme_afnigui)
add_subdirectory(doc)
endif()
quotize("${CMAKE_CURRENT_SOURCE_DIR}/afni_papers.txt" afni_papers)
# ##### Add the source code to build
add_subdirectory(src)
# ##### Tests
if(${ENABLE_TESTS})
enable_testing()
endif()
set(TESTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests)
if(EXISTS ${DOC_DIR})
add_subdirectory(tests)
endif()
# ##### Write out package version information
write_basic_package_version_file(
MyLibConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
# Allow an uninstall (with some risk of messiness)
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY
)
add_custom_target(
uninstall COMMAND ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
)
endif()
# Setup for tests. Things like, clear some cache dirs, and check the tests
# from the source tree are symlinked into the build tree.
add_custom_target(
test_setup
COMMAND
${CMAKE_COMMAND}
-D TESTS_PATH=${CMAKE_CURRENT_SOURCE_DIR}/tests
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/setup_for_tests.cmake
)
# Define PATH modification required for within build tree tests execution
set(COMP_ADD_BINARIES ${CMAKE_CURRENT_BINARY_DIR}/src/targets)
set(T_SCRIPTS ${CMAKE_CURRENT_SOURCE_DIR}/src/scripts_install)
set(P_SCRIPTS ${CMAKE_CURRENT_SOURCE_DIR}/src/python_scripts/afni_python)
set(R_SCRIPTS ${CMAKE_CURRENT_SOURCE_DIR}/src/R_scripts)
set(J_SCRIPTS ${CMAKE_CURRENT_SOURCE_DIR}/src/jzosky)
set(J_SCRIPTS "${J_SCRIPTS}:${J_SCRIPTS}/lib_RetroTS")
set(TESTING_PATHS "${COMP_ADD_BINARIES}:${T_SCRIPTS}:${P_SCRIPTS}:${R_SCRIPTS}:${J_SCRIPTS}")
set(PATH_FOR_TESTING "${TESTING_PATHS}:$ENV{PATH}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/TESTING_PATHS.txt ${TESTING_PATHS})
# Create test target for running tests within the build tree
add_custom_target(
pytest
DEPENDS test_setup
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/afni_tests"
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}
COMMAND echo Running tests with modified path to use build binaries and scripts in the source tree...
COMMAND echo Prepending ${TESTING_PATHS}
COMMAND echo When using 'ninja test' one can define "ARGS" to pass additional arguments to pytest...
COMMAND ${CMAKE_COMMAND} -E env PATH=${PATH_FOR_TESTING} ${Python_EXECUTABLE} -B -m pytest $$ARGS
USES_TERMINAL
)
# Generate packaging if this is the top level project
if(USE_CPACK)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
include(CMakeCPack.cmake)
endif()
endif()
unset(USE_SYSTEM_ALL CACHE)