-
Notifications
You must be signed in to change notification settings - Fork 33
/
CMakeLists.txt
117 lines (87 loc) · 3.22 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
cmake_minimum_required(VERSION 3.19)
project(adol-c
VERSION 2.7.3
LANGUAGES C CXX
DESCRIPTION "A Package for Automatic Differentiation of Algorithms Written in C/C++"
HOMEPAGE_URL "https://github.com/coin-or/ADOL-C")
add_library(adolc SHARED)
add_library(adolc::adolc ALIAS adolc)
target_compile_features(adolc PUBLIC cxx_std_17)
# Make the version of ADOL-C available as compile definitions
target_compile_definitions(adolc PRIVATE
ADOLC_VERSION=${adol-c_VERSION_MAJOR}
ADOLC_SUBVERSION=${adol-c_VERSION_MINOR}
ADOLC_PATCHLEVEL=${adol-c_VERSION_PATCH})
# win specific flags
if (WIN32)
target_compile_definitions(adolc PRIVATE
# handles __declspec
ADOLC_DLL
)
endif(WIN32)
# Set the public include directory containing headers that will be installed
target_include_directories(adolc
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/ADOL-C/include>
$<INSTALL_INTERFACE:include>)
# Set an include directory for the internally used library headers.
#
# This includes the files uni5_for.c, fo_rev.c, and ho_rev.c. Even though
# they end with .c, they are used like header files. Together with some
# preprocessor trickery this is an old-fashioned way to do generic programming.
target_include_directories(adolc
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/ADOL-C/src>)
# handle the options
# ------------------
set(UINT_TYPE uint32_t)
set(REAL_TYPE double)
set(ADVBRANCH "#undef ADOLC_ADVANCED_BRANCHING")
set(ADTL_REFCNT "#undef USE_ADTL_REFCOUNTING")
set(SPARSE_DRIVERS "#undef SPARSE_DRIVERS")
set(USE_BOOST_POOL "#undef USE_BOOST_POOL")
# include subdirectories for handling of includes and source files
# ----------------------------------------------------------------
add_subdirectory(ADOL-C)
# include the c interface of adolc
# ----------------------------------------------------------------
option(BUILD_INTERFACE OFF)
if(BUILD_INTERFACE)
# set rpath for execution to the install location of adolc
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
add_subdirectory(ADOL-C/c_interface)
install(TARGETS ADOLCInterface EXPORT ADOLCInterfaceTargets)
install(EXPORT ADOLCInterfaceTargets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/adolc)
endif()
# build the tests
# ------------------------------------
option(BUILD_TESTS OFF)
if(BUILD_TESTS)
set(ADOLC_INCLUDE_DIR "${CMAKE_BINARY_DIR}/ADOL-C/include")
add_subdirectory(ADOL-C/boost-test)
enable_testing()
add_test(NAME boost-test-adolc
COMMAND boost-test-adolc)
endif()
# build the adolc and tests with coverage
# ------------------------------------
option(BUILD_TESTS_WITH_COV OFF)
if(BUILD_TESTS_WITH_COV)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g --coverage")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g --coverage")
set(ADOLC_INCLUDE_DIR "${CMAKE_BINARY_DIR}/ADOL-C/include")
add_subdirectory(ADOL-C/boost-test)
enable_testing()
add_test(NAME boost-test-adolc
COMMAND boost-test-adolc)
endif()
# export the targets
# ------------------
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
install(TARGETS adolc EXPORT adolcTargets)
install(EXPORT adolcTargets
FILE adolc-targets.cmake
NAMESPACE adolc::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/adolc)