-
Notifications
You must be signed in to change notification settings - Fork 10
/
CMakeLists.txt
155 lines (139 loc) · 4.93 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
cmake_minimum_required(VERSION 3.16.2)
project(TotalVariation)
if(ITK_USE_SYSTEM_proxTV)
set(TotalVariation_LIBRARIES proxTV::proxTV)
else()
set(TotalVariation_LIBRARIES proxTV)
endif()
set(${PROJECT_NAME}_THIRD_PARTY 1)
include(itk-module-init.cmake)
if(NOT ITK_SOURCE_DIR)
find_package(ITK REQUIRED)
list(APPEND CMAKE_MODULE_PATH ${ITK_CMAKE_DIR})
endif()
include(CMakeParseArguments)
include(FetchContent)
# Compile definition needed for proxTV headers
# This will propagate to wrapping.
# For wrapping to work, requires ITK with patch:
# https://github.com/InsightSoftwareConsortium/ITK/pull/707
add_compile_definitions(NOMATLAB)
message(STATUS "TotalVariation_proxTV_USE_EIGEN: ${TotalVariation_proxTV_USE_EIGEN}")
if(TotalVariation_proxTV_USE_EIGEN)
if(NOT ITK_USE_SYSTEM_EIGEN)
# Set Eigen3_DIR to the internal Eigen3 used in ITK
set(Eigen3_DIR "${ITKInternalEigen3_DIR}")
message(STATUS "ITKTotalVariation: Using internal ITK Eigen Config found in: ${Eigen3_DIR}")
endif()
find_package(Eigen3 REQUIRED)
set(${PROJECT_NAME}_EXPORT_CODE_INSTALL
"${${PROJECT_NAME}_EXPORT_CODE_INSTALL}
find_package(OpenMP)
set(Eigen3_DIR \"${Eigen3_DIR}\")
find_package(Eigen3 REQUIRED CONFIG)
")
set(${PROJECT_NAME}_EXPORT_CODE_BUILD
"${${PROJECT_NAME}_EXPORT_CODE_BUILD}
if(NOT ITK_BINARY_DIR)
find_package(OpenMP)
set(Eigen3_DIR \"${Eigen3_DIR}\")
find_package(Eigen3 REQUIRED CONFIG)
endif()
")
else()
# proxTV will be build with external system LAPACK instead of Eigen3
set(proxTV_USE_LAPACK 1)
add_compile_definitions(PROXTV_USE_LAPACK)
endif()
# _proxTV_lib will be `proxTV::proxTV` when find_package, and `proxTV` when add_subdirectory(proxTV_folder)
set(_proxTV_lib "")
# if proxTV is built elsewhere
if(ITK_USE_SYSTEM_proxTV)
find_package(proxTV REQUIRED CONFIG)
set(_proxTV_lib proxTV::proxTV)
set(proxTV_DIR_INSTALL ${proxTV_DIR})
set(proxTV_DIR_BUILD ${proxTV_DIR})
# It is only needed to EXPORT_CODE_BUILD when using external proxTV
set(${PROJECT_NAME}_EXPORT_CODE_BUILD
"${${PROJECT_NAME}_EXPORT_CODE_BUILD}
if(NOT ITK_BINARY_DIR)
find_package(OpenMP)
set(proxTV_DIR \"${proxTV_DIR_BUILD}\")
find_package(proxTV REQUIRED CONFIG)
endif()
")
else() # build proxTV here with the selected Eigen3
# Build proxTV with C++11
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
if(NOT CMAKE_CXX_STANDARD_REQUIRED)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()
if(NOT CMAKE_CXX_EXTENSIONS)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()
set(proxTV_GIT_REPOSITORY "https://github.com/phcerdan/proxTV.git")
set(proxTV_GIT_TAG "use_eigen")
FetchContent_Declare(
proxtv_fetch
GIT_REPOSITORY ${proxTV_GIT_REPOSITORY}
GIT_TAG ${proxTV_GIT_TAG})
FetchContent_GetProperties(proxTV_fetch)
# proxTV options:
set(Eigen3_DIR "${Eigen3_DIR}") # This is not needed but explicit helps reader.
set(proxTV_USE_LAPACK 0)
if(NOT DEFINED proxTV_INSTALL_INCLUDE_DIR)
if(NOT ITK_SOURCE_DIR)
set(ITK_INSTALL_INCLUDE_DIR include/ITK-${ITK_VERSION_MAJOR}.${ITK_VERSION_MINOR})
endif()
set(proxTV_INSTALL_INCLUDE_DIR ${ITK_INSTALL_INCLUDE_DIR}/proxTV)
endif()
if(NOT DEFINED proxTV_INSTALL_LIB_DIR)
if(NOT ITK_SOURCE_DIR)
set(ITK_INSTALL_LIBRARY_DIR lib)
endif()
set(proxTV_INSTALL_LIB_DIR ${ITK_INSTALL_LIBRARY_DIR})
endif()
if(NOT DEFINED proxTV_INSTALL_CMAKE_DIR)
if(NOT ITK_SOURCE_DIR)
set(ITK_INSTALL_PACKAGE_DIR "lib/cmake/ITK-${ITK_VERSION_MAJOR}.${ITK_VERSION_MINOR}")
endif()
set(proxTV_INSTALL_CMAKE_DIR ${ITK_INSTALL_PACKAGE_DIR}/Modules)
endif()
# end proxTV options
FetchContent_MakeAvailable(proxTV_fetch)
# proxTV will generate a target proxTV::proxTV when using find_package,
# or a library proxTV when using add_subdirectory
set(_proxTV_lib proxTV) # proxTV generated in subdirectory
set(proxTV_DIR_INSTALL "${CMAKE_INSTALL_PREFIX}/${proxTV_INSTALL_CMAKE_DIR}")
endif()
# When this module is loaded by an app, load proxTV too.
set(${PROJECT_NAME}_EXPORT_CODE_INSTALL
"${${PROJECT_NAME}_EXPORT_CODE_INSTALL}
find_package(OpenMP)
set(proxTV_DIR \"${proxTV_DIR_INSTALL}\")
find_package(proxTV REQUIRED CONFIG)
")
set(_populate_include_dirs_for_swig TRUE)
if(${_populate_include_dirs_for_swig})
# SWIG (wrapping) requires INCLUDE_DIRS
get_target_property(proxTV_INCLUDE_DIRS ${_proxTV_lib} INTERFACE_INCLUDE_DIRECTORIES)
string(REGEX REPLACE
".*BUILD_INTERFACE:(.*/proxtv_fetch-build/src/include).*"
"\\1"
proxTV_INCLUDE_DIRS_STRIP
${proxTV_INCLUDE_DIRS})
# message(STATUS "proxTV_INCLUDE_DIRS: ${proxTV_INCLUDE_DIRS}")
# message(STATUS "proxTV_INCLUDE_DIRS_STRIP: ${proxTV_INCLUDE_DIRS_STRIP}")
set(TotalVariation_INCLUDE_DIRS ${proxTV_INCLUDE_DIRS_STRIP})
endif()
# Populate module variables
if(NOT ITK_SOURCE_DIR)
include(ITKModuleExternal)
else()
set(ITK_DIR ${CMAKE_BINARY_DIR})
itk_module_impl()
endif()
# Add the proxTV library to Modules/Targets/TotalVariationTargets.cmake
itk_module_target(${_proxTV_lib} NO_INSTALL)