forked from albarji/proxTV
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
147 lines (127 loc) · 5.06 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
cmake_minimum_required(VERSION 3.12)
project(proxTV
VERSION 3.2.1
DESCRIPTION "Toolbox for fast Total Variation proximity operators"
)
message(STATUS "Configuring ${PROJECT_NAME}")
message(STATUS " version: ${proxTV_VERSION}")
message(STATUS " description: ${proxTV_DESCRIPTION}")
# Update CMake module path to lookup proxTV custom CMake modules
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# Add -fPIC
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
#------------------------------------------------------------------------------
if(NOT DEFINED proxTV_INSTALL_DEVELOPMENT)
option(proxTV_INSTALL_DEVELOPMENT "Install development files" ON)
endif()
if(NOT DEFINED proxTV_ENABLE_TESTING)
option(proxTV_ENABLE_TESTING "Compile tests" OFF)
endif()
if(NOT DEFINED proxTV_USE_LAPACK)
option(proxTV_USE_LAPACK "Use LAPACK and LAPACKE instead of EIGEN" ON)
endif()
#------------------------------------------------------------------------------
# Set a default build type if none was specified
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
mark_as_advanced(CMAKE_BUILD_TYPE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
#------------------------------------------------------------------------------
# Install directories
if(NOT DEFINED proxTV_INSTALL_BIN_DIR)
set(proxTV_INSTALL_BIN_DIR bin)
endif()
if(NOT DEFINED proxTV_INSTALL_LIB_DIR)
set(proxTV_INSTALL_LIB_DIR lib)
endif()
if(NOT DEFINED proxTV_INSTALL_INCLUDE_DIR)
set(proxTV_INSTALL_INCLUDE_DIR include)
endif()
if(NOT DEFINED proxTV_INSTALL_CMAKE_DIR)
set(proxTV_INSTALL_CMAKE_DIR ${proxTV_INSTALL_LIB_DIR}/cmake/proxTV)
endif()
message(STATUS "proxTV_INSTALL_INCLUDE_DIR: ${proxTV_INSTALL_INCLUDE_DIR}")
message(STATUS "proxTV_INSTALL_LIB_DIR: ${proxTV_INSTALL_LIB_DIR}")
message(STATUS "proxTV_INSTALL_CMAKE_DIR: ${proxTV_INSTALL_CMAKE_DIR}")
#------------------------------------------------------------------------------
# External dependencies
if(proxTV_USE_LAPACK)
find_package(LAPACKE REQUIRED)
message(STATUS "Lapacke libraries: ${LAPACKE_LIBRARIES}")
find_package(LAPACK REQUIRED)
message(STATUS "Lapack libraries: ${LAPACK_LIBRARIES}")
else()
# No need to find Eigen3 if the Eigen3 target exists already.
# This happens when a project is fetching Eigen before fetching proxTV with add_subdirectory
# Particularly, this allows to build the module inside ITK when Module_TotalVariation is ON
if(NOT TARGET Eigen3::Eigen3)
find_package(Eigen3 REQUIRED)
endif()
get_target_property(EIGEN_INCLUDE_DIR Eigen3::Eigen
INTERFACE_INCLUDE_DIRECTORIES)
message(STATUS "Eigen Found: ${EIGEN_INCLUDE_DIR}")
endif()
set(THREADS_PREFER_PTHREAD_FLAG 1)
find_package(Threads)
find_package(OpenMP)
message(STATUS "OpenMP found: ${OpenMP_FOUND}")
#------------------------------------------------------------------------------
# Add libraries
add_subdirectory(src)
#------------------------------------------------------------------------------
# Testing
if(proxTV_ENABLE_TESTING)
enable_testing()
add_subdirectory(test)
endif()
#------------------------------------------------------------------------------
# Configure proxTVConfigVersion.cmake common to build and install tree
include(CMakePackageConfigHelpers)
set(config_version_file "${proxTV_BINARY_DIR}/proxTVConfigVersion.cmake")
write_basic_package_version_file(${config_version_file}
VERSION ${proxTV_VERSION}
COMPATIBILITY SameMajorVersion
)
#------------------------------------------------------------------------------
# Export 'proxTVTargets.cmake' for a build tree
export(TARGETS proxTV
FILE ${PROJECT_BINARY_DIR}/proxTVTargets.cmake
NAMESPACE proxTV::
)
# Configure 'proxTVConfig.cmake' for a build tree
include(CMakePackageConfigHelpers)
set(build_config ${PROJECT_BINARY_DIR}/proxTVConfig.cmake)
configure_package_config_file(
cmake/proxTVConfig.cmake.in
${build_config}
INSTALL_DESTINATION ${PROJECT_BINARY_DIR}
INSTALL_PREFIX ${PROJECT_BINARY_DIR}
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
#------------------------------------------------------------------------------
# Configure 'proxTVConfig.cmake' for an install tree
if(proxTV_INSTALL_DEVELOPMENT)
set(install_config ${PROJECT_BINARY_DIR}/CMakeFiles/proxTVConfig.cmake)
configure_package_config_file(
cmake/proxTVConfig.cmake.in
${install_config}
INSTALL_DESTINATION ${proxTV_INSTALL_CMAKE_DIR}
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
# Install 'proxTVTargets.cmake'
install(EXPORT proxTVTargets
FILE proxTVTargets.cmake
NAMESPACE proxTV::
DESTINATION ${proxTV_INSTALL_CMAKE_DIR}
COMPONENT Development
)
# Install config files
install(
FILES ${config_version_file} ${install_config}
DESTINATION ${proxTV_INSTALL_CMAKE_DIR}
COMPONENT Development
)
endif()