FIX: Directly use asciidoc+xsltproc for UserGuide-xhtml
[freefoam.git] / CMakeLists.txt
blob48245fca38415b62669aec9fd1bc6c2985c5dbee
1 #-------------------------------------------------------------------------------
2 #               ______                _     ____          __  __
3 #              |  ____|             _| |_  / __ \   /\   |  \/  |
4 #              | |__ _ __ ___  ___ /     \| |  | | /  \  | \  / |
5 #              |  __| '__/ _ \/ _ ( (| |) ) |  | |/ /\ \ | |\/| |
6 #              | |  | | |  __/  __/\_   _/| |__| / ____ \| |  | |
7 #              |_|  |_|  \___|\___|  |_|   \____/_/    \_\_|  |_|
9 #                   FreeFOAM: The Cross-Platform CFD Toolkit
11 # Copyright (C) 2008-2012 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 3 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, see <http://www.gnu.org/licenses/>.
29 #-------------------------------------------------------------------------------
31 cmake_minimum_required(VERSION 2.8.2 FATAL_ERROR)
33 project(FreeFOAM)
35 string(TOLOWER "${PROJECT_NAME}" LOWER_PROJECT_NAME)
37 # version information
38 set(FOAM_VERSION_MAJOR 0)
39 set(FOAM_VERSION_MINOR 1)
40 set(FOAM_VERSION_PATCH 0)
41 set(FOAM_VERSION_SUFFIX rc7)
42 set(FOAM_VERSION ${FOAM_VERSION_MAJOR}.${FOAM_VERSION_MINOR})
43 set(FOAM_VERSION_FULL
44   ${FOAM_VERSION}.${FOAM_VERSION_PATCH}${FOAM_VERSION_SUFFIX})
45 set(FOAM_SOVERSION 1)
46 set(FOAM_UPSTREAM_VERSION_FULL 1.7.x-d08d3c2)
48 # set up custom cmake module path
49 set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake/Modules)
51 # utilities
52 set(FOAM_CREATE_INCLUDE_WRAPPERS TRUE)
53 set(FOAM_HAS_FLEX_SOURCES TRUE)
54 set(FOAM_ENABLE_DOC_INDEX TRUE)
55 set(FOAM_EXPORT_NAMESPACE FOAM_)
56 include(${CMAKE_SOURCE_DIR}/CMake/FOAMUtilities.cmake)
57 include(${CMAKE_SOURCE_DIR}/CMake/FOAMThirdPartyUtilities.cmake)
58 include(${CMAKE_SOURCE_DIR}/CMake/FOAMInternal.cmake)
59 include(CTest)
61 # determine computer system
62 include(${CMAKE_SOURCE_DIR}/CMake/FOAMDetermineArch.cmake)
64 # select precision
65 foam_option(FOAM_DOUBLE_PRECISION "Double precision"
66   "Compile ${PROJECT_NAME} with double precision floating point arithmetics."
67   ON)
68 mark_as_advanced(FOAM_DOUBLE_PRECISION)
69 if(FOAM_DOUBLE_PRECISION)
70   set(FOAM_PRECISION DP)
71 else()
72   set(FOAM_PRECISION SP)
73 endif()
75 # select whether we want to build framewors on Mac OS X
76 if(APPLE)
77   foam_option(FOAM_BUILD_FRAMEWORKS "Build frameworks"
78     "Build frameworks on Mac OS X" OFF)
79   mark_as_advanced(FOAM_BUILD_FRAMEWORKS)
80 else()
81   set(FOAM_BUILD_FRAMEWORKS OFF)
82 endif()
84 # find python interpreter
85 find_package(PythonInterp REQUIRED)
87 # make sure we got Python version 2.6 or newer
88 foam_dependent_variables(PYTHON_EXECUTABLE PYTHON_VERSION)
89 if(NOT PYTHON_VERSION)
90   execute_process(
91     COMMAND ${PYTHON_EXECUTABLE} -c
92     "import sys; sys.stdout.write('%s.%s.%s\\n'%sys.version_info[0:3])"
93     RESULT_VARIABLE _py_version_result
94     OUTPUT_VARIABLE _py_version_output
95     ERROR_VARIABLE _py_version_output
96     OUTPUT_STRIP_TRAILING_WHITESPACE
97     )
98   if(NOT _py_version_result)
99     string(REGEX MATCH "([0-9]+\\.)+[0-9]+" PYTHON_VERSION
100       "${_py_version_output}")
101     message(STATUS "Python version ${PYTHON_VERSION} found")
102     if(${PYTHON_VERSION} VERSION_LESS 2.4.0)
103       message(SEND_ERROR "Python version 2.4 or newer required")
104     endif()
105   else()
106     set(PYTHON_VERSION PYTHON_VERSION-NOTFOUND)
107     message(SEND_ERROR
108       "Failed to determine the python version: ${_py_version_output}")
109   endif()
110   set(PYTHON_VERSION ${PYTHON_VERSION} CACHE INTERNAL "The Python version")
111 endif()
112 string(REGEX REPLACE "\\.[0-9]+$" "" PYTHON_SHORT_VERSION ${PYTHON_VERSION})
114 # find the installed ParaView executable
115 find_program(
116   FOAM_PARAVIEW3_APP NAMES "ParaView 3.12.0" "ParaView 3.10.1"
117   "ParaView 3.10.0" "ParaView 3.8.1" "ParaView 3.8.0" ParaView paraview
118   DOC "Path to the ParaView 3.8 (or newer) application")
119 mark_as_advanced(FOAM_PARAVIEW3_APP)
120 foam_dependent_variables(FOAM_PARAVIEW3_APP FOAM_PARAVIEW3_VERSION)
121 if(FOAM_PARAVIEW3_APP)
122   if(NOT FOAM_PARAVIEW3_VERSION)
123     get_filename_component(_FOAM_PV3_BINDIR ${FOAM_PARAVIEW3_APP} PATH)
124     set(_FOAM_PVBATCH_EXECUTABLE ${_FOAM_PV3_BINDIR}/pvbatch)
125     if(NOT EXISTS ${_FOAM_PVBATCH_EXECUTABLE})
126       set(_FOAM_PVBATCH_EXECUTABLE ${FOAM_PARAVIEW3_APP})
127     endif()
128     execute_process(COMMAND ${_FOAM_PVBATCH_EXECUTABLE} --version
129       OUTPUT_VARIABLE _pv_version_output
130       ERROR_VARIABLE _pv_version_output
131       OUTPUT_STRIP_TRAILING_WHITESPACE
132       )
133     if(_pv_version_output MATCHES
134         "(paraview version |ParaView)(([0-9]+\\.)+[0-9]+)")
135       set(FOAM_PARAVIEW3_VERSION ${CMAKE_MATCH_2} CACHE INTERNAL
136         "The ParaView version")
137       message(STATUS
138         "ParaView ${FOAM_PARAVIEW3_VERSION} found: ${FOAM_PARAVIEW3_APP}")
139     else()
140       message(SEND_ERROR
141         "Failed to determine the ParaView version: ${_pv_version_output}")
142     endif()
143   endif()
144   if(${FOAM_PARAVIEW3_VERSION} VERSION_LESS 3.8)
145     message(WARNING
146       "ParaView versions older than 3.8 might not be able\n"
147       "to read ${PROJECT_NAME} cases.")
148   endif()
149 else()
150   message(WARNING
151     "Failed to find the ParaView application")
152   set(FOAM_PARAVIEW3_APP)
153 endif()
155 # we want shared libraries
156 set(BUILD_SHARED_LIBS SHARED)
158 # installation directories
159 foam_installation_path(FOAM_INSTALL_BIN_PATH bin "Executables"
160   "Executables installation path")
161 if(APPLE AND FOAM_BUILD_FRAMEWORKS)
162   foam_installation_path(FOAM_INSTALL_FRAMEWORK_PATH /Library/Frameworks
163     "Frameworks" "Framework installation path")
164 endif()
165 foam_installation_path(FOAM_INSTALL_LIBRARY_PATH
166   lib/${CMAKE_PROJECT_NAME}-${FOAM_VERSION_FULL}
167   "Libraries" "Library installation path")
168 if(NOT WIN32)
169   foam_installation_path(FOAM_INSTALL_PLUGIN_PATH
170     "${FOAM_INSTALL_LIBRARY_PATH_ORIG}/plugins${FOAM_SOVERSION}"
171     "Plugins" "Plugin installation path")
172 endif()
173 foam_installation_path(FOAM_INSTALL_LIBEXEC_PATH
174   libexec/${CMAKE_PROJECT_NAME}-${FOAM_VERSION_FULL} "Private executables"
175   "Installation path for executables not on PATH.")
176 foam_installation_path(FOAM_INSTALL_HEADER_PATH
177   include/${CMAKE_PROJECT_NAME}-${FOAM_VERSION_FULL}
178   "Headers" "Header installation path (not for frameworks)")
179 foam_installation_path(FOAM_INSTALL_CONFIG_PATH
180   etc/${CMAKE_PROJECT_NAME}/${FOAM_VERSION_FULL} "Config files"
181   "Configuration files installation path")
182 foam_installation_path(FOAM_INSTALL_DATA_PATH
183   share/${CMAKE_PROJECT_NAME}-${FOAM_VERSION_FULL} "Data files"
184   "Data files installation path")
185 foam_installation_path(FOAM_INSTALL_DOC_PATH
186   share/doc/${CMAKE_PROJECT_NAME}-${FOAM_VERSION_FULL} "Documentation"
187   "Documentation files installation path")
188 foam_installation_path(FOAM_INSTALL_MAN_PATH share/man "Man pages"
189   "Man-pages installation path")
190 foam_installation_path(FOAM_INSTALL_TUTORIALS_PATH
191   "${FOAM_INSTALL_DOC_PATH_ORIG}" "Tutorials" "Tutorials installation path")
192 foam_installation_path(FOAM_INSTALL_CMAKE_PATH
193   "${FOAM_INSTALL_DATA_PATH_ORIG}/CMake"
194   "CMake files" "CMake configuration files installation path")
195 foam_installation_path(FOAM_INSTALL_USERDFOAM_PATH
196   "${FOAM_INSTALL_PLUGIN_PATH_ORIG}/ensightReader"
197   "Ensight plugin" "Ensight OpenFOAM-reader plugin installation path")
198 foam_installation_path(FOAM_INSTALL_PYTHON_PATH
199   "lib/python${PYTHON_SHORT_VERSION}/site-packages"
200   "Python modules" "Python modules installation base path")
202 set(FOAM_INSTALL_RUNTIME_PATH "${FOAM_INSTALL_LIBEXEC_PATH}")
204 # determine the INSTALL_NAME_DIR of potential frameworks
205 if(APPLE AND FOAM_BUILD_FRAMEWORKS)
206   set(FOAM_FRAMEWORK_INSTALL_NAME_DIR "${FOAM_INSTALL_FRAMEWORK_PATH}")
207 else()
208   set(FOAM_FRAMEWORK_INSTALL_NAME_DIR "${FOAM_INSTALL_LIBRARY_PATH}")
209 endif()
211 # select html documentation browser (try a few well known ones for default)
212 # have to loop, because find_program(HTML_DOC_BROWSER NAMES ...) garbles things
213 # up
214 set(_BROWSERS xdg-open sensible-browser x-www-browser gnome-open kde-open
215   firefox chromium-browser epiphany konqueror www-browser w3m lynx launch)
216 if(APPLE)
217   list(INSERT _BROWSERS 0 open)
218 endif()
219 foreach(browser IN LISTS _BROWSERS)
220   find_program(HTML_DOC_BROWSER ${browser}
221     DOC "Program to open an HTML file")
222   if(HTML_DOC_BROWSER)
223     break()
224   endif()
225 endforeach()
226 if(NOT HTML_DOC_BROWSER)
227   message(STATUS
228     "Failed to find a program to open HTML pages with (a.k.a a browser).\n"
229     "Point HTML_DOC_BROWSER to a suitable program.")
230   set(HTML_DOC_BROWSER "ECHO" CACHE STRING
231     "Command to open an HTML file (ECHO will print it to STDOUT)" FORCE)
232 endif()
233 set(FOAM_HTML_DOC_BROWSER_COMMAND
234   "\${HTML_DOC_BROWSER} %f" CACHE STRING "Command to open an HTML file")
235 string(CONFIGURE "${FOAM_HTML_DOC_BROWSER_COMMAND}"
236   FOAM_HTML_DOC_BROWSER_COMMAND ESCAPE_QUOTES)
237 mark_as_advanced(HTML_DOC_BROWSER FOAM_HTML_DOC_BROWSER_COMMAND)
239 # Executable-prefix
240 string(TOLOWER "${PROJECT_NAME}-" _FOAM_DEFAULT_EXE_PREFIX)
241 set(FOAM_EXE_PREFIX "${_FOAM_DEFAULT_EXE_PREFIX}"
242   CACHE STRING "Prefix for application output-names")
243 mark_as_advanced(FOAM_EXE_PREFIX)
244 string(TOUPPER "${FOAM_EXE_PREFIX}" FOAM_UPPER_EXE_PREFIX)
246 # ask user whether she wants to build Doxygen docs
247 foam_option(FOAM_ENABLE_DOXYGEN_DOCS "Doxygen API documentation"
248   "Build the Doxygen API documentation" OFF)
249 # make sure only ON and OFF are used
250 if(FOAM_ENABLE_DOXYGEN_DOCS)
251   set(FOAM_ENABLE_DOXYGEN_DOCS ON)
252 else()
253   set(FOAM_ENABLE_DOXYGEN_DOCS OFF)
254 endif()
255 # if user wants doxygen docs, find Doxygen and set up some options
256 if(FOAM_ENABLE_DOXYGEN_DOCS)
257   find_package(Doxygen REQUIRED)
258   execute_process(COMMAND ${DOXYGEN_EXECUTABLE} --version
259     RESULT_VARIABLE DOXYGEN_VERSION_RESULT
260     OUTPUT_VARIABLE DOXYGEN_VERSION_OUTPUT
261     OUTPUT_STRIP_TRAILING_WHITESPACE)
262   if(DOXYGEN_VERSION_RESULT)
263     message(SEND_ERROR "Failed to determine doxygen version")
264   endif()
265   if(${DOXYGEN_VERSION_OUTPUT} VERSION_GREATER 1.6.3 AND
266       ${DOXYGEN_VERSION_OUTPUT} VERSION_LESS 1.7.2-20101106)
267     message(WARNING
268       "Found Doxygen version ${DOXYGEN_VERSION_OUTPUT}. "
269       "Versions newer than 1.6.3 and older than 1.7.2-20101106 "
270       "usually crash when processing the ${PROJECT_NAME} documentation.")
271   endif()
272   # ask user whether she prefers local or www docs
273   foam_option(FOAM_USE_LOCAL_DOXYGEN_DOCS "Use local API docs"
274     "Use the local API documentation instead of http://freefoam.sf.net/doc/API"
275     ON)
276   mark_as_advanced(FOAM_USE_LOCAL_DOXYGEN_DOCS)
277 endif()
279 # ask user whether she wants to build the man pages
280 foam_option(FOAM_ENABLE_MANPAGE_HELP "Build manpage help"
281   "Build the manpages (requires asciidoc)" OFF)
282 # ask user whether she wants to build the xhtml man pages
283 foam_option(FOAM_ENABLE_XHTML_HELP "Build xhtml help"
284   "Build the xhtml help pages (requires asciidoc)" OFF)
285 # as user whether she wanst to build the xhtml guides
286 foam_option(FOAM_ENABLE_XHTML_GUIDES "Build the xhtml guides"
287   "Build the xhtml guides (requires asciidoc, dot, inkscape and asymptote)"
288   OFF)
289 # as user whether she wanst to build the xhtml guides
290 foam_option(FOAM_ENABLE_PDF_GUIDES "Build the PDF guides"
291   "Build the PDF guides (requires asciidoc, dot, inkscape and asymptote)" OFF)
292 if(FOAM_ENABLE_PDF_GUIDES)
293   foam_option(FOAM_USE_FOP "Use FOP instead of dblatex"
294     "Use FOP to build the PDF guides instead of dblatex" OFF)
295   mark_as_advanced(FOAM_USE_FOP)
296 else()
297   set(FOAM_USE_FOP FALSE)
298 endif()
300 if(FOAM_ENABLE_DOXYGEN_DOCS OR FOAM_ENABLE_XHTML_GUIDES)
301   foam_option(FOAM_DOCS_FOR_SF "Docs for SourceForge"
302     "Build the docs for deployment on SourceForge" OFF)
303   mark_as_advanced(FOAM_DOCS_FOR_SF)
304   # make sure only ON and OFF are used
305   if(FOAM_DOCS_FOR_SF)
306     set(FOAM_DOCS_FOR_SF ON)
307   else()
308     set(FOAM_DOCS_FOR_SF OFF)
309   endif()
310 endif()
312 if(BUILD_TESTING)
313   # ask user whether whe wants full tutorial tests
314   foam_option(FOAM_ENABLE_FULL_TUTORIAL_TESTS
315     "Full tutorial tests"
316     "Run the complete tutorial tests (not just a single time step)" OFF)
317   mark_as_advanced(FOAM_ENABLE_FULL_TUTORIAL_TESTS)
318 endif()
320 if(FOAM_ENABLE_XHTML_GUIDES)
321   set(FOAM_ENABLE_XHTML_GUIDES ON)
322   foam_option(FOAM_ENABLE_MATHJAX "Use MathJax in XHTML guides"
323     "Use MathJax for formulas in the XHTML version of the guides" ON)
324   if(FOAM_ENABLE_MATHJAX)
325     foam_option(FOAM_MATHJAX_USE_CDN
326       "Use the MathJax CDN"
327       "Use public MathJax installation at http://cdn.mathjax.org" ON)
328     mark_as_advanced(FOAM_MATHJAX_USE_CDN)
329     if(FOAM_MATHJAX_USE_CDN)
330       set(FOAM_MATHJAX_URL "http://cdn.mathjax.org/mathjax/latest")
331     else()
332       set(FOAM_MATHJAX_URL "MathJAX-NOTFOUND" CACHE PATH
333         "Path or URL to the MathJax directory containing the MathJax.js file")
334       mark_as_advanced(FOAM_MATHJAX_URL)
335       if(NOT FOAM_MATHJAX_URL)
336         message(SEND_ERROR "FOAM_MATHJAX_URL must be set to the directory or "
337           "URL containing MathJax.js")
338       endif()
339     endif()
340   endif()
341 else()
342   set(FOAM_ENABLE_XHTML_GUIDES OFF)
343   set(FOAM_ENABLE_MATHJAX FALSE)
344 endif()
346 # assemble the list of enabled manpage formats
347 set(FOAM_MANPAGE_FORMATS)
348 if(FOAM_ENABLE_MANPAGE_HELP)
349   list(APPEND FOAM_MANPAGE_FORMATS manpage)
350 endif()
351 if(FOAM_ENABLE_XHTML_HELP)
352   list(APPEND FOAM_MANPAGE_FORMATS xhtml)
353 endif()
355 # assemble the list of enabled guides formats
356 set(FOAM_GUIDES_FORMATS)
357 if(FOAM_ENABLE_XHTML_GUIDES)
358   list(APPEND FOAM_GUIDES_FORMATS xhtml)
359 endif()
360 if(FOAM_ENABLE_PDF_GUIDES)
361   list(APPEND FOAM_GUIDES_FORMATS pdf)
362 endif()
364 if(FOAM_MANPAGE_FORMATS OR FOAM_GUIDES_FORMATS)
365   # find AsciiDoc
366   find_program(ASCIIDOC_EXECUTABLE NAMES asciidoc.py asciidoc)
367   get_filename_component(asciidoc_path "${ASCIIDOC_EXECUTABLE}" PATH)
368   find_program(A2X_EXECUTABLE NAMES a2x.py a2x HINTS "${asciidoc_path}")
369   if(NOT ASCIIDOC_EXECUTABLE OR NOT A2X_EXECUTABLE)
370     message(SEND_ERROR
371       "AsciiDoc is required to create man and html help and the guides")
372   endif()
373   mark_as_advanced(ASCIIDOC_EXECUTABLE A2X_EXECUTABLE)
374   # read CONF_DIR from A2X_EXECUTABLE and copy style files over
375   if(A2X_EXECUTABLE)
376     file(READ "${A2X_EXECUTABLE}" _asciidoc_text)
377     if(_asciidoc_text MATCHES "[ \t]*CONF_DIR[ \t]*=[ \t]*r?['\"]([^'\"]+)")
378       set(A2X_CONF_DIR "${CMAKE_MATCH_1}")
379       if(IS_DIRECTORY "${A2X_CONF_DIR}")
380         configure_file("${A2X_CONF_DIR}/docbook-xsl/common.xsl"
381           "${CMAKE_BINARY_DIR}/data/asciidoc/docbook-xsl/orig-common.xsl"
382           COPYONLY)
383         configure_file("${A2X_CONF_DIR}/docbook-xsl/chunked.xsl"
384           "${CMAKE_BINARY_DIR}/data/asciidoc/docbook-xsl/orig-chunked.xsl"
385           COPYONLY)
386         configure_file("${A2X_CONF_DIR}/docbook-xsl/xhtml.xsl"
387           "${CMAKE_BINARY_DIR}/data/asciidoc/docbook-xsl/orig-xhtml.xsl"
388           COPYONLY)
389         configure_file("${A2X_CONF_DIR}/dblatex/asciidoc-dblatex.sty"
390           "${CMAKE_BINARY_DIR}/data/asciidoc/dblatex/orig-asciidoc-dblatex.sty"
391           COPYONLY)
392         configure_file("${A2X_CONF_DIR}/dblatex/asciidoc-dblatex.xsl"
393           "${CMAKE_BINARY_DIR}/data/asciidoc/dblatex/orig-asciidoc-dblatex.xsl"
394           COPYONLY)
395       else()
396         message(SEND_ERROR "The Asciidoc configuration directory "
397           "${A2X_CONF_DIR} does not exist")
398       endif()
399     else()
400       message(SEND_ERROR "Failed to read CONF_DIR from ${A2X_EXECUTABLE}")
401     endif()
402   endif()
403   if(FOAM_ENABLE_XHTML_GUIDES)
404     find_program(XSLTPROC_EXECUTABLE xsltproc)
405     if(NOT XSLTPROC_EXECUTABLE)
406       message(SEND_ERROR "Failed to find xsltproc executable"
407         "Required if FOAM_ENABLE_XHTML_GUIDES is enabled")
408     endif()
409     mark_as_advanced(XSLTPROC_EXECUTABLE)
410   endif()
411   set(FOAM_NEED_PNGMATH FALSE)
412   if((FOAM_ENABLE_XHTML_GUIDES AND NOT FOAM_ENABLE_MATHJAX) OR
413     (FOAM_ENABLE_PDF_GUIES AND FOAM_USE_FOP))
414     set(FOAM_NEED_PNGMATH TRUE)
415     foreach(prog latex dvipng)
416       string(TOUPPER ${prog} uprog)
417       find_program(${uprog}_EXECUTABLE ${prog})
418       mark_as_advanced(${uprog}_EXECUTABLE)
419       if(NOT ${uprog}_EXECUTABLE)
420         message(SEND_ERROR
421           "${prog} is required when FOAM_ENABLE_MATHJAX is disabled "
422           "or FOAM_USE_FOP is enabled")
423       endif()
424     endforeach()
425   endif()
426 endif()
427 if(FOAM_GUIDES_FORMATS)
428   # find asymptote
429   find_program(ASY_EXECUTABLE asy)
430   if(NOT ASY_EXECUTABLE)
431     message(SEND_ERROR "Asymptote is required to create the guides")
432   endif()
433   mark_as_advanced(ASY_EXECUTABLE)
434 endif()
436 # set up the RPATH for installation
437 set(CMAKE_INSTALL_RPATH ${FOAM_INSTALL_LIBRARY_PATH})
438 set(CMAKE_INSTALL_NAME_DIR ${FOAM_FRAMEWORK_INSTALL_NAME_DIR})
440 # we want executables and libraries in uniform places
441 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
442   "${CMAKE_BINARY_DIR}/libexec/${PROJECT_NAME}/${FOAM_VERSION_FULL}")
443 set(FOAM_LIBRARY_OUTPUT_DIRECTORY
444   "${CMAKE_BINARY_DIR}/lib/${PROJECT_NAME}-${FOAM_VERSION_FULL}")
445 set(FOAM_FRAMEWORK_OUTPUT_DIRECTORY
446   "${CMAKE_BINARY_DIR}/Library/Frameworks")
447 if(FOAM_BUILD_FRAMEWORKS)
448   set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${FOAM_FRAMEWORK_OUTPUT_DIRECTORY}")
449 else()
450   set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${FOAM_LIBRARY_OUTPUT_DIRECTORY}")
451 endif()
452 set(FOAM_ARCHIVE_OUTPUT_DIRECTORY "${FOAM_LIBRARY_OUTPUT_DIRECTORY}")
454 # find parallel libraries
455 find_package(MPI)
456 if(MPI_FOUND)
457   set(_FOAM_USE_MPI ON)
458 else()
459   set(_FOAM_USE_MPI OFF)
460 endif()
461 foam_option(FOAM_USE_MPI "Use MPI"
462   "Build ${CMAKE_PROJECT} against MPI parallel libraries" ${_FOAM_USE_MPI})
463 mark_as_advanced(FOAM_USE_MPI)
464 if(FOAM_USE_MPI AND NOT MPI_FOUND)
465   message(SEND_ERROR
466     "FOAM_ENABLE_MPI is true, but MPI cannot be found.\n"
467     "If you have MPI installed on your system, edit the variables\n"
468     "MPI_INCLUDE_DIR and MPI_LIBRARY in the cache, else disable the\n"
469     "setting FOAM_USE_MPI."
470   )
471 endif()
473 # find readline
474 find_package(Readline)
476 # substitution for build-tree and install-tree as used by
477 # foam_configure_files.
478 set(FOAM_CONFIGURE_FILES_VARIABLES
479   FOAM_DATA_DIR
480     "${CMAKE_BINARY_DIR}/data"
481     "${FOAM_INSTALL_DATA_PATH}"
482   FOAM_LOCAL_DOC_DIR
483     "${CMAKE_BINARY_DIR}/doc"
484     "${FOAM_INSTALL_DOC_PATH}"
485   FOAM_BIN_DIR
486     "${CMAKE_BINARY_DIR}/bin"
487     "${FOAM_INSTALL_BIN_PATH}"
488   FOAM_LIB_DIR
489     "${CMAKE_BINARY_DIR}/lib/FreeFOAM-${FOAM_VERSION_FULL}"
490     "${FOAM_INSTALL_LIBRARY_PATH}"
491   FOAM_LIBEXEC_DIR
492     "${CMAKE_BINARY_DIR}/libexec/FreeFOAM/${FOAM_VERSION_FULL}"
493     "${FOAM_INSTALL_LIBEXEC_PATH}"
494   FOAM_FRAMEWORK_DIR
495     "${CMAKE_BINARY_DIR}/Library/Frameworks"
496     "${FOAM_INSTALL_FRAMEWORK_PATH}"
497   FOAM_INCLUDE_DIR
498     "${CMAKE_BINARY_DIR}/include"
499     "${FOAM_INSTALL_HEADER_PATH}"
500   FOAM_CONFIG_DIR
501     "${CMAKE_BINARY_DIR}/etc"
502     "${FOAM_INSTALL_CONFIG_PATH}"
503   FOAM_CMAKECONFIG_DIR
504     "${CMAKE_BINARY_DIR}/CMake"
505     "${FOAM_INSTALL_CMAKE_PATH}"
506   FOAM_PYTHON_DIR
507     "${CMAKE_BINARY_DIR}/data/python"
508     "${FOAM_INSTALL_PYTHON_PATH}"
509   FOAM_IS_INSTALLED
510     "FALSE"
511     "TRUE"
512   )
513 if(WIN32)
514   list(APPEND FOAM_CONFIGURE_FILES_VARIABLES
515     FOAM_PLUGIN_DIR
516       "${CMAKE_BINARY_DIR}/lib/FreeFOAM-${FOAM_VERSION_FULL}"
517       "${FOAM_INSTALL_LIBRARY_PATH}")
518 else()
519   list(APPEND FOAM_CONFIGURE_FILES_VARIABLES
520     FOAM_PLUGIN_DIR
521       "${CMAKE_BINARY_DIR}/lib/FreeFOAM-${FOAM_VERSION_FULL}/plugins"
522       "${FOAM_INSTALL_PLUGIN_PATH}")
523 endif()
524 if(FOAM_USE_LOCAL_DOXYGEN_DOCS)
525   list(APPEND FOAM_CONFIGURE_FILES_VARIABLES
526     FOAM_DOC_DIR "${CMAKE_BINARY_DIR}/doc" "${FOAM_INSTALL_DOC_PATH}")
527 else()
528   set(_sf_doc "http://freefoam.sf.net/doc/${FOAM_VERSION_FULL}")
529   list(APPEND FOAM_CONFIGURE_FILES_VARIABLES
530     FOAM_DOC_DIR "${_sf_doc}" "${_sf_doc}")
531 endif()
533 # thirdparty libraries
534 foam_thirdparty_option(Metis
535   "Required by the metis decomposition method"
536   Metis TRUE ON)
537 if(FOAM_ENABLE_METIS)
538   if(FOAM_ENABLE_METIS AND METIS_REQUIRES_MPI AND NOT FOAM_USE_MPI)
539     message(SEND_ERROR
540       "Your metis implementation requires FOAM_USE_MPI to be enabled."
541       "If you don't have/want MPI, enable FOAM_BUILD_PRIVATE_METIS instead.")
542   endif()
543 endif()
544 foam_thirdparty_option(ParMetis
545   "Required by the parmetis decomposition method"
546   ParMetis TRUE ${FOAM_USE_MPI}
547   PARMETIS_metis_LIBRARY PARMETIS_parmetis_LIBRARY)
548 if(FOAM_ENABLE_PARMETIS AND NOT FOAM_USE_MPI)
549   message(SEND_ERROR
550     "ParMetis requires FOAM_USE_MPI to be enabled.")
551 endif()
552 if(FOAM_ENABLE_PARMETIS AND NOT FOAM_ENABLE_METIS)
553   message(SEND_ERROR
554     "ParMetis requires FOAM_ENABLE_METIS to be enabled.")
555 endif()
556 set(SCOTCH_USE_ERREXIT TRUE)
557 foam_thirdparty_option(SCOTCH "" SCOTCH FALSE ON SCOTCH_scotch_LIBRARY
558   SCOTCH_scotcherr_LIBRARY SCOTCH_scotcherrexit_LIBRARY)
559 # do not enable mgridgen by default (licensing issues)
560 if(NOT FOAM_DOUBLE_PRECISION)
561   set(MGRIDGEN_USE_REAL ON)
562 endif()
563 foam_thirdparty_option(MGRIDGEN
564   "Required by the MGridGen GAMG agglomerator. LICENSE UNCLEAR"
565   MGRIDGEN TRUE OFF)
566 # do not enable libccmio by default (licensing issues)
567 foam_thirdparty_option(ccmio
568   "Required by ccm26ToFoam. REQUIRES PERMISSION BY CDADAPCO!"
569   Ccmio TRUE OFF)
570 foam_thirdparty_option(zlib "" ZLIB FALSE ON)
572 # figure out default Pstream library
573 if(FOAM_USE_MPI)
574   set(_FOAM_DEFAULT_PSTREAM mpi)
575 else()
576   set(_FOAM_DEFAULT_PSTREAM dummy)
577 endif()
578 set(FOAM_DEFAULT_PSTREAM ${_FOAM_DEFAULT_PSTREAM} CACHE STRING
579   "Default Pstream library implementation [dummy|mpi]")
580 mark_as_advanced(FOAM_DEFAULT_PSTREAM)
582 # find m4 macro processor
583 find_program(M4_EXECUTABLE m4 DOC "Path to the m4 macro processor")
584 mark_as_advanced(M4_EXECUTABLE)
585 if(NOT M4_EXECUTABLE)
586   message("WARNING: Failed to find M4 macro processor.\n"
587     "Some of the tutorials will fail if it can't be found.")
588   set(M4_EXECUTABLE m4)
589 endif()
591 # on APPLE use cp -R -P -p, otherwise use cp -a
592 if(APPLE)
593   set(FOAM_CP_A_FLAGS "-R -P -p")
594 else()
595   set(FOAM_CP_A_FLAGS "-a")
596 endif()
598 # execinfo.h and cxxabi.h only work using GNU gcc and Debug config
599 # assume that if we have execinfo.h, cxxabi.h is also present.
600 if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_BUILD_TYPE STREQUAL Debug)
601   find_package(Execinfo)
602 endif()
604 # create the FOAMConfig.h file
605 configure_file(${CMAKE_SOURCE_DIR}/FOAMConfig.h.in
606   ${CMAKE_BINARY_DIR}/include/FOAMConfig.h @ONLY)
608 # on Solaris/SunOS fix up the shebangs
609 if(CMAKE_SYSTEM_NAME STREQUAL SunOS AND
610     NOT EXISTS ${CMAKE_BINARY_DIR}/replaceAllShellSun.run)
611   message(STATUS "Fixing shell-interpreter for SunOS and Solaris")
612   execute_process(
613     COMMAND ${CMAKE_SOURCE_DIR}/data/utilities/replaceAllShellSun bin
614     COMMAND ${CMAKE_SOURCE_DIR}/data/utilities/replaceAllShellSun data
615     COMMAND ${CMAKE_SOURCE_DIR}/data/utilities/replaceAllShellSun tutorials
616     COMMAND ${CMAKE_SOURCE_DIR}/data/utilities/replaceAllShellSun doc
617     COMMAND ${CMAKE_COMMAND} -E touch${CMAKE_BINARY_DIR}/replaceAllShellSun.run
618     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
619     )
620 endif()
622 # set up defines
623 set(FOAM_COMPILE_DEFINITIONS
624   -D${FOAM_PRECISION}
625   -DNoRepository
626   -D${FOAM_OS}
627   )
628 if(APPLE)
629   list(APPEND FOAM_COMPILE_DEFINITIONS -Ddarwin)
630 endif()
631 add_definitions(${FOAM_COMPILE_DEFINITIONS})
633 # set up include-directories for own headers
634 include_directories(${CMAKE_BINARY_DIR}/include)
636 # set up version info checks and updating of global.C
637 set(FOAM_HAVE_GIT FALSE)
638 if(EXISTS "${CMAKE_SOURCE_DIR}/.git/config")
639   find_package(Git)
640   if(GIT_FOUND)
641     set(FOAM_HAVE_GIT TRUE)
642     option(FOAM_VERSION_CHECK_WARN_ONLY
643       "Only warn if the version numbers are wrong" FALSE)
644     mark_as_advanced(FOAM_VERSION_CHECK_WARN_ONLY)
645     configure_file(CMake/ConfigureGlobalC.cmake.in
646       "${CMAKE_BINARY_DIR}/CMake/ConfigureGlobalC.cmake" @ONLY)
647     add_custom_target(version_check ALL
648       COMMAND "${PYTHON_EXECUTABLE}"
649         "${CMAKE_BINARY_DIR}/data/utilities/checkVersionInfo.py"
650         ${_CHECK_VERSION_INFO_ARGS}
651       DEPENDS "${CMAKE_BINARY_DIR}/data/utilities/checkVersionInfo.py"
652       COMMENT "Checking version information"
653       VERBATIM)
654   else()
655     message(WARNING
656       "Not performing version checks because GIT_EXECUTABLE is missing")
657   endif()
658 else()
659   message(STATUS
660     "Not performing version checks because not in a Git checkout")
661 endif()
663 if(NOT FOAM_HAVE_GIT)
664   if(NOT EXISTS ${CMAKE_SOURCE_DIR}/.build.cmake)
665     message(SEND_ERROR "If not in a Git checkout, .build.cmake is required")
666   endif()
667   include(${CMAKE_SOURCE_DIR}/.build.cmake)
668 endif()
670 # helper variables to force linking on some systems
671 set(_TURBULENCE_MODELS ${PROJECT_SOURCE_DIR}/src/turbulenceModels)
672 set(FORCE_LINK_COMPRESSIBLE_RAS_MODELS
673   ${_TURBULENCE_MODELS}/compressible/RAS/RASModel/forceLink.C)
674 set(FORCE_LINK_COMPRESSIBLE_LES_MODELS
675   ${_TURBULENCE_MODELS}/compressible/LES/LESModel/forceLink.C)
676 set(FORCE_LINK_INCOMPRESSIBLE_RAS_MODELS
677   ${_TURBULENCE_MODELS}/incompressible/RAS/RASModel/forceLink.C)
678 set(FORCE_LINK_INCOMPRESSIBLE_LES_MODELS
679   ${_TURBULENCE_MODELS}/incompressible/LES/LESModel/forceLink.C)
680 set(FORCE_LINK_GENERIC_PATCH_FIELDS
681   ${PROJECT_SOURCE_DIR}/src/genericPatchFields/include/forceLink.C)
682 set(FORCE_LINK_RADIATION
683   ${PROJECT_SOURCE_DIR}/src/thermophysicalModels/radiation/radiationModel/radiationModel/forceLink.C)
684 set(FORCE_LINK_COAL_COMBUSTION
685   ${PROJECT_SOURCE_DIR}/src/lagrangian/coalCombustion/include/forceLink.C)
686 set(FORCE_LINK_INTERFACE_PROPERTIES
687   ${PROJECT_SOURCE_DIR}/src/transportModels/interfaceProperties/forceLink.C)
689 # descend into the sources...
690 add_subdirectory(bin)
691 add_subdirectory(etc)
692 add_subdirectory(data)
693 add_subdirectory(src)
694 add_subdirectory(applications)
695 add_subdirectory(tutorials)
696 # doc *must* be last, else manpage and Doxygen generation fails
697 add_subdirectory(doc)
699 # export the library dependencies to the build tree
700 foam_export_targets_to_build_tree(${PROJECT_NAME}LibraryDepends)
701 export(PACKAGE ${PROJECT_NAME})
703 # write the doc index file and install it
704 foam_write_doc_index()
705 install(FILES
706   ${CMAKE_BINARY_DIR}/InstallFiles/data/DoxyDocIndex
707   DESTINATION ${FOAM_INSTALL_DATA_PATH}
708   COMPONENT data
709   )
711 # create ${PROJECT_NAME}Config.cmake ${PROJECT_NAME}Use.cmake,
712 # ${PROJECT_NAME}Utilities.cmake and ${PROJECT_NAME}WmakeCompatibility.cmake
713 # for the build and install tree
714 foam_configure_files(ConfigInstallFiles
715   "CMake/FOAMConfig.cmake.in==CMake/${PROJECT_NAME}Config.cmake"
716   "CMake/FOAMUse.cmake.in==CMake/${PROJECT_NAME}Use.cmake"
717   "CMake/FOAMWmakeCompatibility.cmake.in==CMake/${PROJECT_NAME}WmakeCompatibility.cmake"
718   COPYONLY
719   "CMake/FOAMUtilities.cmake==CMake/${PROJECT_NAME}Utilities.cmake"
720   )
722 # install the CMake config files
723 install(FILES
724   ${ConfigInstallFiles}
725   DESTINATION ${FOAM_INSTALL_CMAKE_PATH}
726   COMPONENT dev
727   )
729 # install the ${PROJECT_NAME}LibraryDepends.cmake file
730 install(EXPORT ${PROJECT_NAME}LibraryDepends
731   DESTINATION ${FOAM_INSTALL_CMAKE_PATH}
732   NAMESPACE FOAM_
733   COMPONENT dev
734   )
736 # uninstall target
737 configure_file(
738   "${CMAKE_SOURCE_DIR}/CMake/Modules/cmake_uninstall.cmake.in"
739   "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake"
740   @ONLY
741   )
743 add_custom_target(uninstall
744   "${CMAKE_COMMAND}" -P "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake"
745   )
747 # print cool feature summary
748 foam_print_feature_summary()
750 # ------------------------- vim: set sw=2 sts=2 et: --------------- end-of-file