ENH: Added ReleaseNotes, ChangeLog and INSTALL
[freefoam.git] / CMakeLists.txt
blob7850db717b742a214d68f2d2e92336ce0ad9c3e0
1 #-------------------------------------------------------------------------------
2 #                ______             ______ ____          __  __
3 #               |  ____|           |  ____/ __ \   /\   |  \/  |
4 #               | |__ _ __ ___  ___| |__ | |  | | /  \  | \  / |
5 #               |  __| '__/ _ \/ _ \  __|| |  | |/ /\ \ | |\/| |
6 #               | |  | | |  __/  __/ |   | |__| / ____ \| |  | |
7 #               |_|  |_|  \___|\___|_|    \____/_/    \_\_|  |_|
9 #                   FreeFOAM: The Cross-Platform CFD Toolkit
11 # Copyright (C) 2008 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 project( FreeFOAM )
34 cmake_minimum_required( VERSION 2.6.0 )
36 # version information
37 set( FF_VERSION_MAJOR 0 )
38 set( FF_VERSION_MINOR 1 )
39 set( FF_VERSION_PATCH 0 )
40 set( FF_VERSION ${FF_VERSION_MAJOR}.${FF_VERSION_MINOR} )
41 set( FF_VERSION_FULL ${FF_VERSION}.${FF_VERSION_PATCH} )
43 # set up custom cmake module path
44 set( CMAKE_MODULE_PATH
45   ${CMAKE_SOURCE_DIR}/CMake
46   ${CMAKE_SOURCE_DIR}/CMake/Modules
47   )
49 # select precision
50 option( FF_DOUBLE_PRECISION "Compile FreeFOAM with double precision floating point arithmetics." ON )
51 if( FF_DOUBLE_PRECISION )
52   set( FF_PRECISION DP )
53 else( FF_DOUBLE_PRECISION )
54   set( FF_PRECISION SP )
55 endif( FF_DOUBLE_PRECISION )
57 # select whether we want to build framewors on Mac OS X
58 if( APPLE )
59   option( FF_BUILD_FRAMEWORK "Build frameworks on Mac OS X" OFF )
60 else( APPLE )
61   set( FF_BUILD_FRAMEWORK OFF )
62 endif( APPLE )
63 mark_as_advanced( FF_BUILD_FRAMEWORK )
65 # we want shared libraries
66 set( BUILD_SHARED_LIBS SHARED )
68 # use a prefix for executables
69 set (EXECUTABLE_PREFIX "ff_" CACHE STRING "Prefix prepended to all program and script names")
70 mark_as_advanced( EXECUTABLE_PREFIX )
72 # installation directories
73 set( FF_INSTALL_BIN_PATH bin CACHE STRING "Executables installation path (absolute or relative to CMAKE_INSTALL_PREFIX)" )
74 if( APPLE AND FF_BUILD_FRAMEWORK )
75   set( FF_INSTALL_FRAMEWORK_PATH /Library/Frameworks CACHE STRING "Framework installation path (absolute or relative to CMAKE_INSTALL_PREFIX)" )
76 endif( APPLE AND FF_BUILD_FRAMEWORK )
77 set( FF_INSTALL_LIB_PATH lib/${CMAKE_PROJECT_NAME}/${FF_VERSION} CACHE STRING "Library installation path (absolute or relative to CMAKE_INSTALL_PREFIX)" )
78 set( FF_INSTALL_HEADER_PATH include/${CMAKE_PROJECT_NAME}/${FF_VERSION} CACHE STRING "Header installation path (absolute or relative to CMAKE_INSTALL_PREFIX, not for frameworks)" )
79 set( FF_INSTALL_CONFIG_PATH etc/${CMAKE_PROJECT_NAME}/${FF_VERSION} CACHE STRING "Configuration files installation path (absolute or relative to CMAKE_INSTALL_PREFIX)" )
80 set( FF_INSTALL_DATA_PATH share/${CMAKE_PROJECT_NAME}/${FF_VERSION} CACHE STRING "Data files installation path (absolute or relative to CMAKE_INSTALL_PREFIX)" )
81 set( FF_INSTALL_DOC_PATH share/doc/${CMAKE_PROJECT_NAME}/${FF_VERSION} CACHE STRING "Documentation files installation path (absolute or relative to CMAKE_INSTALL_PREFIX)" )
82 set( FF_INSTALL_TUTORIALS_PATH share/doc/${CMAKE_PROJECT_NAME}/${FF_VERSION} CACHE STRING "Tutorials installation path (absolute or relative to CMAKE_INSTALL_PREFIX)" )
83 set( FF_INSTALL_PVFOAMREADER_PATH lib/${CMAKE_PROJECT_NAME}/${FF_VERSION}/plugins/PVFoamReader CACHE STRING "ParaView2 OpenFOAM-reader plugin installation path" )
84 set( FF_INSTALL_PV3FOAMREADER_PATH lib/${CMAKE_PROJECT_NAME}/${FF_VERSION}/plugins/PV3FoamReader CACHE STRING "ParaView3 OpenFOAM-reader plugin installation path" )
85 set( FF_INSTALL_USERDFOAM_PATH lib/${CMAKE_PROJECT_NAME}/${FF_VERSION}/plugins/userd-foam CACHE STRING "Ensight OpenFOAM-reader plugin installation path" )
86 mark_as_advanced( FF_INSTALL_BIN_PATH FF_INSTALL_FRAMEWORK_PATH FF_INSTALL_LIB_PATH FF_INSTALL_HEADER_PATH FF_INSTALL_CONFIG_PATH FF_INSTALL_DATA_PATH
87   FF_INSTALL_DOC_PATH FF_INSTALL_TUTORIALS_PATH FF_INSTALL_PVFOAMREADER_PATH FF_INSTALL_PV3FOAMREADER_PATH FF_INSTALL_USERDFOAM_PATH )
89 # make absolute paths
90 foreach( _p FF_INSTALL_BIN_PATH FF_INSTALL_LIB_PATH FF_INSTALL_FRAMEWORK_PATH
91     FF_INSTALL_HEADER_PATH FF_INSTALL_CONFIG_PATH FF_INSTALL_DATA_PATH FF_INSTALL_DOC_PATH )
92   if( NOT IS_ABSOLUTE ${${_p}} )
93     set( ${_p} "${CMAKE_INSTALL_PREFIX}/${${_p}}" )
94   endif( NOT IS_ABSOLUTE ${${_p}} )
95 endforeach( _p )
97 # determine the INSTALL_NAME_DIR of potential frameworks
98 if( APPLE AND FF_BUILD_FRAMEWORK )
99   set( FF_FRAMEWORK_INSTALL_NAME_DIR ${FF_INSTALL_FRAMEWORK_PATH} )
100 else( APPLE AND FF_BUILD_FRAMEWORK )
101   set( FF_FRAMEWORK_INSTALL_NAME_DIR ${FF_INSTALL_LIB_PATH} )
102 endif( APPLE AND FF_BUILD_FRAMEWORK )
104 # select html documentation browser (try a few well known ones for default)
105 # have to loop, because find_program( HTML_DOC_BROWSER NAMES ... ) garbles things up
106 foreach( browser open kde-open gnome-open x-www-browser www-browser firefox epiphany konqueror w3m lynx open )
107   find_program( HTML_DOC_BROWSER ${browser}
108     DOC "Program to open an HTML file" )
109   if( HTML_DOC_BROWSER )
110     set( FF_HTML_DOC_BROWSER_COMMAND "${HTML_DOC_BROWSER} %f" CACHE STRING "Command to open an HTML file" )
111     break()
112   endif( HTML_DOC_BROWSER )
113 endforeach( browser )
114 if( NOT HTML_DOC_BROWSER )
115   message( SEND_ERROR "Failed to find a program to open HTML pages with (a.k.a a browser). Point HTML_DOC_BROWSER to a suitable program." )
116 endif( NOT HTML_DOC_BROWSER )
117 mark_as_advanced( HTML_DOC_BROWSER FF_HTML_DOC_BROWSER_COMMAND )
119 # set up the RPATH for installation
120 set( CMAKE_INSTALL_RPATH ${FF_INSTALL_LIB_PATH} )
122 # we want executables and libraries in uniform places
123 set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin )
124 set( FF_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/FreeFOAM/${FF_VERSION} )
125 set( FF_FRAMEWORK_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Library/Frameworks )
126 if( FF_BUILD_FRAMEWORK )
127   set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${FF_FRAMEWORK_OUTPUT_DIRECTORY} )
128 else( FF_BUILD_FRAMEWORK )
129   set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${FF_LIBRARY_OUTPUT_DIRECTORY} )
130 endif( FF_BUILD_FRAMEWORK )
131 set( FF_ARCHIVE_OUTPUT_DIRECTORY ${FF_LIBRARY_OUTPUT_DIRECTORY} )
133 # determine computer system
134 include( FFDetermineArch )
136 # find parallel libraries
137 option( FF_USE_MPI "Build ${CMAKE_PROJECT} against MPI parallel libraries" ON )
138 if( FF_USE_MPI )
139   find_package( MPI REQUIRED )
140 endif( FF_USE_MPI )
141 option( FF_USE_PVM "Build ${CMAKE_PROJECT} against PVM parallel libraries" OFF )
142 if( FF_USE_PVM )
143   find_package( PVM REQUIRED )
144 endif( FF_USE_PVM )
145 if( CMAKE_SYSTEM_NAME STREQUAL Linux )
146 option( FF_USE_GAMMA "Build ${CMAKE_PROJECT} against GAMMA parallel libraries" OFF )
147 if( FF_USE_GAMMA )
148   find_package( GAMMA REQUIRED )
149 endif( FF_USE_GAMMA )
150 endif( CMAKE_SYSTEM_NAME STREQUAL Linux )
151 if( MPI_FOUND OR PVM_FOUND OR GAMMA_FOUND )
152   set( FF_USE_PARALLEL TRUE )
153 endif( MPI_FOUND OR PVM_FOUND OR GAMMA_FOUND )
154 mark_as_advanced( FF_USE_MPI FF_USE_PVM FF_USE_GAMMA )
156 # find flex
157 find_package( FLEX REQUIRED )
158 set( FLEX_CXX_FLAGS "-+" CACHE STRING "Flags used by the flex compiler for flex++ targets." )
159 mark_as_advanced( FLEX_CXX_FLAGS )
161 # find zlib
162 find_package( ZLIB REQUIRED )
163 if( NOT ZLIB_FOUND )
164   message( SEND_ERROR "zlib is required! Override ZLIB_* settings [advanced]." )
165 endif( NOT ZLIB_FOUND )
167 # utility
168 include( FFConfigureFiles )
169 include( FFDetectChangedValue )
170 include( FFExportTargetsToBuildTree )
171 include( FFLinkLoadableLibrary )
173 # find metis (recent distros have it in their repository, so default to search for that)
174 option( FF_BUILD_PRIVATE_METIS "Download and compile private METIS library instead of searching the system for it" OFF )
175 ff_detect_changed_value( FF_BUILD_PRIVATE_METIS_CHANGED FF_BUILD_PRIVATE_METIS
176   METIS_INCLUDE_DIR METIS_LIBRARY )
177 if( FF_BUILD_PRIVATE_METIS )
178   find_package( Threads REQUIRED )
179   add_subdirectory( ThirdParty/METIS )
180 else( FF_BUILD_PRIVATE_METIS )
181   find_package( Metis REQUIRED )
182   if( NOT METIS_FOUND )
183     message( SEND_ERROR "metis is required! Override METIS_* settings [advanced]." )
184   endif( NOT METIS_FOUND )
185   if( METIS_REQUIRES_MPI AND NOT FF_USE_MPI )
186     message( SEND_ERROR "Your metis implementation requires FF_USE_MPI to be enabled. If you don't have/want MPI, enable FF_BUILD_PRIVATE_METIS instead." )
187   endif( METIS_REQUIRES_MPI AND NOT FF_USE_MPI )
188 endif( FF_BUILD_PRIVATE_METIS )
190 # find ParMetis (recent distros have it in their repository, so default to search for that)
191 if( FF_USE_MPI )
192   option( FF_BUILD_PRIVATE_PARMETIS "Download and compile private ParMetis library instead of searching the system for it" OFF )
193   ff_detect_changed_value( FF_BUILD_PRIVATE_PARMETIS_CHANGED FF_BUILD_PRIVATE_PARMETIS
194     PARMETIS_INCLUDE_DIR PARMETIS_metis_LIBRARY PARMETIS_parmetis_LIBRARY )
195   if( FF_BUILD_PRIVATE_PARMETIS )
196     add_subdirectory( ThirdParty/ParMetis )
197   else( FF_BUILD_PRIVATE_PARMETIS )
198     find_package( ParMetis REQUIRED )
199     if( NOT PARMETIS_FOUND )
200       message( SEND_ERROR "ParMetis is required! Override PARMETIS_* settings [advanced]." )
201     endif( NOT PARMETIS_FOUND )
202   endif( FF_BUILD_PRIVATE_PARMETIS )
203 else( FF_USE_MPI )
204   message( STATUS "NOTE: Not using ParMetis because FF_USE_MPI not selected." )
205 endif( FF_USE_MPI )
207 # do not enable (par)mgridgen by default (licensing issues)
208 option( FF_ENABLE_PARMGRIDGEN "Enable PARMGRIDGEN support (required by the MGridGen GAMG agglomerator option). LICENSE UNCLEAR" OFF )
209 if( FF_ENABLE_PARMGRIDGEN )
210   # find mgridgen (not commonly available, default to private build)
211   option( FF_BUILD_PRIVATE_PARMGRIDGEN "Download and compile private PARMGRIDGEN library instead of searching the system for it" OFF )
212   ff_detect_changed_value( FF_BUILD_PRIVATE_PARMGRIDGEN_CHANGED FF_BUILD_PRIVATE_PARMGRIDGEN
213     MGRIDGEN_INCLUDE_DIR MGRIDGEN_LIBRARY )
214   if( FF_BUILD_PRIVATE_PARMGRIDGEN )
215     add_subdirectory( ThirdParty/PARMGRIDGEN )
216   else( FF_BUILD_PRIVATE_PARMGRIDGEN )
217     if( NOT FF_DOUBLE_PRECISION )
218       set( MGRIDGEN_USE_REAL ON )
219     endif( NOT FF_DOUBLE_PRECISION )
220     find_package( MGRIDGEN REQUIRED )
221     if( NOT MGRIDGEN_FOUND )
222       message( SEND_ERROR "MGRIDGEN is required! Override MGRIDGEN_* settings [advanced]." )
223     endif( NOT MGRIDGEN_FOUND )
224   endif( FF_BUILD_PRIVATE_PARMGRIDGEN )
225 endif( FF_ENABLE_PARMGRIDGEN )
227 # do not enable libccmio by default (proprietary license)
228 option( FF_ENABLE_CCMIO "Enable libccmio support (required by the ccm26ToFoam grid converter). REQUIRES PERMISSION BY CDADAPCO!" OFF )
229 if( FF_ENABLE_CCMIO )
230   # find ccmio (not commonly available, default to private build)
231   option( FF_BUILD_PRIVATE_CCMIO "Download and compile private CCMIO library instead of searching the system for it" OFF )
232   ff_detect_changed_value( FF_BUILD_PRIVATE_CCMIO_CHANGED FF_BUILD_PRIVATE_CCMIO
233     CCMIO_INCLUDE_DIR CCMIO_LIBRARY )
234   if( FF_BUILD_PRIVATE_CCMIO )
235     add_subdirectory( ThirdParty/ccmio )
236   else( FF_BUILD_PRIVATE_CCMIO )
237     find_package( Ccmio REQUIRED )
238     if( NOT CCMIO_FOUND )
239       message( SEND_ERROR "ccmio is required! Override CCMIO_* settings [advanced]." )
240     endif( NOT CCMIO_FOUND )
241   endif( FF_BUILD_PRIVATE_CCMIO )
242 endif( FF_ENABLE_CCMIO )
244 mark_as_advanced( FF_BUILD_PRIVATE_CCMIO FF_BUILD_PRIVATE_METIS FF_BUILD_PRIVATE_PARMETIS
245   FF_BUILD_PRIVATE_PARMGRIDGEN FF_DOUBLE_PRECISION FF_ENABLE_PARMGRIDGEN FF_ENABLE_CCMIO )
247 # ask user whether she wants to build ParaView plugins
248 option( FF_BUILD_PARAVIEW_PLUGINS "Build the ParaView plugins. Requires a ParaView build tree." OFF )
249 if( FF_BUILD_PARAVIEW_PLUGINS )
250   # find ParaView, which also find the VTK which has been used to build ParaView
251   find_package( ParaView REQUIRED )
252   if( NOT ParaView_FOUND )
253     message( FATAL_ERROR "Failed to find the ParaView build tree. Specify ParaView_DIR or disable FF_BUILD_PARAVIEW_PLUGINS" )
254   endif( NOT ParaView_FOUND )
255   # find the installed ParaView executable
256   find_program(
257     FF_PARAVIEW3_APP NAMES paraview paraview.app
258     PATHS ${ParaView_DIR}/bin
259     DOC "Path to the ParaView 3 executable (or application bundle on Mac OS X)"
260     )
261   if( NOT FF_PARAVIEW3_APP )
262     message( FATAL_ERROR "Failed to find the ParaView 3 executable or application bundle" )
263   endif( NOT FF_PARAVIEW3_APP )
264 endif( FF_BUILD_PARAVIEW_PLUGINS )
265 mark_as_advanced( FF_BUILD_PARAVIEW_PLUGINS FF_PARAVIEW3_APP )
267 # figure out default Pstream library
268 if( FF_USE_MPI )
269   set( _FF_DEFAULT_PSTREAM mpi )
270 elseif( FF_USE_PVM )
271   set( _FF_DEFAULT_PSTREAM pvm )
272 elseif( FF_USE_GAMMA )
273   set( _FF_DEFAULT_PSTREAM gamma )
274 else( FF_USE_MPI )
275   set( _FF_DEFAULT_PSTREAM dummy )
276 endif( FF_USE_MPI )
277 set( FF_DEFAULT_PSTREAM ${_FF_DEFAULT_PSTREAM} CACHE STRING "Default Pstream library implementation [dummy|mpi|pvm|gamma]" )
278 mark_as_advanced( FF_DEFAULT_PSTREAM )
280 # ask user whether she wants to build Doxygen docs
281 option( FF_ENABLE_DOXYGEN_DOCS "Build the Doxygen documentation" OFF )
282 if( FF_ENABLE_DOXYGEN_DOCS )
283   find_package( Doxygen REQUIRED )
284 endif( FF_ENABLE_DOXYGEN_DOCS )
285 mark_as_advanced( FF_ENABLE_DOXYGEN_DOCS )
287 # find m4 macro processor
288 find_program( M4_EXECUTABLE m4 DOC "Path to the m4 macro processor" )
289 mark_as_advanced( M4_EXECUTABLE )
290 if( NOT M4_EXECUTABLE )
291   message( "WARNING: Failed to find M4 macro processor. Some of the tutorials will fail if it can't be found." )
292   set( M4_EXECUTABLE m4 )
293 endif( NOT M4_EXECUTABLE )
295 # on APPLE use cp -R -P -p, otherwise use cp -a
296 if( APPLE )
297   set( FF_CP_A_FLAGS "-R -P -p" )
298 else( APPLE )
299   set( FF_CP_A_FLAGS "-a" )
300 endif( APPLE )
303 # set up defines
304 add_definitions(
305   -D${FF_PRECISION}
306   -DNoRepository
307   -D${FF_OS}
308   )
310 # tools for building the include tree
311 include( createIncludeWrappers )
312 include_directories( ${CMAKE_BINARY_DIR}/include )
314 # descend into the sources...
315 add_subdirectory( bin )
316 add_subdirectory( etc )
317 add_subdirectory( data )
318 add_subdirectory( src )
319 add_subdirectory( applications )
320 add_subdirectory( doc )
321 add_subdirectory( tutorials )
323 # export the library dependencies to the build tree
324 ff_export_targets_to_build_tree()
326 # export build settings and library dependencies
327 include( CMakeExportBuildSettings )
328 cmake_export_build_settings( ${FF_LIBRARY_OUTPUT_DIRECTORY}/FreeFOAMBuildSettings.cmake )
330 # create FreeFOAMConfig.cmake for the build tree
331 set( CONFIG_DEFINITIONS -DNoRepository -D${FF_OS} -D${FF_PRECISION} )
332 if( APPLE )
333   list( APPEND CONFIG_DEFINITIONS -Ddarwin )
334 endif( APPLE )
335 set( CONFIG_HEADER_PATH ${CMAKE_BINARY_DIR}/include )
336 set( CONFIG_LIBRARY_PATH ${FF_LIBRARY_OUTPUT_DIRECTORY} )
337 if( APPLE AND FF_BUILD_FRAMEWORK )
338   set( CONFIG_FRAMEWORK_PATH "${FF_FRAMEWORK_OUTPUT_DIRECTORY}" )
339 endif( APPLE AND FF_BUILD_FRAMEWORK )
340 set( CONFIG_USE_FILE_PATH ${CMAKE_SOURCE_DIR} )
341 configure_file(
342   ${CMAKE_SOURCE_DIR}/FreeFOAMConfig.cmake.in
343   ${CMAKE_BINARY_DIR}/FreeFOAMConfig.cmake
344   @ONLY
345   )
347 # create FreeFOAMConfig.cmake for the install tree
348 set( CONFIG_HEADER_PATH "${FF_INSTALL_HEADER_PATH}" )
349 set( CONFIG_LIBRARY_PATH "${FF_INSTALL_LIB_PATH}" )
350 if( APPLE AND FF_BUILD_FRAMEWORK )
351   set( CONFIG_FRAMEWORK_PATH "${FF_INSTALL_FRAMEWORK_PATH}" )
352 endif( APPLE AND FF_BUILD_FRAMEWORK )
353 set( CONFIG_USE_FILE_PATH "${FF_INSTALL_LIB_PATH}" )
354 configure_file(
355   ${CMAKE_SOURCE_DIR}/FreeFOAMConfig.cmake.in
356   ${CMAKE_BINARY_DIR}/InstallFiles/FreeFOAMConfig.cmake
357   @ONLY
358   )
360 # install the CMake config files
361 install( FILES
362   FreeFOAMUse.cmake
363   ${CMAKE_BINARY_DIR}/InstallFiles/FreeFOAMConfig.cmake
364   ${FF_LIBRARY_OUTPUT_DIRECTORY}/FreeFOAMBuildSettings.cmake
365   DESTINATION ${FF_INSTALL_LIB_PATH}
366   COMPONENT dev
367   )
369 # install the FreeFOAMLibraryDepends.cmake file
370 install( EXPORT FreeFOAMLibraryDepends
371   DESTINATION ${FF_INSTALL_LIB_PATH}
372   NAMESPACE FF_
373   COMPONENT dev
374   )
376 # pack things up
377 include( FreeFOAMCPack )
379 # uninstall target
380 configure_file(
381   "${CMAKE_SOURCE_DIR}/CMake/Modules/cmake_uninstall.cmake.in"
382   "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake"
383   @ONLY
384   )
386 add_custom_target( uninstall
387   "${CMAKE_COMMAND}" -P "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake"
388   )
390 # ------------------------- vim: set sw=2 sts=2 et: --------------- end-of-file