forked from bradbell/cppad_py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
155 lines (155 loc) · 6.03 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
# -----------------------------------------------------------------------------
# cppad_py: A C++ Object Library and Python Interface to Cppad
# Copyright (C) 2017-18 Bradley M. Bell ([email protected])
# This program is distributed under the terms of the
# GNU General Public License version 3.0 or later see
# https://www.gnu.org/licenses/gpl-3.0.txt
# -----------------------------------------------------------------------------
# cmake \
# -D CMAKE_VERBOSE_MAKEFILE=value \
# -D cppad_prefix=value \
# -D extra_cxx_flags=value \
# -D python_version=value
#
# -----------------------------------------------------------------------------
# preamble
# Suppress warnging that WIN32 not defined on cygwin
SET(CMAKE_LEGACY_CYGWIN_WIN32 0) # remove when version below >= 2.8.4
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
SET(cppad_py_version "20181110")
PROJECT(cppad_py)
# =============================================================================
# MACROS
# =============================================================================
# assert(variable)
#
# ${variable}: (in)
# This variable is checked to make sure it is true, and if it is not true,
# a fatal error message is printed.
MACRO(assert variable)
IF( NOT ${variable} )
MESSAGE(FATAL_ERROR
"Error: ${variable} is false in ${CMAKE_CURRENT_LIST_FILE}"
)
ENDIF( NOT ${variable} )
ENDMACRO(assert)
# ----------------------------------------------------------------------------
# MACRO: print_variable(variable)
#
# ${variable}: (in)
# The variable name and ${${variable}} is the variable value.
MACRO(print_variable variable)
MESSAGE(STATUS "${variable} = ${${variable}}" )
ENDMACRO(print_variable)
# -----------------------------------------------------------------------------
# MACRO: cmake_argument(variable default type description)
#
# ${variable}: (in)
# is the variable we are setting to its default value.
#
# ${$variable}} (out)
# The value of the variable. It can be changed on the cmake command line
# (or in the camke gui). The final value of the variable is printed with
# the cmake output.
#
# ${default}: (in)
# is the default value for this variable; i.e.,
# if it is not set by the cmake command line or gui.
#
# ${type}: (in)
# must be one of the following:
# STRING, if the variable holds an arbitrary string.
# PATH, if the variable holds a directory.
# BOOL, if the variable only has the values true or false.
#
# ${description}: (in)
# Is a description of how the variable affects the Cppad install procedure.
MACRO(cmake_argument variable default type description)
IF( NOT ( ${type} STREQUAL "STRING" ) )
IF( NOT ( ${type} STREQUAL "PATH" ) )
IF( NOT ( ${type} STREQUAL "BOOL" ) )
print_variable(variable)
print_variable(type)
MESSAGE(FATAL_ERROR,
"optional_cmake_agument: error in a CMakeLists.txt file."
)
ENDIF( NOT ( ${type} STREQUAL "BOOL" ) )
ENDIF( NOT ( ${type} STREQUAL "PATH" ) )
ENDIF( NOT ( ${type} STREQUAL "STRING" ) )
#
SET(${variable} "${default}" CACHE ${type} "${description}")
print_variable(${variable})
ENDMACRO( cmake_argument )
# -----------------------------------------------------------------------------
# MACRO: add_to_list(variable_list constant_value)
#
# ${variables_list}: (in/out)
# The variable containing the list of values.
# The original list may be ""; i.e., the empty list.
#
# ${constant_value}: (in)
# Is the value we are adding to the list. This value cannot be empty.
MACRO(add_to_list variable_list constant_value )
IF( "${constant_value}" STREQUAL "" )
print_variable(variable_list)
print_variable(constant_value)
MESSAGE(FATAL_ERROR "add_to_list: constant_value is empty")
ENDIF( "${constant_value}" STREQUAL "" )
IF( "${${variable_list}}" STREQUAL "" )
SET( ${variable_list} ${constant_value} )
ELSE( "${${variable_list}}" STREQUAL "" )
SET( ${variable_list} ${${variable_list}} ${constant_value} )
ENDIF( "${${variable_list}}" STREQUAL "" )
ENDMACRO(add_to_list)
# -----------------------------------------------------------------------------
# make sure we have Swig available
FIND_PACKAGE(SWIG)
IF( NOT SWIG_FOUND )
MESSAGE(FATAL_ERROR "Aborting because cmake cannot find Swig")
ENDIF( NOT SWIG_FOUND )
# -----------------------------------------------------------------------------
# print important system variables
print_variable(CMAKE_BINARY_DIR)
print_variable(CMAKE_VERBOSE_MAKEFILE)
print_variable(CMAKE_CXX_FLAGS)
print_variable(CMAKE_BUILD_TYPE)
# -----------------------------------------------------------------------------
# cppad_prefix and corresponding include directories
cmake_argument(cppad_prefix NOTFOUND PATH "prefix used to install Cppad" )
IF( NOT cppad_prefix )
MESSAGE(FATAL_ERROR "cppad_prefix is not defined by cmake command line")
ENDIF( NOT cppad_prefix )
INCLUDE_DIRECTORIES( ${cppad_prefix}/include )
# -----------------------------------------------------------------------------
# extra_cxx_flags
cmake_argument(extra_cxx_flags "" STRING
"Flags, added to CMAKE_CXX_FLAGS, used when compiling cppad_py code."
)
# -----------------------------------------------------------------------------
# python_version
cmake_argument(python_version "" STRING
"major and minor version number for python, major part of must be 2 or 3."
)
STRING(REGEX MATCH "[23][.][0-9.]*" python_version_ok "${python_version}")
IF( NOT python_version_ok )
MESSAGE(FATAL_ERROR "python major version is not 2 or 3")
ENDIF( NOT python_version_ok )
STRING(REGEX MATCH "[23][.][0-9]*" python_version_ok "${python_version}")
IF( NOT python_version_ok )
MESSAGE(FATAL_ERROR "python_version not just major and minor numbers")
ENDIF( NOT python_version_ok )
# -----------------------------------------------------------------------------
#
# Initialize list of tests as empty (added to by sub-directories below)
SET(check_depends "")
#
# sub-directories
ADD_SUBDIRECTORY(lib)
#
IF( "${check_depends}" STREQUAL "" )
MESSAGE(FATAL_ERROR "no correctnes checks are available")
ENDIF( "${check_depends}" STREQUAL "" )
#
# Add the check target
ADD_CUSTOM_TARGET(check DEPENDS ${check_depends})
MESSAGE(STATUS "make check: available")