ENH: Revamped docs generation
[freefoam.git] / CMakeLists.txt
blob23c50661758a838fdf6319102593e538c1c8fbad
1 #-------------------------------------------------------------------------------
2 #               ______                _     ____          __  __
3 #              |  ____|             _| |_  / __ \   /\   |  \/  |
4 #              | |__ _ __ ___  ___ /     \| |  | | /  \  | \  / |
5 #              |  __| '__/ _ \/ _ ( (| |) ) |  | |/ /\ \ | |\/| |
6 #              | |  | | |  __/  __/\_   _/| |__| / ____ \| |  | |
7 #              |_|  |_|  \___|\___|  |_|   \____/_/    \_\_|  |_|
9 #                   FreeFOAM: The Cross-Platform CFD Toolkit
11 # Copyright (C) 2008-2011 Michael Wild <themiwi@users.sf.net>
12 #                         Gerber van der Graaf <gerber_graaf@users.sf.net>
13 #-------------------------------------------------------------------------------
14 # License
15 #   This file is part of FreeFOAM.
17 #   FreeFOAM is free software; you can redistribute it and/or modify it
18 #   under the terms of the GNU General Public License as published by the
19 #   Free Software Foundation; either version 2 of the License, or (at your
20 #   option) any later version.
22 #   FreeFOAM is distributed in the hope that it will be useful, but WITHOUT
23 #   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
24 #   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
25 #   for more details.
27 #   You should have received a copy of the GNU General Public License
28 #   along with FreeFOAM; if not, write to the Free Software Foundation,
29 #   Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 #-------------------------------------------------------------------------------
32 cmake_minimum_required(VERSION 2.8.0 FATAL_ERROR)
34 project(FreeFOAM)
36 string(TOLOWER "${PROJECT_NAME}" LOWER_PROJECT_NAME)
38 # version information
39 set(FOAM_VERSION_MAJOR 0)
40 set(FOAM_VERSION_MINOR 2)
41 set(FOAM_VERSION_PATCH 0)
42 set(FOAM_VERSION ${FOAM_VERSION_MAJOR}.${FOAM_VERSION_MINOR})
43 set(FOAM_VERSION_FULL ${FOAM_VERSION}.${FOAM_VERSION_PATCH})
44 set(FOAM_SOVERSION 1)
46 # set up custom cmake module path
47 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake/Modules)
49 # utilities
50 set(FOAM_CREATE_INCLUDE_WRAPPERS TRUE)
51 set(FOAM_HAS_FLEX_SOURCES TRUE)
52 set(FOAM_ENABLE_DOC_INDEX TRUE)
53 set(FOAM_EXPORT_NAMESPACE FOAM_)
54 include(${CMAKE_SOURCE_DIR}/CMake/FOAMUtilities.cmake)
55 include(${CMAKE_SOURCE_DIR}/CMake/FOAMThirdPartyUtilities.cmake)
56 include(${CMAKE_SOURCE_DIR}/CMake/FOAMInternal.cmake)
57 include(CTest)
59 # determine computer system
60 include(${CMAKE_SOURCE_DIR}/CMake/FOAMDetermineArch.cmake)
62 # select precision
63 foam_option(FOAM_DOUBLE_PRECISION "Double precision"
64   "Compile ${PROJECT_NAME} with double precision floating point arithmetics." ON)
65 mark_as_advanced(FOAM_DOUBLE_PRECISION)
66 if(FOAM_DOUBLE_PRECISION)
67   set(FOAM_PRECISION DP)
68 else()
69   set(FOAM_PRECISION SP)
70 endif()
72 # select whether we want to build framewors on Mac OS X
73 if(APPLE)
74   foam_option(FOAM_BUILD_FRAMEWORKS "Build frameworks"
75     "Build frameworks on Mac OS X" OFF)
76   mark_as_advanced(FOAM_BUILD_FRAMEWORKS)
77 else()
78   set(FOAM_BUILD_FRAMEWORKS OFF)
79 endif()
81 # find python interpreter
82 find_package(PythonInterp REQUIRED)
84 # make sure we got Python version 2.6 or newer
85 foam_dependent_variables(PYTHON_EXECUTABLE PYTHON_VERSION)
86 if(NOT PYTHON_VERSION)
87   execute_process(
88     COMMAND ${PYTHON_EXECUTABLE} -c
89     "import sys; sys.stdout.write('%s.%s.%s\\n'%sys.version_info[0:3])"
90     RESULT_VARIABLE _py_version_result
91     OUTPUT_VARIABLE _py_version_output
92     ERROR_VARIABLE _py_version_output
93     OUTPUT_STRIP_TRAILING_WHITESPACE
94     )
95   if(NOT _py_version_result)
96     string(REGEX MATCH "([0-9]+\\.)+[0-9]+" PYTHON_VERSION "${_py_version_output}")
97     message(STATUS "Python version ${PYTHON_VERSION} found")
98     if(${PYTHON_VERSION} VERSION_LESS 2.4.0)
99       message(SEND_ERROR "Python version 2.4 or newer required")
100     endif()
101   else()
102     set(PYTHON_VERSION PYTHON_VERSION-NOTFOUND)
103     message(SEND_ERROR "Failed to determine the python version: ${_py_version_output}")
104   endif()
105   set(PYTHON_VERSION ${PYTHON_VERSION} CACHE INTERNAL "The Python version")
106 endif()
107 string(REGEX REPLACE "\\.[0-9]+$" "" PYTHON_SHORT_VERSION ${PYTHON_VERSION})
109 # find the installed ParaView executable
110 find_program(
111   FOAM_PARAVIEW3_APP NAMES "ParaView 3.8.1" "ParaView 3.8.0" ParaView paraview
112   DOC "Path to the ParaView 3.8 (or newer) application"
113   )
114 mark_as_advanced(FOAM_PARAVIEW3_APP)
115 foam_dependent_variables(FOAM_PARAVIEW3_APP FOAM_PARAVIEW3_VERSION)
116 if(FOAM_PARAVIEW3_APP)
117   if(NOT FOAM_PARAVIEW3_VERSION)
118     execute_process(COMMAND ${FOAM_PARAVIEW3_APP} --version
119       OUTPUT_VARIABLE _pv_version_output
120       ERROR_VARIABLE _pv_version_output
121       OUTPUT_STRIP_TRAILING_WHITESPACE
122       )
123     if(_pv_version_output MATCHES "ParaView(([0-9]+\\.)+[0-9]+)")
124       set(FOAM_PARAVIEW3_VERSION ${CMAKE_MATCH_1} CACHE INTERNAL
125         "The ParaView version")
126       message(STATUS
127         "ParaView ${FOAM_PARAVIEW3_VERSION} found: ${FOAM_PARAVIEW3_APP}")
128     else()
129       message(SEND_ERROR
130         "Failed to determine the ParaView version: ${_pv_version_output}")
131     endif()
132   endif()
133   if(${FOAM_PARAVIEW3_VERSION} VERSION_LESS 3.8)
134     message(WARNING
135       "ParaView versions older than 3.8 might not be able\n"
136       "to read ${PROJECT_NAME} cases.")
137   endif()
138 else()
139   message(WARNING
140     "Failed to find the ParaView application")
141   set(FOAM_PARAVIEW3_APP)
142 endif()
144 # we want shared libraries
145 set(BUILD_SHARED_LIBS SHARED)
147 # installation directories
148 foam_installation_path(FOAM_INSTALL_BIN_PATH bin "Executables"
149   "Executables installation path")
150 if(APPLE AND FOAM_BUILD_FRAMEWORKS)
151   foam_installation_path(FOAM_INSTALL_FRAMEWORK_PATH /Library/Frameworks
152     "Frameworks" "Framework installation path")
153 endif()
154 foam_installation_path(FOAM_INSTALL_LIBRARY_PATH
155   lib/${CMAKE_PROJECT_NAME}-${FOAM_VERSION_FULL}
156   "Libraries" "Library installation path")
157 if(NOT WIN32)
158   foam_installation_path(FOAM_INSTALL_PLUGIN_PATH
159     "${FOAM_INSTALL_LIBRARY_PATH_ORIG}/plugins${FOAM_SOVERSION}"
160     "Plugins" "Plugin installation path")
161 endif()
162 foam_installation_path(FOAM_INSTALL_LIBEXEC_PATH
163   libexec/${CMAKE_PROJECT_NAME}-${FOAM_VERSION_FULL} "Private executables"
164   "Installation path for executables not on PATH.")
165 foam_installation_path(FOAM_INSTALL_HEADER_PATH
166   include/${CMAKE_PROJECT_NAME}-${FOAM_VERSION_FULL}
167   "Headers" "Header installation path (not for frameworks)")
168 foam_installation_path(FOAM_INSTALL_CONFIG_PATH
169   etc/${CMAKE_PROJECT_NAME}/${FOAM_VERSION_FULL} "Config files"
170   "Configuration files installation path")
171 foam_installation_path(FOAM_INSTALL_DATA_PATH
172   share/${CMAKE_PROJECT_NAME}-${FOAM_VERSION_FULL} "Data files"
173   "Data files installation path")
174 foam_installation_path(FOAM_INSTALL_DOC_PATH
175   share/doc/${CMAKE_PROJECT_NAME}-${FOAM_VERSION_FULL} "Documentation"
176   "Documentation files installation path")
177 foam_installation_path(FOAM_INSTALL_MAN_PATH share/man "Man pages"
178   "Man-pages installation path")
179 foam_installation_path(FOAM_INSTALL_TUTORIALS_PATH
180   "${FOAM_INSTALL_DOC_PATH_ORIG}" "Tutorials" "Tutorials installation path")
181 foam_installation_path(FOAM_INSTALL_CMAKE_PATH
182   "${FOAM_INSTALL_DATA_PATH_ORIG}/CMake"
183   "CMake files" "CMake configuration files installation path")
184 foam_installation_path(FOAM_INSTALL_USERDFOAM_PATH
185   "${FOAM_INSTALL_PLUGIN_PATH_ORIG}/ensightReader"
186   "Ensight plugin" "Ensight OpenFOAM-reader plugin installation path")
187 foam_installation_path(FOAM_INSTALL_PYTHON_PATH
188   "lib/python${PYTHON_SHORT_VERSION}/site-packages"
189   "Python modules" "Python modules installation base path")
191 set(FOAM_INSTALL_RUNTIME_PATH "${FOAM_INSTALL_LIBEXEC_PATH}")
193 # determine the INSTALL_NAME_DIR of potential frameworks
194 if(APPLE AND FOAM_BUILD_FRAMEWORKS)
195   set(FOAM_FRAMEWORK_INSTALL_NAME_DIR "${FOAM_INSTALL_FRAMEWORK_PATH}")
196 else()
197   set(FOAM_FRAMEWORK_INSTALL_NAME_DIR "${FOAM_INSTALL_LIBRARY_PATH}")
198 endif()
200 # select html documentation browser (try a few well known ones for default)
201 # have to loop, because find_program(HTML_DOC_BROWSER NAMES ...) garbles things
202 # up
203 set(_BROWSERS xdg-open sensible-browser x-www-browser gnome-open kde-open
204   firefox chromium-browser epiphany konqueror www-browser w3m lynx launch)
205 if(APPLE)
206   list(INSERT _BROWSERS 0 open)
207 endif()
208 foreach(browser IN LISTS _BROWSERS)
209   find_program(HTML_DOC_BROWSER ${browser}
210     DOC "Program to open an HTML file")
211   if(HTML_DOC_BROWSER)
212     break()
213   endif()
214 endforeach()
215 if(NOT HTML_DOC_BROWSER)
216   message(STATUS
217     "Failed to find a program to open HTML pages with (a.k.a a browser).\n"
218     "Point HTML_DOC_BROWSER to a suitable program.")
219   set(HTML_DOC_BROWSER "ECHO" CACHE STRING
220     "Command to open an HTML file (ECHO will print it to STDOUT)" FORCE)
221 endif()
222 set(FOAM_HTML_DOC_BROWSER_COMMAND
223   "\${HTML_DOC_BROWSER} %f" CACHE STRING "Command to open an HTML file")
224 string(CONFIGURE "${FOAM_HTML_DOC_BROWSER_COMMAND}"
225   FOAM_HTML_DOC_BROWSER_COMMAND ESCAPE_QUOTES)
226 mark_as_advanced(HTML_DOC_BROWSER FOAM_HTML_DOC_BROWSER_COMMAND)
228 # Executable-prefix
229 string(TOLOWER "${PROJECT_NAME}-" _FOAM_DEFAULT_EXE_PREFIX)
230 set(FOAM_EXE_PREFIX "${_FOAM_DEFAULT_EXE_PREFIX}"
231   CACHE STRING "Prefix for application output-names")
232 mark_as_advanced(FOAM_EXE_PREFIX)
233 string(TOUPPER "${FOAM_EXE_PREFIX}" FOAM_UPPER_EXE_PREFIX)
235 # ask user whether she wants to build Doxygen docs
236 foam_option(FOAM_ENABLE_DOXYGEN_DOCS "Doxygen API documentation"
237   "Build the Doxygen API documentation" OFF)
238 # make sure only ON and OFF are used
239 if(FOAM_ENABLE_DOXYGEN_DOCS)
240   set(FOAM_ENABLE_DOXYGEN_DOCS ON)
241 else()
242   set(FOAM_ENABLE_DOXYGEN_DOCS OFF)
243 endif()
244 # if user wants doxygen docs, find Doxygen and set up some options
245 if(FOAM_ENABLE_DOXYGEN_DOCS)
246   find_package(Doxygen REQUIRED)
247   execute_process(COMMAND ${DOXYGEN_EXECUTABLE} --version
248     RESULT_VARIABLE DOXYGEN_VERSION_RESULT
249     OUTPUT_VARIABLE DOXYGEN_VERSION_OUTPUT
250     OUTPUT_STRIP_TRAILING_WHITESPACE)
251   if(DOXYGEN_VERSION_RESULT)
252     message(SEND_ERROR "Failed to determine doxygen version")
253   endif()
254   if(${DOXYGEN_VERSION_OUTPUT} VERSION_GREATER 1.6.3 AND
255       ${DOXYGEN_VERSION_OUTPUT} VERSION_LESS 1.7.2-20101106)
256     message(WARNING
257       "Found Doxygen version ${DOXYGEN_VERSION_OUTPUT}. "
258       "Versions newer than 1.6.3 and older than 1.7.2-20101106 "
259       "usually crash when processing the ${PROJECT_NAME} documentation.")
260   endif()
261   # ask user whether she prefers local or www docs
262   foam_option(FOAM_USE_LOCAL_DOXYGEN_DOCS "Use local API docs"
263     "Use the local Doxygen documentation instead of the one on http://freefoam.sf.net/doc/API" ON)
264   mark_as_advanced(FOAM_USE_LOCAL_DOXYGEN_DOCS)
265 endif()
267 # ask user whether she wants to build the man pages
268 foam_option(FOAM_ENABLE_MANPAGE_HELP "Build manpage help"
269   "Build the manpages (requires asciidoc)" OFF)
270 # ask user whether she wants to build the xhtml man pages
271 foam_option(FOAM_ENABLE_XHTML_HELP "Build xhtml help"
272   "Build the xhtml help pages (requires asciidoc)" OFF)
273 # as user whether she wanst to build the xhtml guides
274 foam_option(FOAM_ENABLE_XHTML_GUIDES "Build the xhtml guides"
275   "Build the xhtml guides (requires asciidoc, dot, inkscape and asymptote)" OFF)
276 # as user whether she wanst to build the xhtml guides
277 foam_option(FOAM_ENABLE_PDF_GUIDES "Build the PDF guides"
278   "Build the PDF guides (requires asciidoc, dot, inkscape and asymptote)" OFF)
279 if(FOAM_ENABLE_PDF_GUIDES)
280   foam_option(FOAM_USE_FOP "Use FOP instead of dblatex"
281     "Use FOP to build the PDF guides instead of dblatex" OFF)
282   mark_as_advanced(FOAM_USE_FOP)
283 else()
284   set(FOAM_USE_FOP FALSE)
285 endif()
287 if(FOAM_ENABLE_DOXYGEN_DOCS OR FOAM_ENABLE_XHTML_GUIDES)
288   foam_option(FOAM_DOCS_FOR_SF "Docs for SourceForge"
289     "Build the docs for deployment on SourceForge" OFF)
290   mark_as_advanced(FOAM_DOCS_FOR_SF)
291   # make sure only ON and OFF are used
292   if(FOAM_DOCS_FOR_SF)
293     set(FOAM_DOCS_FOR_SF ON)
294   else()
295     set(FOAM_DOCS_FOR_SF OFF)
296   endif()
297 endif()
299 if(BUILD_TESTING)
300   # ask user whether whe wants full tutorial tests
301   foam_option(FOAM_ENABLE_FULL_TUTORIAL_TESTS
302     "Full tutorial tests"
303     "Run the complete tutorial tests (not just a single time step)" OFF)
304 endif()
306 foam_option(FOAM_ENABLE_CPACK "CPack packaging"
307   "Enable CPack packaging support" OFF)
308 mark_as_advanced(FOAM_ENABLE_CPACK)
310 if(FOAM_ENABLE_XHTML_GUIDES)
311   set(FOAM_ENABLE_XHTML_GUIDES ON)
312   foam_option(FOAM_ENABLE_MATHJAX "Use MathJax in XHTML guides"
313     "Use MathJax for formulas in the XHTML version of the guides" ON)
314   if(FOAM_ENABLE_MATHJAX)
315     foam_option(FOAM_MATHJAX_USE_CDN
316       "Use the MathJax CDN"
317       "Use public MathJax installation at http://cdn.mathjax.org" ON)
318     mark_as_advanced(FOAM_MATHJAX_USE_CDN)
319     if(FOAM_MATHJAX_USE_CDN)
320       set(FOAM_MATHJAX_URL "http://cdn.mathjax.org/mathjax/latest")
321     else()
322       set(FOAM_MATHJAX_URL "MathJAX-NOTFOUND" CACHE PATH
323         "Path or URL to the MathJax directory containing the MathJax.js file")
324       mark_as_advanced(FOAM_MATHJAX_URL)
325       if(NOT FOAM_MATHJAX_URL)
326         message(SEND_ERROR "FOAM_MATHJAX_URL must be set to the directory or "
327           "URL containing MathJax.js")
328       endif()
329     endif()
330   endif()
331 else()
332   set(FOAM_ENABLE_XHTML_GUIDES OFF)
333   set(FOAM_ENABLE_MATHJAX FALSE)
334 endif()
336 # assemble the list of enabled manpage formats
337 set(FOAM_MANPAGE_FORMATS)
338 if(FOAM_ENABLE_MANPAGE_HELP)
339   list(APPEND FOAM_MANPAGE_FORMATS manpage)
340 endif()
341 if(FOAM_ENABLE_XHTML_HELP)
342   list(APPEND FOAM_MANPAGE_FORMATS xhtml)
343 endif()
345 # assemble the list of enabled guides formats
346 set(FOAM_GUIDES_FORMATS)
347 if(FOAM_ENABLE_XHTML_GUIDES)
348   list(APPEND FOAM_GUIDES_FORMATS xhtml)
349 endif()
350 if(FOAM_ENABLE_PDF_GUIDES)
351   list(APPEND FOAM_GUIDES_FORMATS pdf)
352 endif()
354 if(FOAM_MANPAGE_FORMATS OR FOAM_ENABLE_CPACK OR FOAM_GUIDES_FORMATS)
355   # find AsciiDoc
356   find_program(ASCIIDOC_EXECUTABLE NAMES asciidoc.py asciidoc)
357   get_filename_component(asciidoc_path "${ASCIIDOC_EXECUTABLE}" PATH)
358   find_program(A2X_EXECUTABLE NAMES a2x.py a2x HINTS "${asciidoc_path}")
359   if(NOT ASCIIDOC_EXECUTABLE OR NOT A2X_EXECUTABLE)
360     message(SEND_ERROR
361       "AsciiDoc is required to create man and html help and the guides")
362   endif()
363   mark_as_advanced(ASCIIDOC_EXECUTABLE A2X_EXECUTABLE)
364   # read CONF_DIR from A2X_EXECUTABLE and copy style files over
365   if(A2X_EXECUTABLE)
366     file(READ "${A2X_EXECUTABLE}" _asciidoc_text)
367     if(_asciidoc_text MATCHES "[ \t]*CONF_DIR[ \t]*=[ \t]*r?['\"]([^'\"]+)")
368       set(A2X_CONF_DIR "${CMAKE_MATCH_1}")
369       if(IS_DIRECTORY "${A2X_CONF_DIR}")
370         configure_file("${A2X_CONF_DIR}/docbook-xsl/common.xsl"
371           "${CMAKE_BINARY_DIR}/data/asciidoc/docbook-xsl/orig-common.xsl"
372           COPYONLY)
373         configure_file("${A2X_CONF_DIR}/docbook-xsl/chunked.xsl"
374           "${CMAKE_BINARY_DIR}/data/asciidoc/docbook-xsl/orig-chunked.xsl"
375           COPYONLY)
376         configure_file("${A2X_CONF_DIR}/docbook-xsl/xhtml.xsl"
377           "${CMAKE_BINARY_DIR}/data/asciidoc/docbook-xsl/orig-xhtml.xsl"
378           COPYONLY)
379         configure_file("${A2X_CONF_DIR}/dblatex/asciidoc-dblatex.sty"
380           "${CMAKE_BINARY_DIR}/data/asciidoc/dblatex/orig-asciidoc-dblatex.sty"
381           COPYONLY)
382         configure_file("${A2X_CONF_DIR}/dblatex/asciidoc-dblatex.xsl"
383           "${CMAKE_BINARY_DIR}/data/asciidoc/dblatex/orig-asciidoc-dblatex.xsl"
384           COPYONLY)
385       else()
386         message(SEND_ERROR "The Asciidoc configuration directory "
387           "${A2X_CONF_DIR} does not exist")
388       endif()
389     else()
390       message(SEND_ERROR "Failed to read CONF_DIR from ${A2X_EXECUTABLE}")
391     endif()
392   endif()
393   set(FOAM_NEED_PNGMATH FALSE)
394   if((FOAM_ENABLE_XHTML_GUIDES AND NOT FOAM_ENABLE_MATHJAX) OR
395     (FOAM_ENABLE_PDF_GUIES AND FOAM_USE_FOP))
396     set(FOAM_NEED_PNGMATH TRUE)
397     foreach(prog latex dvipng)
398       string(TOUPPER ${prog} uprog)
399       find_program(${uprog}_EXECUTABLE ${prog})
400       mark_as_advanced(${uprog}_EXECUTABLE)
401       if(NOT ${uprog}_EXECUTABLE)
402         message(SEND_ERROR
403           "${prog} is required when FOAM_ENABLE_MATHJAX is disabled "
404           "or FOAM_USE_FOP is enabled")
405       endif()
406     endforeach()
407   endif()
408 endif()
409 if(FOAM_GUIDES_FORMATS)
410   # find asymptote
411   find_program(ASY_EXECUTABLE asy)
412   if(NOT ASY_EXECUTABLE)
413     message(SEND_ERROR "Asymptote is required to create the guides")
414   endif()
415   mark_as_advanced(ASY_EXECUTABLE)
416 endif()
418 # set up the RPATH for installation
419 set(CMAKE_INSTALL_RPATH ${FOAM_INSTALL_LIBRARY_PATH})
420 set(CMAKE_INSTALL_NAME_DIR ${FOAM_FRAMEWORK_INSTALL_NAME_DIR})
422 # we want executables and libraries in uniform places
423 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
424   "${CMAKE_BINARY_DIR}/libexec/${PROJECT_NAME}/${FOAM_VERSION_FULL}")
425 set(FOAM_LIBRARY_OUTPUT_DIRECTORY
426   "${CMAKE_BINARY_DIR}/lib/${PROJECT_NAME}-${FOAM_VERSION_FULL}")
427 set(FOAM_FRAMEWORK_OUTPUT_DIRECTORY
428   "${CMAKE_BINARY_DIR}/Library/Frameworks")
429 if(FOAM_BUILD_FRAMEWORKS)
430   set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${FOAM_FRAMEWORK_OUTPUT_DIRECTORY}")
431 else()
432   set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${FOAM_LIBRARY_OUTPUT_DIRECTORY}")
433 endif()
434 set(FOAM_ARCHIVE_OUTPUT_DIRECTORY "${FOAM_LIBRARY_OUTPUT_DIRECTORY}")
436 # find parallel libraries
437 find_package(MPI)
438 if(MPI_FOUND)
439   set(_FOAM_USE_MPI ON)
440 else()
441   set(_FOAM_USE_MPI OFF)
442 endif()
443 foam_option(FOAM_USE_MPI "Use MPI"
444   "Build ${CMAKE_PROJECT} against MPI parallel libraries" ${_FOAM_USE_MPI})
445 mark_as_advanced(FOAM_USE_MPI)
446 if(FOAM_USE_MPI AND NOT MPI_FOUND)
447   message(SEND_ERROR
448     "FOAM_ENABLE_MPI is true, but MPI cannot be found.\n"
449     "If you have MPI installed on your system, edit the variables\n"
450     "MPI_INCLUDE_DIR and MPI_LIBRARY in the cache, else disable the\n"
451     "setting FOAM_USE_MPI."
452   )
453 endif()
455 # find readline
456 find_package(Readline)
458 # substitution for build-tree and install-tree as used by
459 # foam_configure_files.
460 set(FOAM_CONFIGURE_FILES_VARIABLES
461   FOAM_DATA_DIR
462     "${CMAKE_BINARY_DIR}/data"
463     "${FOAM_INSTALL_DATA_PATH}"
464   FOAM_LOCAL_DOC_DIR
465     "${CMAKE_BINARY_DIR}/doc"
466     "${FOAM_INSTALL_DOC_PATH}"
467   FOAM_BIN_DIR
468     "${CMAKE_BINARY_DIR}/bin"
469     "${FOAM_INSTALL_BIN_PATH}"
470   FOAM_LIB_DIR
471     "${CMAKE_BINARY_DIR}/lib/FreeFOAM-${FOAM_VERSION_FULL}"
472     "${FOAM_INSTALL_LIBRARY_PATH}"
473   FOAM_LIBEXEC_DIR
474     "${CMAKE_BINARY_DIR}/libexec/FreeFOAM/${FOAM_VERSION_FULL}"
475     "${FOAM_INSTALL_LIBEXEC_PATH}"
476   FOAM_FRAMEWORK_DIR
477     "${CMAKE_BINARY_DIR}/Library/Frameworks"
478     "${FOAM_INSTALL_FRAMEWORK_PATH}"
479   FOAM_INCLUDE_DIR
480     "${CMAKE_BINARY_DIR}/include"
481     "${FOAM_INSTALL_HEADER_PATH}"
482   FOAM_CONFIG_DIR
483     "${CMAKE_BINARY_DIR}/etc"
484     "${FOAM_INSTALL_CONFIG_PATH}"
485   FOAM_CMAKECONFIG_DIR
486     "${CMAKE_BINARY_DIR}/CMake"
487     "${FOAM_INSTALL_CMAKE_PATH}"
488   FOAM_PYTHON_DIR
489     "${CMAKE_BINARY_DIR}/data/python"
490     "${FOAM_INSTALL_PYTHON_PATH}"
491   FOAM_IS_INSTALLED
492     "FALSE"
493     "TRUE"
494   )
495 if(WIN32)
496   list(APPEND FOAM_CONFIGURE_FILES_VARIABLES
497     FOAM_PLUGIN_DIR
498       "${CMAKE_BINARY_DIR}/lib/FreeFOAM-${FOAM_VERSION_FULL}"
499       "${FOAM_INSTALL_LIBRARY_PATH}")
500 else()
501   list(APPEND FOAM_CONFIGURE_FILES_VARIABLES
502     FOAM_PLUGIN_DIR
503       "${CMAKE_BINARY_DIR}/lib/FreeFOAM-${FOAM_VERSION_FULL}/plugins"
504       "${FOAM_INSTALL_PLUGIN_PATH}")
505 endif()
506 if(FOAM_USE_LOCAL_DOXYGEN_DOCS)
507   list(APPEND FOAM_CONFIGURE_FILES_VARIABLES
508     FOAM_DOC_DIR "${CMAKE_BINARY_DIR}/doc" "${FOAM_INSTALL_DOC_PATH}")
509 else()
510   set(_sf_doc "http://freefoam.sf.net/doc/${FOAM_VERSION_FULL}")
511   list(APPEND FOAM_CONFIGURE_FILES_VARIABLES
512     FOAM_DOC_DIR "${_sf_doc}" "${_sf_doc}")
513 endif()
515 # thirdparty libraries
516 foam_thirdparty_option(Metis
517   "Required by the metis decomposition method"
518   Metis TRUE ON)
519 if(FOAM_ENABLE_METIS)
520   if(FOAM_ENABLE_METIS AND METIS_REQUIRES_MPI AND NOT FOAM_USE_MPI)
521     message(SEND_ERROR
522       "Your metis implementation requires FOAM_USE_MPI to be enabled."
523       "If you don't have/want MPI, enable FOAM_BUILD_PRIVATE_METIS instead.")
524   endif()
525 endif()
526 foam_thirdparty_option(ParMetis
527   "Required by the parmetis decomposition method"
528   ParMetis TRUE ${FOAM_USE_MPI}
529   PARMETIS_metis_LIBRARY PARMETIS_parmetis_LIBRARY)
530 if(FOAM_ENABLE_PARMETIS AND NOT FOAM_USE_MPI)
531   message(SEND_ERROR
532     "ParMetis requires FOAM_USE_MPI to be enabled.")
533 endif()
534 if(FOAM_ENABLE_PARMETIS AND NOT FOAM_ENABLE_METIS)
535   message(SEND_ERROR
536     "ParMetis requires FOAM_ENABLE_METIS to be enabled.")
537 endif()
538 set(SCOTCH_USE_ERREXIT TRUE)
539 foam_thirdparty_option(SCOTCH "" SCOTCH FALSE ON SCOTCH_scotch_LIBRARY
540   SCOTCH_scotcherr_LIBRARY SCOTCH_scotcherrexit_LIBRARY)
541 # do not enable mgridgen by default (licensing issues)
542 if(NOT FOAM_DOUBLE_PRECISION)
543   set(MGRIDGEN_USE_REAL ON)
544 endif()
545 foam_thirdparty_option(MGRIDGEN
546   "Required by the MGridGen GAMG agglomerator. LICENSE UNCLEAR"
547   MGRIDGEN TRUE OFF)
548 # do not enable libccmio by default (licensing issues)
549 foam_thirdparty_option(ccmio
550   "Required by ccm26ToFoam. REQUIRES PERMISSION BY CDADAPCO!"
551   Ccmio TRUE OFF)
552 foam_thirdparty_option(zlib "" ZLIB FALSE ON)
554 # figure out default Pstream library
555 if(FOAM_USE_MPI)
556   set(_FOAM_DEFAULT_PSTREAM mpi)
557 else()
558   set(_FOAM_DEFAULT_PSTREAM dummy)
559 endif()
560 set(FOAM_DEFAULT_PSTREAM ${_FOAM_DEFAULT_PSTREAM} CACHE STRING
561   "Default Pstream library implementation [dummy|mpi]")
562 mark_as_advanced(FOAM_DEFAULT_PSTREAM)
564 # find m4 macro processor
565 find_program(M4_EXECUTABLE m4 DOC "Path to the m4 macro processor")
566 mark_as_advanced(M4_EXECUTABLE)
567 if(NOT M4_EXECUTABLE)
568   message("WARNING: Failed to find M4 macro processor.\n"
569     "Some of the tutorials will fail if it can't be found.")
570   set(M4_EXECUTABLE m4)
571 endif()
573 # on APPLE use cp -R -P -p, otherwise use cp -a
574 if(APPLE)
575   set(FOAM_CP_A_FLAGS "-R -P -p")
576 else()
577   set(FOAM_CP_A_FLAGS "-a")
578 endif()
580 # execinfo.h and cxxabi.h only work using GNU gcc and Debug config
581 # assume that if we have execinfo.h, cxxabi.h is also present.
582 if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_BUILD_TYPE STREQUAL Debug)
583   find_package(Execinfo)
584 endif()
586 # create the FOAMConfig.h file
587 configure_file(${CMAKE_SOURCE_DIR}/FOAMConfig.h.in
588   ${CMAKE_BINARY_DIR}/include/FOAMConfig.h @ONLY)
590 # on Solaris/SunOS fix up the shebangs
591 if(CMAKE_SYSTEM_NAME STREQUAL SunOS AND NOT EXISTS ${CMAKE_BINARY_DIR}/replaceAllShellSun.run)
592   message(STATUS "Fixing shell-interpreter for SunOS and Solaris")
593   execute_process(
594     COMMAND ${CMAKE_SOURCE_DIR}/data/utilities/replaceAllShellSun bin
595     COMMAND ${CMAKE_SOURCE_DIR}/data/utilities/replaceAllShellSun data
596     COMMAND ${CMAKE_SOURCE_DIR}/data/utilities/replaceAllShellSun tutorials
597     COMMAND ${CMAKE_SOURCE_DIR}/data/utilities/replaceAllShellSun doc
598     COMMAND ${CMAKE_COMMAND} -E touch${CMAKE_BINARY_DIR}/replaceAllShellSun.run
599     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
600     )
601 endif()
603 # set up defines
604 set(FOAM_COMPILE_DEFINITIONS
605   -D${FOAM_PRECISION}
606   -DNoRepository
607   -D${FOAM_OS}
608   )
609 if(APPLE)
610   list(APPEND FOAM_COMPILE_DEFINITIONS -Ddarwin)
611 endif()
612 add_definitions(${FOAM_COMPILE_DEFINITIONS})
614 # set up include-directories for own headers
615 include_directories(${CMAKE_BINARY_DIR}/include)
617 # descend into the sources...
618 add_subdirectory(bin)
619 add_subdirectory(etc)
620 add_subdirectory(data)
621 add_subdirectory(src)
622 add_subdirectory(applications)
623 add_subdirectory(tutorials)
624 # doc *must* be last, else manpage and Doxygen generation fails
625 add_subdirectory(doc)
627 # export the library dependencies to the build tree
628 foam_export_targets_to_build_tree(${PROJECT_NAME}LibraryDepends)
629 export(PACKAGE ${PROJECT_NAME})
631 # write the doc index file and install it
632 foam_write_doc_index()
633 install(FILES
634   ${CMAKE_BINARY_DIR}/InstallFiles/data/DoxyDocIndex
635   DESTINATION ${FOAM_INSTALL_DATA_PATH}
636   COMPONENT data
637   )
639 # create ${PROJECT_NAME}Config.cmake ${PROJECT_NAME}Use.cmake,
640 # ${PROJECT_NAME}Utilities.cmake and ${PROJECT_NAME}WmakeCompatibility.cmake
641 # for the build and install tree
642 foam_configure_files(ConfigInstallFiles
643   "CMake/FOAMConfig.cmake.in==CMake/${PROJECT_NAME}Config.cmake"
644   "CMake/FOAMUse.cmake.in==CMake/${PROJECT_NAME}Use.cmake"
645   "CMake/FOAMWmakeCompatibility.cmake.in==CMake/${PROJECT_NAME}WmakeCompatibility.cmake"
646   COPYONLY
647   "CMake/FOAMUtilities.cmake==CMake/${PROJECT_NAME}Utilities.cmake"
648   )
650 # install the CMake config files
651 install(FILES
652   ${ConfigInstallFiles}
653   DESTINATION ${FOAM_INSTALL_CMAKE_PATH}
654   COMPONENT dev
655   )
657 # install the ${PROJECT_NAME}LibraryDepends.cmake file
658 install(EXPORT ${PROJECT_NAME}LibraryDepends
659   DESTINATION ${FOAM_INSTALL_CMAKE_PATH}
660   NAMESPACE FOAM_
661   COMPONENT dev
662   )
664 # pack things up
665 if(FOAM_ENABLE_CPACK)
666   include(${CMAKE_SOURCE_DIR}/CMake/FOAMCPack.cmake)
667 endif()
669 # uninstall target
670 configure_file(
671   "${CMAKE_SOURCE_DIR}/CMake/Modules/cmake_uninstall.cmake.in"
672   "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake"
673   @ONLY
674   )
676 add_custom_target(uninstall
677   "${CMAKE_COMMAND}" -P "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake"
678   )
680 # print cool feature summary
681 foam_print_feature_summary()
683 # ------------------------- vim: set sw=2 sts=2 et: --------------- end-of-file