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