source: trunk/CMakeLists.txt @ 3309

Last change on this file since 3309 was 3309, checked in by bradbell, 6 years ago
  1. Fix copying cppad_colpack.cpp to install directiory.
  2. Put colpack info in cppad pkgconfig file (no pkgconfig colpack file).

CMakeLists.txt: remove extra CppAD in first line of file.

  • Property svn:keywords set to Id
File size: 13.4 KB
Line 
1# $Id: CMakeLists.txt 3309 2014-05-28 00:08:58Z bradbell $
2# -----------------------------------------------------------------------------
3# CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-14 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      "20130918" )
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# Add this directory to the list of C++ preprocessor include directories
30# for the entire project.
31# include_directories([AFTER|BEFORE] [SYSTEM] dir1 dir2 ...)
32INCLUDE_DIRECTORIES( ${cppad_SOURCE_DIR} )
33
34
35
36# =============================================================================
37# Some system cmake language extensions
38# =============================================================================
39# CHECK_CXX_SOURCE_COMPILES(source variable)
40# Checks whether the code given in source will compile, link and run and
41# return zero status. You can set
42# CMAKE_REQUIRED_LIBRARIES, CMAKE_REQUIRED_FLAGS and CMAKE_REQUIRED_INCLUDES
43# accordingly if additional libraries or compiler flags are required.
44INCLUDE(CheckCXXSourceRuns)
45
46# ============================================================================
47# Some local cmake language
48# ============================================================================
49# dos_path_to_unix(dos_path unix_path)
50INCLUDE(cmake/dos_path_to_unix.cmake)
51#
52# add_to_list(variable_list constant_value)
53INCLUDE(cmake/add_to_list.cmake)
54#
55# command_line_arg(variable default type description)
56INCLUDE(cmake/command_line_arg.cmake)
57#
58# optional_package(prefix_variable description)
59INCLUDE(cmake/optional_package.cmake)
60#
61# add_cppad_cxx_flags(target_name)
62INCLUDE(cmake/add_cppad_cxx_flags.cmake)
63#
64# sources_libs_define(prefix_name sources libs define)
65INCLUDE(cmake/sources_libs_define.cmake)
66# =============================================================================
67# command line arguments
68# =============================================================================
69# cmake_install_datadir
70command_line_arg(cmake_install_datadir share STRING
71        "directory, below prefix, where cmake installs cppad data files"
72)
73# -----------------------------------------------------------------------------
74# cmake_install_docdir
75command_line_arg(cmake_install_docdir "" STRING
76        "directory, below prefix, where cmake installs cppad documentation files"
77)
78# -----------------------------------------------------------------------------
79# cmake_install_includedirs
80command_line_arg(cmake_install_includedirs include STRING
81        "directories, below prefix, where cmake installs include files"
82)
83# -----------------------------------------------------------------------------
84# cmake_install_libdirs
85command_line_arg(cmake_install_libdirs lib STRING
86        "directories, below prefix, where cmake installs library files"
87)
88# -----------------------------------------------------------------------------
89# cmake_install_prefix
90command_line_arg(cmake_install_prefix /usr PATH
91        "cppad install prefix"
92)
93SET(CMAKE_INSTALL_PREFIX "${cmake_install_prefix}"
94        CACHE PATH "value copied from cmake_install_prefix" FORCE
95)
96# -----------------------------------------------------------------------------
97# cmake_install_postfix
98command_line_arg(cmake_install_postfix NOTFOUND STRING
99        "cppad install postfix"
100)
101# -----------------------------------------------------------------------------
102# cppad_cxx_flags
103command_line_arg(cppad_cxx_flags NOTFOUND STRING
104        "extra flags used with cppad source (besides debug and release flags)"
105)
106# -----------------------------------------------------------------------------
107# cppad_documentation
108command_line_arg(cppad_documentation "" STRING
109        "install cppad documentation: use camke_install_docdir instead"
110)
111STRING(COMPARE NOTEQUAL "${cppad_documentation}" "" cppad_documentation_error)
112IF( cppad_documentation_error )
113        MESSAGE(FATAL_ERROR
114"cppad_documentation is no longer an option, use cmake_install_docdir instead"
115        )
116ENDIF( cppad_documentation_error )
117# -----------------------------------------------------------------------------
118# External package prefixes
119#
120# adolc_prefix
121optional_package(adolc_prefix "adolc install prefix")
122#
123# colpack_prefix
124optional_package(colpack_prefix "colpack install prefix")
125#
126# eigen_prefix
127optional_package(eigen_prefix "eigen install prefix")
128#
129# fadbad_prefix
130optional_package(fadbad_prefix "fadbad install prefix")
131#
132# ipopt_prefix
133optional_package(ipopt_prefix "ipopt install prefix")
134#
135# sacado_prefix
136optional_package(sacado_prefix "sacado install prefix")
137# -----------------------------------------------------------------------------
138# cppad_has_colpack
139#
140IF( colpack_prefix )
141        SET(cppad_has_colpack 1)
142ELSE( colpack_prefix )
143        SET(cppad_has_colpack 0)
144ENDIF( colpack_prefix )
145# =============================================================================
146# automated system configuration
147# =============================================================================
148# cppad_install_includedir
149SET(cppad_install_includedir NOTFOUND)
150FOREACH(dir ${cmake_install_includedirs})
151        IF( NOT cppad_install_includedir )
152                SET(cppad_install_includedir ${dir})
153        ENDIF( NOT cppad_install_includedir )
154ENDFOREACH(dir ${cmake_install_includedirs})
155# -----------------------------------------------------------------------------
156# cppad_install_libdir
157SET(cppad_install_libdir NOTFOUND)
158FOREACH(dir ${cmake_install_libdirs})
159        IF( NOT cppad_install_libdir )
160                SET(cppad_install_libdir ${dir})
161        ENDIF( NOT cppad_install_libdir )
162ENDFOREACH(dir ${cmake_install_libdirs})
163# -----------------------------------------------------------------------------
164# cppad_cxx_flags_sacado
165IF( ${cppad_cxx_flags} MATCHES ".*-std=c[+][+]11.*" )
166        SET(cppad_cxx_flags_sacado "${cppad_cxx_flags} -D HAS_C99_TR1_CMATH" )
167ELSE( ${cppad_cxx_flags} MATCHES ".*-std=c[+][+]11.*" )
168        SET(cppad_cxx_flags_sacado ${cppad_cxx_flags} )
169ENDIF( ${cppad_cxx_flags} MATCHES ".*-std=c[+][+]11.*" )
170MESSAGE(STATUS "cppad_cxx_flags_sacado = ${cppad_cxx_flags_sacado}")
171# -----------------------------------------------------------------------------
172# cppad_cxx_flags_skip_eigen
173STRING(REGEX REPLACE
174        "(.*)-Wshadow(.*)"         "\\1 \\2"
175        cppad_cxx_flags_eigen "${cppad_cxx_flags}"
176)
177MESSAGE(STATUS "cppad_cxx_flags_eigen = ${cppad_cxx_flags_eigen}")
178# -----------------------------------------------------------------------------
179# cppad_cxx_flags_skip_fadbad
180STRING(REGEX REPLACE
181        "(.*)-Wshadow(.*)"         "\\1 \\2"
182        cppad_cxx_flags_fadbad "${cppad_cxx_flags}"
183)
184MESSAGE(STATUS "cppad_cxx_flags_fadbad = ${cppad_cxx_flags_fadbad}")
185# -----------------------------------------------------------------------------
186# cppad_abs_includedir, cppad_abs_libdir, cppad_abs_datadir, cppad_abs_docdir
187#
188# cppad_abs_docdir is not used if cmake_install_docdir is ""
189#
190IF ( cmake_install_postfix )
191        SET(cppad_abs_includedir
192"${cmake_install_prefix}/${cppad_install_includedir}/${cmake_install_postfix}"
193                CACHE INTERNAL "cppad install include file directory" FORCE
194        )
195        SET(cppad_abs_libdir
196"${cmake_install_prefix}/${cppad_install_libdir}/${cmake_install_postfix}"
197                CACHE INTERNAL "cppad install library file directory" FORCE
198        )
199        SET(cppad_abs_datadir
200"${cmake_install_prefix}/${cmake_install_datadir}/${cmake_install_postfix}"
201                CACHE INTERNAL "cppad install data file directory" FORCE
202        )
203        SET(cppad_abs_docdir
204"${cmake_install_prefix}/${cmake_install_docdir}/${cmake_install_postfix}"
205                CACHE INTERNAL "cppad install data file directory" FORCE
206        )
207ELSE ( cmake_install_postfix )
208        SET(cppad_abs_includedir
209                "${cmake_install_prefix}/${cppad_install_includedir}"
210                CACHE INTERNAL "cppad install include file directory" FORCE
211        )
212        SET(cppad_abs_libdir
213                "${cmake_install_prefix}/${cppad_install_libdir}"
214                CACHE INTERNAL "cppad install library file directory" FORCE
215        )
216        SET(cppad_abs_datadir
217                "${cmake_install_prefix}/${cmake_install_datadir}"
218                CACHE INTERNAL "cppad install data file directory" FORCE
219        )
220        SET(cppad_abs_docdir
221                "${cmake_install_prefix}/${cmake_install_docdir}"
222                CACHE INTERNAL "cppad install data file directory" FORCE
223        )
224ENDIF ( cmake_install_postfix )
225# -----------------------------------------------------------------------------
226# boost_prefix
227FIND_PACKAGE(Boost)
228IF ( Boost_FOUND )
229        # Extract the Boost prefix from Boost_INCLUDE_DIRS
230        #
231        # convert to using unix directory separator
232        dos_path_to_unix("${Boost_INCLUDE_DIRS}" boost_include_dirs)
233        #
234        # convert to just one directory
235        STRING(REGEX REPLACE
236                "([^ ]+).*" "\\1"
237                boost_include_dir "${boost_include_dirs}"
238        )
239        #
240        # extract part before last backslash
241        STRING(REGEX REPLACE
242                "([^ ]*)/[^/ ]*" "\\1"
243                boost_prefix "${boost_include_dir}"
244        )
245        MESSAGE(STATUS "boost_prefix = ${boost_prefix}")
246        #
247        # add boost include directories
248        FOREACH(dir ${cmake_install_includedirs})
249                IF( IS_DIRECTORY ${boost_prefix}/${dir} )
250                        INCLUDE_DIRECTORIES( ${boost_prefix}/${dir} )
251                        MESSAGE(STATUS "Found ${boost_prefix}/${dir}")
252                ENDIF( IS_DIRECTORY ${boost_prefix}/${dir} )
253        ENDFOREACH( dir )
254        #
255        # add boost link directories
256        FOREACH(dir ${cmake_install_libdirs})
257                IF( IS_DIRECTORY ${boost_prefix}/${dir} )
258                        LINK_DIRECTORIES( ${boost_prefix}/${dir} )
259                        MESSAGE(STATUS "Found ${boost_prefix}/${dir}")
260                ENDIF( IS_DIRECTORY ${boost_prefix}/${dir} )
261        ENDFOREACH( dir )
262ENDIF ( Boost_FOUND )
263# -----------------------------------------------------------------------------
264# ipopt_LIBRARIES and ipopt_LIBRARY_DIRS
265IF( ipopt_prefix )
266        FIND_PACKAGE(PkgConfig)
267        IF( NOT PKG_CONFIG_FOUND )
268                MESSAGE(FATAL_ERROR "Using ipopt_prefix but cannot find pkg-config")
269        ENDIF( NOT PKG_CONFIG_FOUND )
270        #
271        # Set the system environment variable PKG_CONFIG_PATH
272        FOREACH(dir ${cmake_install_libdirs})
273                IF(EXISTS "${ipopt_prefix}/${dir}/pkgconfig/ipopt.pc")
274                        SET( ENV{PKG_CONFIG_PATH} ${ipopt_prefix}/${dir}/pkgconfig )
275                ENDIF(EXISTS "${ipopt_prefix}/${dir}/pkgconfig/ipopt.pc")
276        ENDFOREACH(dir)
277        #
278        # pkg_check_modules(<PREFIX> [REQUIRED] <MODULE> [<MODULE>]*)
279        # ipopt_LIBRARIES      ... only the libraries (w/o the '-l')
280        # ipopt_LIBRARY_DIRS   ... the paths of the libraries (w/o the '-L')
281        pkg_check_modules(ipopt ipopt)
282        IF( NOT ipopt_FOUND )
283                MESSAGE(FATAL_ERROR
284"For all directories dir in cmake_install_libdirs, cannot find the file
285        ipopt_prefix/dir/pkgconfig/ipopt.pc
286where
287        ipopt_prefix = ${ipopt_prefix}
288        cmake_install_libdirs = ${cmake_install_libdirs}
289"
290                )
291        ENDIF( NOT ipopt_FOUND )
292ENDIF( ipopt_prefix )
293# =============================================================================
294# Currently building tests as normal executables
295# =============================================================================
296# The CMakeLists.txt file in the specified source directory is processed
297# before the current input file continues beyond this command.
298# add_subdirectory(source_dir [binary_dir] [EXCLUDE_FROM_ALL])
299#
300# Initialize list of tests as empty
301SET(check_depends "")
302#
303ADD_SUBDIRECTORY(cppad)
304ADD_SUBDIRECTORY(pkgconfig)
305#
306ADD_SUBDIRECTORY(compare_c)
307add_to_list(check_depends check_compare_c)
308#
309ADD_SUBDIRECTORY(example)
310add_to_list(check_depends check_example)
311#
312ADD_SUBDIRECTORY(introduction)
313add_to_list(check_depends check_introduction)
314#
315ADD_SUBDIRECTORY(print_for)
316add_to_list(check_depends check_print_for)
317#
318ADD_SUBDIRECTORY(test_more)
319add_to_list(check_depends check_test_more)
320#
321ADD_SUBDIRECTORY(multi_thread)
322add_to_list(check_depends check_multi_thread)
323#
324ADD_SUBDIRECTORY(speed)
325add_to_list(check_depends check_speed)
326#
327IF ( ipopt_prefix )
328        ADD_SUBDIRECTORY(cppad_ipopt)
329        add_to_list(check_depends check_cppad_ipopt)
330ENDIF( ipopt_prefix )
331#
332ADD_CUSTOM_TARGET(check DEPENDS ${check_depends})
333#
334# =============================================================================
335# install procedure
336# =============================================================================
337# install(DIRECTORY dirs... DESTINATION <dir>
338#       [FILE_PERMISSIONS permissions...]
339#       [DIRECTORY_PERMISSIONS permissions...]
340#       [USE_SOURCE_PERMISSIONS] [OPTIONAL]
341#       [CONFIGURATIONS [Debug|Release|...]]
342#       [COMPONENT <component>] [FILES_MATCHING]
343#       [[PATTERN <pattern> | REGEX <regex>]
344#       [EXCLUDE] [PERMISSIONS permissions...]] [...]
345# )
346# Note a trailing / in the source directory name drops the source directory
347# name during the copy.
348#
349# During install copy all the cppad include files to
350# ${cppad_abs_includedir}/cppad 
351INSTALL(
352        DIRECTORY "cppad/"
353        DESTINATION ${cppad_abs_includedir}/cppad
354        FILES_MATCHING PATTERN "*.h"
355)
356INSTALL(
357        DIRECTORY "cppad/"
358        DESTINATION ${cppad_abs_includedir}/cppad
359        FILES_MATCHING PATTERN "*.hpp"
360)
361INSTALL(
362        FILES "cppad/local/cppad_colpack.cpp"
363        DESTINATION ${cppad_abs_datadir}/cppad
364)
365#
366# During install copy doc direcrory to cppad_abs_docdir/cppad
367STRING( COMPARE NOTEQUAL "${cmake_install_docdir}" "" cppad_documentation )
368IF ( cppad_documentation )
369        INSTALL( DIRECTORY "doc/" DESTINATION ${cppad_abs_docdir}/cppad )
370ENDIF ( cppad_documentation )
Note: See TracBrowser for help on using the repository browser.