source: stable/20130000/CMakeLists.txt @ 2907

Last change on this file since 2907 was 2907, checked in by bradbell, 7 years ago

Advance version number for next release.

ode.cpp: fix warning (missing from previous commit).

  • Property svn:keywords set to Id
File size: 14.2 KB
Line 
1# $Id: CMakeLists.txt 2907 2013-10-06 14:20:31Z bradbell $
2# -----------------------------------------------------------------------------
3# CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-13 Bradley M. Bell
4#
5# CppAD is distributed under multiple licenses. This distribution is under
6# the terms of the
7#                     Eclipse Public License Version 1.0.
8#
9# A copy of this license is included in the COPYING file of this distribution.
10# Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
11# -----------------------------------------------------------------------------
12# =============================================================================
13# Some constants
14# =============================================================================
15# Set the minimum required version of cmake for this project.
16CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
17
18# cppad_version is used by set_version.sh to get the version number.
19SET(cppad_version      "20130000.3" )
20SET(cppad_url          "http://www.coin-or.org/CppAD" )
21SET(cppad_description  "Differentiation of C++ Algorithms" )
22
23
24# Set name of this project and create the variables
25# cppad_BINARY_DIR and cppad_SOURCE_DIR.
26# project(projectname [CXX] [C] [Java])
27PROJECT(cppad)
28
29# include_directories([AFTER|BEFORE] [SYSTEM] dir1 dir2 ...)
30INCLUDE_DIRECTORIES( ${cppad_SOURCE_DIR} )
31# =============================================================================
32# Some cmake language extensions
33# =============================================================================
34# CHECK_CXX_SOURCE_COMPILES(source variable)
35# Checks whether the code given in source will compile, link and run and
36# return zero status. You can set
37# CMAKE_REQUIRED_LIBRARIES, CMAKE_REQUIRED_FLAGS and CMAKE_REQUIRED_INCLUDES
38# accordingly if additional libraries or compiler flags are required.
39INCLUDE(CheckCXXSourceRuns)
40# =============================================================================
41# Some macros
42# =============================================================================
43# dos_path_to_unix
44#
45# Set the unix_variable to the dos_path but with \ replaced by /
46MACRO(dos_path_to_unix dos_constant unix_variable )
47        STRING(REGEX REPLACE "[\\]" "/" ${unix_variable} "${dos_constant}" )
48ENDMACRO(dos_path_to_unix dos_path unix_path)
49# -----------------------------------------------------------------------------
50# add_to_list
51#
52# Set the the list to include the value at the end. An empty original list
53# is denoted by the string value "" (the value may not be empty).
54MACRO(add_to_list variable_list constant_value )
55        IF( "${${variable_list}}" STREQUAL "" )
56                SET( ${variable_list} ${constant_value} )
57        ELSE( "${${variable_list}}" STREQUAL "" )
58                SET( ${variable_list} ${${variable_list}} ${constant_value} )
59        ENDIF( "${${variable_list}}" STREQUAL "" )
60ENDMACRO(add_to_list)
61# -----------------------------------------------------------------------------
62# command_line_arg
63#
64# Define a command line argument and set its default value
65# also echo it in the cmake status output.
66MACRO(command_line_arg variable default type description)
67        SET(${variable} "${default}" CACHE $type "${description}")
68        MESSAGE(STATUS "${variable} = ${${variable}}")
69ENDMACRO( command_line_arg )
70# -----------------------------------------------------------------------------
71# optional_package
72#
73# Check for package_prefix and if it is specified, set correspodong
74# include and link directories.
75MACRO(optional_package prefix_variable description)
76        SET(${prefix_variable} NOTFOUND CACHE PATH "${description}")
77        SET(prefix ${${prefix_variable}} )
78        MESSAGE(STATUS "${prefix_variable} = ${prefix}")
79        IF ( prefix )
80                # List of preprocessor include file search directories
81                FOREACH(dir ${cmake_install_includedirs})
82                        IF(IS_DIRECTORY ${prefix}/${dir} )
83                                INCLUDE_DIRECTORIES( ${prefix}/${dir} )
84                                MESSAGE(STATUS "Found ${prefix}/${dir}")
85                        ENDIF(IS_DIRECTORY ${prefix}/${dir} )
86                ENDFOREACH(dir)
87                # Paths in which the linker will search for libraries,
88                # only applies to targets created after it is called
89                FOREACH(dir ${cmake_install_libdirs})
90                        IF(IS_DIRECTORY ${prefix}/${dir} )
91                                LINK_DIRECTORIES( ${prefix}/${dir} )
92                                MESSAGE(STATUS "Found ${prefix}/${dir}")
93                        ENDIF(IS_DIRECTORY ${prefix}/${dir} )
94                ENDFOREACH(dir)
95        ENDIF ( prefix )
96ENDMACRO(optional_package)
97# -----------------------------------------------------------------------------
98# add_cppad_cxx_flags
99#
100# Add C++ compiler flags for a target, checking for special cases where
101# -Wshadow is left out.
102MACRO(add_cppad_cxx_flags target_name)
103        SET(no_shadow NO)
104        IF( ${target_name} STREQUAL example_eigen )
105                SET(no_shadow YES)
106        ENDIF( ${target_name} STREQUAL example_eigen )
107        IF( ${target_name} STREQUAL test_more_eigen )
108                SET(no_shadow YES)
109        ENDIF( ${target_name} STREQUAL test_more_eigen )
110        IF( ${target_name} STREQUAL speed_fadbad )
111                SET(no_shadow YES)
112        ENDIF( ${target_name} STREQUAL speed_fadbad )
113        IF( no_shadow )
114                SET(cxx_flags "${cppad_cxx_flags_skip_Wshadow}")
115        ELSE( no_shadow )
116                SET(cxx_flags "${cppad_cxx_flags}")
117        ENDIF( no_shadow )
118        IF( cxx_flags )
119                SET_TARGET_PROPERTIES(
120                        ${target_name} PROPERTIES COMPILE_FLAGS "${cxx_flags}"
121                )
122        ENDIF( cxx_flags )
123ENDMACRO(add_cppad_cxx_flags)
124# =============================================================================
125# command line arguments
126# =============================================================================
127# cmake_install_datadir
128command_line_arg(cmake_install_datadir share STRING
129        "directory, below prefix, where cmake installs cppad data files"
130)
131# -----------------------------------------------------------------------------
132# cmake_install_includedirs
133command_line_arg(cmake_install_includedirs include STRING
134        "directories, below prefix, where cmake installs include files"
135)
136# -----------------------------------------------------------------------------
137# cmake_install_libdirs
138command_line_arg(cmake_install_libdirs lib STRING
139        "directories, below prefix, where cmake installs library files"
140)
141# -----------------------------------------------------------------------------
142# cmake_install_prefix
143command_line_arg(cmake_install_prefix /usr PATH
144        "cppad install prefix"
145)
146SET(CMAKE_INSTALL_PREFIX "${cmake_install_prefix}"
147        CACHE PATH "value copied from cmake_install_prefix" FORCE
148)
149# -----------------------------------------------------------------------------
150# cmake_install_postfix
151command_line_arg(cmake_install_postfix NOTFOUND STRING
152        "cppad install postfix"
153)
154# -----------------------------------------------------------------------------
155# cppad_documentation
156command_line_arg(cppad_documentation NO BOOL
157        "install cppad documentation"
158)
159# -----------------------------------------------------------------------------
160# cppad_cxx_flags
161command_line_arg(cppad_cxx_flags NOTFOUND STRING
162        "extra flags used with cppad source (besides debug and release flags)"
163)
164# -----------------------------------------------------------------------------
165# External package prefixes
166#
167# adolc_prefix
168optional_package(adolc_prefix "adolc install prefix")
169#
170# eigen_prefix
171optional_package(eigen_prefix "eigen install prefix")
172#
173# fadbad_prefix
174optional_package(fadbad_prefix "fadbad install prefix")
175#
176# ipopt_prefix
177optional_package(ipopt_prefix "ipopt install prefix")
178#
179# sacado_prefix
180optional_package(sacado_prefix "sacado install prefix")
181# =============================================================================
182# automated system configuration
183# =============================================================================
184# cppad_install_includedir
185SET(cppad_install_includedir NOTFOUND)
186FOREACH(dir ${cmake_install_includedirs})
187        IF( NOT cppad_install_includedir )
188                SET(cppad_install_includedir ${dir})
189        ENDIF( NOT cppad_install_includedir )
190ENDFOREACH(dir ${cmake_install_includedirs})
191# -----------------------------------------------------------------------------
192# cppad_install_libdir
193SET(cppad_install_libdir NOTFOUND)
194FOREACH(dir ${cmake_install_libdirs})
195        IF( NOT cppad_install_libdir )
196                SET(cppad_install_libdir ${dir})
197        ENDIF( NOT cppad_install_libdir )
198ENDFOREACH(dir ${cmake_install_libdirs})
199# -----------------------------------------------------------------------------
200# cppad_cxx_flags_skip_Wshadow
201STRING(REGEX REPLACE
202        "(.*)-Wshadow(.*)"         "\\1 \\2"
203        cppad_cxx_flags_skip_Wshadow "${cppad_cxx_flags}"
204)
205MESSAGE(STATUS "cppad_cxx_flags_skip_Wshadow = ${cppad_cxx_flags_skip_Wshadow}")
206# -----------------------------------------------------------------------------
207# cppad_abs_includedir, cppad_abs_libdir, cppad_abs_datadir, cppad_abs_docdir
208IF ( cmake_install_postfix )
209        SET(cppad_abs_includedir
210"${cmake_install_prefix}/${cppad_install_includedir}/${cmake_install_postfix}"
211                CACHE INTERNAL "cppad install include file directory" FORCE
212        )
213        SET(cppad_abs_libdir
214"${cmake_install_prefix}/${cppad_install_libdir}/${cmake_install_postfix}"
215                CACHE INTERNAL "cppad install library file directory" FORCE
216        )
217        SET(cppad_abs_datadir
218"${cmake_install_prefix}/${cmake_install_datadir}/${cmake_install_postfix}"
219                CACHE INTERNAL "cppad install data file directory" FORCE
220        )
221        SET(cppad_abs_docdir
222"${cmake_install_prefix}/${cmake_install_datadir}/doc/${cmake_install_postfix}"
223                CACHE INTERNAL "cppad install data file directory" FORCE
224        )
225ELSE ( cmake_install_postfix )
226        SET(cppad_abs_includedir
227                "${cmake_install_prefix}/${cppad_install_includedir}"
228                CACHE INTERNAL "cppad install include file directory" FORCE
229        )
230        SET(cppad_abs_libdir
231                "${cmake_install_prefix}/${cppad_install_libdir}"
232                CACHE INTERNAL "cppad install library file directory" FORCE
233        )
234        SET(cppad_abs_datadir
235                "${cmake_install_prefix}/${cmake_install_datadir}"
236                CACHE INTERNAL "cppad install data file directory" FORCE
237        )
238        SET(cppad_abs_docdir
239                "${cmake_install_prefix}/${cmake_install_datadir}/doc"
240                CACHE INTERNAL "cppad install data file directory" FORCE
241        )
242ENDIF ( cmake_install_postfix )
243# -----------------------------------------------------------------------------
244# boost_prefix
245FIND_PACKAGE(Boost)
246IF ( Boost_FOUND )
247        # Extract the Boost prefix from Boost_INCLUDE_DIRS
248        #
249        # convert to using unix directory separator
250        dos_path_to_unix("${Boost_INCLUDE_DIRS}" boost_include_dirs)
251        #
252        # convert to just one directory
253        STRING(REGEX REPLACE
254                "([^ ]+).*" "\\1"
255                boost_include_dir "${boost_include_dirs}"
256        )
257        #
258        # extract part before last backslash
259        STRING(REGEX REPLACE
260                "([^ ]*)/[^/ ]*" "\\1"
261                boost_prefix "${boost_include_dir}"
262        )
263        MESSAGE(STATUS "boost_prefix = ${boost_prefix}")
264        #
265        # add boost include directories
266        FOREACH(dir ${cmake_install_includedirs})
267                IF( IS_DIRECTORY ${boost_prefix}/${dir} )
268                        INCLUDE_DIRECTORIES( ${boost_prefix}/${dir} )
269                        MESSAGE(STATUS "Found ${boost_prefix}/${dir}")
270                ENDIF( IS_DIRECTORY ${boost_prefix}/${dir} )
271        ENDFOREACH( dir )
272        #
273        # add boost link directories
274        FOREACH(dir ${cmake_install_libdirs})
275                IF( IS_DIRECTORY ${boost_prefix}/${dir} )
276                        LINK_DIRECTORIES( ${boost_prefix}/${dir} )
277                        MESSAGE(STATUS "Found ${boost_prefix}/${dir}")
278                ENDIF( IS_DIRECTORY ${boost_prefix}/${dir} )
279        ENDFOREACH( dir )
280ENDIF ( Boost_FOUND )
281# -----------------------------------------------------------------------------
282# ipopt_LIBRARIES and ipopt_LIBRARY_DIRS
283IF( ipopt_prefix )
284        FIND_PACKAGE(PkgConfig)
285        IF( NOT PKG_CONFIG_FOUND )
286                MESSAGE(FATAL_ERROR "Using ipopt_prefix but cannot find pkg-config")
287        ENDIF( NOT PKG_CONFIG_FOUND )
288        #
289        # Set the system environment variable PKG_CONFIG_PATH
290        FOREACH(dir ${cmake_install_libdirs})
291                IF(EXISTS "${ipopt_prefix}/${dir}/pkgconfig/ipopt.pc")
292                        SET( ENV{PKG_CONFIG_PATH} ${ipopt_prefix}/${dir}/pkgconfig )
293                ENDIF(EXISTS "${ipopt_prefix}/${dir}/pkgconfig/ipopt.pc")
294        ENDFOREACH(dir)
295        #
296        # pkg_check_modules(<PREFIX> [REQUIRED] <MODULE> [<MODULE>]*)
297        # ipopt_LIBRARIES      ... only the libraries (w/o the '-l')
298        # ipopt_LIBRARY_DIRS   ... the paths of the libraries (w/o the '-L')
299        pkg_check_modules(ipopt ipopt)
300        IF( NOT ipopt_FOUND )
301                MESSAGE(FATAL_ERROR
302"For all directories dir in cmake_install_libdirs, cannot find the file
303        ipopt_prefix/dir/pkgconfig/ipopt.pc
304where
305        ipopt_prefix = ${ipopt_prefix}
306        cmake_install_libdirs = ${cmake_install_libdirs}
307"
308                )
309        ENDIF( NOT ipopt_FOUND )
310ENDIF( ipopt_prefix )
311# =============================================================================
312# Currently building tests as normal executables
313# =============================================================================
314# The CMakeLists.txt file in the specified source directory is processed
315# before the current input file continues beyond this command.
316# add_subdirectory(source_dir [binary_dir] [EXCLUDE_FROM_ALL])
317#
318# Initialize list of tests as empty
319SET(list_check "")
320#
321ADD_SUBDIRECTORY(cppad)
322ADD_SUBDIRECTORY(pkgconfig)
323#
324ADD_SUBDIRECTORY(compare_c)
325add_to_list(list_check check_compare_c)
326#
327ADD_SUBDIRECTORY(example)
328add_to_list(list_check check_example)
329#
330ADD_SUBDIRECTORY(introduction)
331add_to_list(list_check check_introduction)
332#
333ADD_SUBDIRECTORY(print_for)
334add_to_list(list_check check_print_for)
335#
336ADD_SUBDIRECTORY(test_more)
337add_to_list(list_check check_test_more)
338#
339ADD_SUBDIRECTORY(multi_thread)
340add_to_list(list_check check_multi_thread)
341#
342ADD_SUBDIRECTORY(speed)
343add_to_list(list_check check_speed)
344#
345IF ( ipopt_prefix )
346        ADD_SUBDIRECTORY(cppad_ipopt)
347        add_to_list(list_check check_ipopt_nlp)
348ENDIF( ipopt_prefix )
349#
350ADD_CUSTOM_TARGET(check DEPENDS ${list_check})
351#
352# =============================================================================
353# install procedure
354# =============================================================================
355# install(DIRECTORY dirs... DESTINATION <dir>
356#       [FILE_PERMISSIONS permissions...]
357#       [DIRECTORY_PERMISSIONS permissions...]
358#       [USE_SOURCE_PERMISSIONS] [OPTIONAL]
359#       [CONFIGURATIONS [Debug|Release|...]]
360#       [COMPONENT <component>] [FILES_MATCHING]
361#       [[PATTERN <pattern> | REGEX <regex>]
362#       [EXCLUDE] [PERMISSIONS permissions...]] [...]
363# )
364# Note a trailing / in the source directory name drops the source directory
365# name during the copy.
366#
367# During install copy all ithe cppad include files to
368# ${cppad_abs_includedir}/cppad 
369INSTALL(
370        DIRECTORY "cppad/"
371        DESTINATION ${cppad_abs_includedir}/cppad
372        FILES_MATCHING PATTERN "*.h"
373)
374INSTALL(
375        DIRECTORY "cppad/"
376        DESTINATION ${cppad_abs_includedir}/cppad
377        FILES_MATCHING PATTERN "*.hpp"
378)
379#
380# During install copy doc direcrory to cppad_abs_docdir/cppad-${cppad_version} 
381IF ( cppad_documentation )
382        INSTALL( DIRECTORY "doc/" DESTINATION
383                ${cppad_abs_docdir}/cppad-${cppad_version}
384        )
385ENDIF ( cppad_documentation )
Note: See TracBrowser for help on using the repository browser.