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