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 #-------------------------------------------------------------------------------
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
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 #-------------------------------------------------------------------------------
34 cmake_minimum_required( VERSION 2.6.0 )
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
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
59 option( FF_BUILD_FRAMEWORK "Build frameworks on Mac OS X" ON )
61 set( FF_BUILD_FRAMEWORK OFF )
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 )
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}} )
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" )
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 )
139 find_package( MPI REQUIRED )
141 option( FF_USE_PVM "Build ${CMAKE_PROJECT} against PVM parallel libraries" OFF )
143 find_package( PVM REQUIRED )
145 if( CMAKE_SYSTEM_NAME STREQUAL Linux )
146 option( FF_USE_GAMMA "Build ${CMAKE_PROJECT} against GAMMA parallel libraries" OFF )
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 )
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 )
162 find_package( ZLIB REQUIRED )
164 message( SEND_ERROR "zlib is required! Override ZLIB_* settings [advanced]." )
165 endif( NOT ZLIB_FOUND )
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)
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 )
204 message( STATUS "NOTE: Not using ParMetis because FF_USE_MPI not selected." )
207 # find mgridgen (not commonly available, default to private build)
208 option( FF_BUILD_PRIVATE_PARMGRIDGEN "Download and compile private PARMGRIDGEN library instead of searching the system for it" OFF )
209 ff_detect_changed_value( FF_BUILD_PRIVATE_PARMGRIDGEN_CHANGED FF_BUILD_PRIVATE_PARMGRIDGEN
210 MGRIDGEN_INCLUDE_DIR MGRIDGEN_LIBRARY )
211 if( FF_BUILD_PRIVATE_PARMGRIDGEN )
212 add_subdirectory( ThirdParty/PARMGRIDGEN )
213 else( FF_BUILD_PRIVATE_PARMGRIDGEN )
214 if( NOT FF_DOUBLE_PRECISION )
215 set( MGRIDGEN_USE_REAL ON )
216 endif( NOT FF_DOUBLE_PRECISION )
217 find_package( MGRIDGEN REQUIRED )
218 if( NOT MGRIDGEN_FOUND )
219 message( SEND_ERROR "MGRIDGEN is required! Override MGRIDGEN_* settings [advanced]." )
220 endif( NOT MGRIDGEN_FOUND )
221 endif( FF_BUILD_PRIVATE_PARMGRIDGEN )
223 # find ccmio (not commonly available, default to private build)
224 option( FF_BUILD_PRIVATE_CCMIO "Download and compile private CCMIO library instead of searching the system for it" OFF )
225 ff_detect_changed_value( FF_BUILD_PRIVATE_CCMIO_CHANGED FF_BUILD_PRIVATE_CCMIO
226 CCMIO_INCLUDE_DIR CCMIO_LIBRARY )
227 if( FF_BUILD_PRIVATE_CCMIO )
228 add_subdirectory( ThirdParty/ccmio )
229 else( FF_BUILD_PRIVATE_CCMIO )
230 find_package( Ccmio REQUIRED )
231 if( NOT CCMIO_FOUND )
232 message( SEND_ERROR "ccmio is required! Override CCMIO_* settings [advanced]." )
233 endif( NOT CCMIO_FOUND )
234 endif( FF_BUILD_PRIVATE_CCMIO )
236 mark_as_advanced( FF_BUILD_PRIVATE_CCMIO FF_BUILD_PRIVATE_METIS FF_BUILD_PRIVATE_PARMETIS
237 FF_BUILD_PRIVATE_PARMGRIDGEN FF_DOUBLE_PRECISION )
239 # ask user whether she wants to build ParaView plugins
240 option( FF_BUILD_PARAVIEW_PLUGINS "Build the ParaView plugins. Requires a ParaView build tree." ON )
241 if( FF_BUILD_PARAVIEW_PLUGINS )
242 # find ParaView, which also find the VTK which has been used to build ParaView
243 find_package( ParaView REQUIRED )
244 if( NOT ParaView_FOUND )
245 message( FATAL_ERROR "Failed to find the ParaView build tree. Specify ParaView_DIR or disable FF_BUILD_PARAVIEW_PLUGINS" )
246 endif( NOT ParaView_FOUND )
247 # find the installed ParaView executable
249 FF_PARAVIEW3_APP NAMES paraview paraview.app
250 PATHS ${ParaView_DIR}/bin
251 DOC "Path to the ParaView 3 executable (or application bundle on Mac OS X)"
253 if( NOT FF_PARAVIEW3_APP )
254 message( FATAL_ERROR "Failed to find the ParaView 3 executable or application bundle" )
255 endif( NOT FF_PARAVIEW3_APP )
256 endif( FF_BUILD_PARAVIEW_PLUGINS )
257 mark_as_advanced( FF_BUILD_PARAVIEW_PLUGINS FF_PARAVIEW3_APP )
259 # figure out default Pstream library
261 set( _FF_DEFAULT_PSTREAM mpi )
263 set( _FF_DEFAULT_PSTREAM pvm )
264 elseif( FF_USE_GAMMA )
265 set( _FF_DEFAULT_PSTREAM gamma )
267 set( _FF_DEFAULT_PSTREAM dummy )
269 set( FF_DEFAULT_PSTREAM ${_FF_DEFAULT_PSTREAM} CACHE STRING "Default Pstream library implementation [dummy|mpi|pvm|gamma]" )
270 mark_as_advanced( FF_DEFAULT_PSTREAM )
272 # ask user whether she wants to build Doxygen docs
273 option( FF_ENABLE_DOXYGEN_DOCS "Build the Doxygen documentation" OFF )
274 if( FF_ENABLE_DOXYGEN_DOCS )
275 find_package( Doxygen REQUIRED )
276 endif( FF_ENABLE_DOXYGEN_DOCS )
277 mark_as_advanced( FF_ENABLE_DOXYGEN_DOCS )
279 # find m4 macro processor
280 find_program( M4_EXECUTABLE m4 DOC "Path to the m4 macro processor" )
281 mark_as_advanced( M4_EXECUTABLE )
282 if( NOT M4_EXECUTABLE )
283 message( "WARNING: Failed to find M4 macro processor. Some of the tutorials will fail if it can't be found." )
284 set( M4_EXECUTABLE m4 )
285 endif( NOT M4_EXECUTABLE )
287 # on APPLE use cp -R -P -p, otherwise use cp -a
289 set( FF_CP_A_FLAGS "-R -P -p" )
291 set( FF_CP_A_FLAGS "-R -P -p" )
302 # tools for building the include tree
303 include( createIncludeWrappers )
304 include_directories( ${CMAKE_BINARY_DIR}/include )
306 # descend into the sources...
307 add_subdirectory( bin )
308 add_subdirectory( etc )
309 add_subdirectory( data )
310 add_subdirectory( src )
311 add_subdirectory( applications )
312 add_subdirectory( doc )
313 add_subdirectory( tutorials )
315 # export the library dependencies to the build tree
316 ff_export_targets_to_build_tree()
318 # export build settings and library dependencies
319 include( CMakeExportBuildSettings )
320 cmake_export_build_settings( ${FF_LIBRARY_OUTPUT_DIRECTORY}/FreeFOAMBuildSettings.cmake )
322 # create FreeFOAMConfig.cmake for the build tree
323 set( CONFIG_DEFINITIONS -DNoRepository -D${FF_OS} -D${FF_PRECISION} )
325 list( APPEND CONFIG_DEFINITIONS -Ddarwin )
327 set( CONFIG_HEADER_PATH ${CMAKE_BINARY_DIR}/include )
328 set( CONFIG_LIBRARY_PATH ${FF_LIBRARY_OUTPUT_DIRECTORY} )
329 if( APPLE AND FF_BUILD_FRAMEWORK )
330 set( CONFIG_FRAMEWORK_PATH "${FF_FRAMEWORK_OUTPUT_DIRECTORY}" )
331 endif( APPLE AND FF_BUILD_FRAMEWORK )
332 set( CONFIG_USE_FILE_PATH ${CMAKE_SOURCE_DIR} )
334 ${CMAKE_SOURCE_DIR}/FreeFOAMConfig.cmake.in
335 ${CMAKE_BINARY_DIR}/FreeFOAMConfig.cmake
339 # create FreeFOAMConfig.cmake for the install tree
340 set( CONFIG_HEADER_PATH "${FF_INSTALL_HEADER_PATH}" )
341 set( CONFIG_LIBRARY_PATH "${FF_INSTALL_LIB_PATH}" )
342 if( APPLE AND FF_BUILD_FRAMEWORK )
343 set( CONFIG_FRAMEWORK_PATH "${FF_INSTALL_FRAMEWORK_PATH}" )
344 endif( APPLE AND FF_BUILD_FRAMEWORK )
345 set( CONFIG_USE_FILE_PATH "${FF_INSTALL_LIB_PATH}" )
347 ${CMAKE_SOURCE_DIR}/FreeFOAMConfig.cmake.in
348 ${CMAKE_BINARY_DIR}/InstallFiles/FreeFOAMConfig.cmake
352 # install the CMake config files
355 ${CMAKE_BINARY_DIR}/InstallFiles/FreeFOAMConfig.cmake
356 ${FF_LIBRARY_OUTPUT_DIRECTORY}/FreeFOAMBuildSettings.cmake
357 DESTINATION ${FF_INSTALL_LIB_PATH}
361 # install the FreeFOAMLibraryDepends.cmake file
362 install( EXPORT FreeFOAMLibraryDepends
363 DESTINATION ${FF_INSTALL_LIB_PATH}
369 include( FreeFOAMCPack )
373 "${CMAKE_SOURCE_DIR}/CMake/Modules/cmake_uninstall.cmake.in"
374 "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake"
378 add_custom_target( uninstall
379 "${CMAKE_COMMAND}" -P "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake"
382 # ------------------------- vim: set sw=2 sts=2 et: --------------- end-of-file