forked from david-m-rosen/Optimization
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
121 lines (98 loc) · 5.49 KB
/
CMakeLists.txt
File metadata and controls
121 lines (98 loc) · 5.49 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
# A simple CMakeLists file that enables the Optimization library to be conveniently imported by other CMake projects using
cmake_minimum_required(VERSION 3.1)
# PROJECT CONFIGURATION
project(Optimization LANGUAGES CXX VERSION 1.0.0)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
include(GNUInstallDirs)
if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHa")
endif()
include(CTest)
# Set build type to 'RelWithDebInfo' if one was not specified by the user
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS RelWithDebInfo Release Debug MinSizeRel)
message(STATUS "Setting build type to ${CMAKE_BUILD_TYPE}, as none was specified\n")
else()
message(STATUS "Building in ${CMAKE_BUILD_TYPE} mode\n")
endif()
# BUILD CONFIGURATIONS
# Build the examples?
set(BUILD_OPTIMIZATION_EXAMPLES OFF CACHE BOOL "Build example executables? [disabled by default]")
# Build the unit tests?
set(BUILD_OPTIMIZATION_TESTS OFF CACHE BOOL "Build unit tests? [disabled by default]")
# SET UP EXPORT OF OPTIMIZATION LIBRARY
# We declare this library as an INTERFACE library; this means that it does not directly produce built output, though it may have properties set on it and it may be installed, exported and imported.
add_library(${PROJECT_NAME} INTERFACE)
# Set the include directory for this project. We use include/ as the top-level include directory so that #include directives in client source files are of the form "${PROJECT_NAME}/blah/blah.h"
set(OPTIMIZATION_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
message(STATUS "Found ${PROJECT_NAME} include directory: ${OPTIMIZATION_INCLUDE_DIR}")
target_include_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${OPTIMIZATION_INCLUDE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
# Top-level directory of the Optimization library
set(OPTIMIZATION_TOPLEVEL_DIR ${OPTIMIZATION_INCLUDE_DIR}/Optimization)
# The list of header files provided by this project
set(OPTIMIZATION_HDRS
${OPTIMIZATION_TOPLEVEL_DIR}/Base/Concepts.h
${OPTIMIZATION_TOPLEVEL_DIR}/Util/Stopwatch.h
${OPTIMIZATION_TOPLEVEL_DIR}/Convex/Concepts.h
${OPTIMIZATION_TOPLEVEL_DIR}/Convex/ProximalGradient.h
${OPTIMIZATION_TOPLEVEL_DIR}/Convex/ADMM.h
${OPTIMIZATION_TOPLEVEL_DIR}/LinearAlgebra/Concepts.h
${OPTIMIZATION_TOPLEVEL_DIR}/LinearAlgebra/IterativeSolvers.h
${OPTIMIZATION_TOPLEVEL_DIR}/Riemannian/Concepts.h
${OPTIMIZATION_TOPLEVEL_DIR}/Riemannian/GradientDescent.h
${OPTIMIZATION_TOPLEVEL_DIR}/Riemannian/TNT.h
${OPTIMIZATION_TOPLEVEL_DIR}/Riemannian/TNLS.h
)
message(STATUS "Found ${PROJECT_NAME} header files:\n ${OPTIMIZATION_HDRS}")
# List the complete set of header files as source files.
target_sources(${PROJECT_NAME} INTERFACE $<BUILD_INTERFACE:${OPTIMIZATION_HDRS}>)
# SET UP [OPTIONAL] CODE EXAMPLES AND TESTS
# Define some additional (optional) named targets, not built by default. Typically, these will be e.g. unit tests, example executables.
if(${BUILD_OPTIMIZATION_EXAMPLES} OR ${BUILD_OPTIMIZATION_TESTS})
# Directory for built libraries
set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/lib CACHE PATH "The directory in which to place libraries built by this project")
# Directory for built executables
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/bin CACHE PATH "The directory in which to place executables built by this project")
endif()
# This is the name of the target in the generated Makefile that builds the example executables; i.e., to build these, one must type "make $EXAMPLES_TARGET_NAME" using the generated Makefile in order to build the example executables (we do this because we don't want these executables to be automatically built by other CMake projects that use this one as a dependency)
if(${BUILD_OPTIMIZATION_EXAMPLES})
message(STATUS "Adding examples to build")
add_subdirectory(examples)
endif()
# This is the name of the target in the generated Makefile that builds the tests; i.e., to build these, one must type "make $TESTS_TARGET_NAME" using the generated Makefile in order to build the example executables (we do this because we don't want these executables to be automatically built by other CMake projects that use this one as a dependency)
if(${BUILD_OPTIMIZATION_TESTS})
message(STATUS "Adding unit tests to build")
add_subdirectory(tests)
endif()
###############################################################################################
# install
###############################################################################################
include(CMakePackageConfigHelpers)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/CMake/${PROJECT_NAME}Config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}
)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME})
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-export
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(EXPORT ${PROJECT_NAME}-export
FILE
${PROJECT_NAME}Targets.cmake
NAMESPACE
${PROJECT_NAME}::
DESTINATION
${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}
)