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 1 )
38 set( FF_VERSION_MINOR 5 )
39 set( FF_VERSION_PATCH 0 )
40 set( FF_VERSION_REVISION 0 )
41 set( FF_VERSION ${FF_VERSION_MAJOR}.${FF_VERSION_MINOR}.${FF_VERSION_PATCH} )
42 set( FF_VERSION_FULL ${FF_VERSION}-${FF_VERSION_REVISION} )
44 # set up custom cmake module path
45 set( CMAKE_MODULE_PATH
46 ${CMAKE_SOURCE_DIR}/CMake
47 ${CMAKE_SOURCE_DIR}/CMake/Modules
51 option( FF_DOUBLE_PRECISION "Compile FreeFOAM with double precision floating point arithmetics." ON )
52 if( FF_DOUBLE_PRECISION )
53 set( FF_PRECISION DP )
54 else( FF_DOUBLE_PRECISION )
55 set( FF_PRECISION SP )
56 endif( FF_DOUBLE_PRECISION )
58 # select whether we want to build framewors on Mac OS X
60 option( FF_BUILD_FRAMEWORK "Build frameworks on Mac OS X" ON )
62 set( FF_BUILD_FRAMEWORK OFF )
64 mark_as_advanced( FF_BUILD_FRAMEWORK )
66 # we want shared libraries
67 set( BUILD_SHARED_LIBS SHARED )
69 # use a prefix for executables
70 set (EXECUTABLE_PREFIX "ff_" CACHE STRING "Prefix prepended to all program and script names")
71 mark_as_advanced( EXECUTABLE_PREFIX )
73 # installation directories
74 set( FF_INSTALL_BIN_PATH bin CACHE STRING "Executables installation path (absolute or relative to CMAKE_INSTALL_PREFIX)" )
75 if( APPLE AND FF_BUILD_FRAMEWORK )
76 set( FF_INSTALL_LIB_PATH /Library/Frameworks CACHE STRING "Framework installation path (absolute or relative to CMAKE_INSTALL_PREFIX)" )
77 else( APPLE AND FF_BUILD_FRAMEWORK )
78 set( FF_INSTALL_LIB_PATH lib/${CMAKE_PROJECT_NAME}/${FF_VERSION} CACHE STRING "Library installation path (absolute or relative to CMAKE_INSTALL_PREFIX)" )
79 endif( APPLE AND FF_BUILD_FRAMEWORK )
80 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)" )
81 set( FF_INSTALL_CONFIG_PATH etc/${CMAKE_PROJECT_NAME}/${FF_VERSION} CACHE STRING "Configuration files installation path (absolute or relative to CMAKE_INSTALL_PREFIX)" )
82 set( FF_INSTALL_DATA_PATH share/${CMAKE_PROJECT_NAME}/${FF_VERSION} CACHE STRING "Data files installation path (absolute or relative to CMAKE_INSTALL_PREFIX)" )
83 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)" )
84 set( FF_INSTALL_PVFOAMREADER_PATH lib/${CMAKE_PROJECT_NAME}/${FF_VERSION}/plugins/PVFoamReader CACHE STRING "ParaView2 OpenFOAM-reader plugin installation path" )
85 set( FF_INSTALL_PV3FOAMREADER_PATH lib/${CMAKE_PROJECT_NAME}/${FF_VERSION}/plugins/PV3FoamReader CACHE STRING "ParaView3 OpenFOAM-reader plugin installation path" )
86 set( FF_INSTALL_USERDFOAM_PATH lib/${CMAKE_PROJECT_NAME}/${FF_VERSION}/plugins/userd-foam CACHE STRING "Ensight OpenFOAM-reader plugin installation path" )
87 mark_as_advanced( FF_INSTALL_BIN_PATH FF_INSTALL_LIB_PATH FF_INSTALL_HEADER_PATH FF_INSTALL_CONFIG_PATH FF_INSTALL_DATA_PATH
88 FF_INSTALL_DOC_PATH FF_INSTALL_PVFOAMREADER_PATH FF_INSTALL_PV3FOAMREADER_PATH FF_INSTALL_USERDFOAM_PATH )
91 foreach( _p FF_INSTALL_BIN_PATH FF_INSTALL_LIB_PATH FF_INSTALL_HEADER_PATH
92 FF_INSTALL_CONFIG_PATH FF_INSTALL_DATA_PATH FF_INSTALL_DOC_PATH )
93 if( NOT IS_ABSOLUTE ${${_p}} )
94 set( ${_p} "${CMAKE_INSTALL_PREFIX}/${${_p}}" )
95 endif( NOT IS_ABSOLUTE ${${_p}} )
98 # select html documentation browser (try a few well known ones for default)
99 # have to loop, because find_program( HTML_DOC_BROWSER NAMES ... ) garbles things up
100 foreach( browser open kde-open gnome-open x-www-browser www-browser firefox epiphany konqueror w3m lynx open )
101 find_program( HTML_DOC_BROWSER ${browser}
102 DOC "Program to open an HTML file" )
103 if( HTML_DOC_BROWSER )
104 set( FF_HTML_DOC_BROWSER_COMMAND "${HTML_DOC_BROWSER} %f" CACHE STRING "Command to open an HTML file" )
106 endif( HTML_DOC_BROWSER )
107 endforeach( browser )
108 if( NOT HTML_DOC_BROWSER )
109 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." )
110 endif( NOT HTML_DOC_BROWSER )
111 mark_as_advanced( HTML_DOC_BROWSER FF_HTML_DOC_BROWSER_COMMAND )
113 # set up the RPATH for installation
114 set( CMAKE_INSTALL_RPATH ${FF_INSTALL_LIB_PATH} )
116 # we want executables and libraries in one place
117 set( EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin )
118 set( LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib/FreeFOAM/${FF_VERSION} )
120 # determine computer system
121 include( FFDetermineArch )
123 # find parallel libraries
124 option( FF_USE_MPI "Build ${CMAKE_PROJECT} against MPI parallel libraries" ON )
126 find_package( MPI REQUIRED )
128 option( FF_USE_PVM "Build ${CMAKE_PROJECT} against PVM parallel libraries" OFF )
130 find_package( PVM REQUIRED )
132 if( CMAKE_SYSTEM_NAME STREQUAL Linux )
133 option( FF_USE_GAMMA "Build ${CMAKE_PROJECT} against GAMMA parallel libraries" OFF )
135 find_package( GAMMA REQUIRED )
136 endif( FF_USE_GAMMA )
137 endif( CMAKE_SYSTEM_NAME STREQUAL Linux )
138 if( MPI_FOUND OR PVM_FOUND OR GAMMA_FOUND )
139 set( FF_USE_PARALLEL TRUE )
140 endif( MPI_FOUND OR PVM_FOUND OR GAMMA_FOUND )
141 mark_as_advanced( FF_USE_MPI FF_USE_PVM FF_USE_GAMMA )
144 find_package( FLEX REQUIRED )
145 set( FLEX_CXX_FLAGS "-+" CACHE STRING "Flags used by the flex compiler for flex++ targets." )
146 mark_as_advanced( FLEX_CXX_FLAGS )
149 find_package( ZLIB REQUIRED )
151 message( SEND_ERROR "zlib is required! Override ZLIB_* settings [advanced]." )
152 endif( NOT ZLIB_FOUND )
155 include( FFLinkLoadableLibrary )
156 include( FFExportTargetsToBuildTree )
158 # find metis (recent distros have it in their repository, so default to search for that)
159 option( FF_BUILD_PRIVATE_METIS "Download and compile private METIS library instead of searching the system for it" OFF )
160 if( FF_BUILD_PRIVATE_METIS )
161 find_package( Threads REQUIRED )
162 add_subdirectory( ThirdParty/METIS )
163 else( FF_BUILD_PRIVATE_METIS )
164 find_package( Metis REQUIRED )
165 if( NOT METIS_FOUND )
166 message( SEND_ERROR "metis is required! Override METIS_* settings [advanced]." )
167 endif( NOT METIS_FOUND )
168 if( METIS_REQUIRES_MPI AND NOT FF_USE_MPI )
169 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." )
170 endif( METIS_REQUIRES_MPI AND NOT FF_USE_MPI )
171 endif( FF_BUILD_PRIVATE_METIS )
173 # find ParMetis (recent distros have it in their repository, so default to search for that)
175 option( FF_BUILD_PRIVATE_PARMETIS "Download and compile private ParMetis library instead of searching the system for it" OFF )
176 if( FF_BUILD_PRIVATE_PARMETIS )
177 add_subdirectory( ThirdParty/ParMetis )
178 else( FF_BUILD_PRIVATE_PARMETIS )
179 find_package( ParMetis REQUIRED )
180 if( NOT PARMETIS_FOUND )
181 message( SEND_ERROR "ParMetis is required! Override PARMETIS_* settings [advanced]." )
182 endif( NOT PARMETIS_FOUND )
183 endif( FF_BUILD_PRIVATE_PARMETIS )
185 message( STATUS "NOTE: Not using ParMetis because FF_USE_MPI not selected." )
188 # find mgridgen (not commonly available, default to private build)
189 option( FF_BUILD_PRIVATE_PARMGRIDGEN "Download and compile private PARMGRIDGEN library instead of searching the system for it" ON )
190 if( FF_BUILD_PRIVATE_PARMGRIDGEN )
191 add_subdirectory( ThirdParty/PARMGRIDGEN )
192 else( FF_BUILD_PRIVATE_PARMGRIDGEN )
193 if( NOT FF_DOUBLE_PRECISION )
194 set( MGRIDGEN_USE_REAL ON )
195 endif( NOT FF_DOUBLE_PRECISION )
196 find_package( MGRIDGEN REQUIRED )
197 if( NOT MGRIDGEN_FOUND )
198 message( SEND_ERROR "MGRIDGEN is required! Override MGRIDGEN_* settings [advanced]." )
199 endif( NOT MGRIDGEN_FOUND )
200 endif( FF_BUILD_PRIVATE_PARMGRIDGEN )
202 # find ccmio (not commonly available, default to private build)
203 option( FF_BUILD_PRIVATE_CCMIO "Download and compile private CCMIO library instead of searching the system for it" ON )
204 if( FF_BUILD_PRIVATE_CCMIO )
205 add_subdirectory( ThirdParty/ccmio )
206 else( FF_BUILD_PRIVATE_CCMIO )
207 find_package( Ccmio REQUIRED )
208 if( NOT CCMIO_FOUND )
209 message( SEND_ERROR "ccmio is required! Override CCMIO_* settings [advanced]." )
210 endif( NOT CCMIO_FOUND )
211 endif( FF_BUILD_PRIVATE_CCMIO )
213 mark_as_advanced( FF_BUILD_PRIVATE_CCMIO FF_BUILD_PRIVATE_METIS FF_BUILD_PRIVATE_PARMETIS
214 FF_BUILD_PRIVATE_PARMGRIDGEN FF_DOUBLE_PRECISION )
216 # ask user whether she wants to build ParaView plugins
217 option( FF_BUILD_PARAVIEW_PLUGINS "Build the ParaView plugins. Requires a ParaView build tree." ON )
218 if( FF_BUILD_PARAVIEW_PLUGINS )
219 # find ParaView, which also find the VTK which has been used to build ParaView
220 find_package( ParaView REQUIRED )
221 if( NOT ParaView_FOUND )
222 message( FATAL_ERROR "Failed to find the ParaView build tree. Specify ParaView_DIR or disable FF_BUILD_PARAVIEW_PLUGINS" )
223 endif( NOT ParaView_FOUND )
224 # find the installed ParaView executable
226 FF_PARAVIEW3_APP NAMES paraview paraview.app
227 PATHS ${ParaView_DIR}/bin
228 DOC "Path to the ParaView 3 executable (or application bundle on Mac OS X)"
230 if( NOT FF_PARAVIEW3_APP )
231 message( FATAL_ERROR "Failed to find the ParaView 3 executable or application bundle" )
232 endif( NOT FF_PARAVIEW3_APP )
233 endif( FF_BUILD_PARAVIEW_PLUGINS )
234 mark_as_advanced( FF_BUILD_PARAVIEW_PLUGINS FF_PARAVIEW3_APP )
236 # figure out default Pstream library
238 set( _FF_DEFAULT_PSTREAM mpi )
240 set( _FF_DEFAULT_PSTREAM pvm )
241 elseif( FF_USE_GAMMA )
242 set( _FF_DEFAULT_PSTREAM gamma )
244 set( _FF_DEFAULT_PSTREAM dummy )
246 set( FF_DEFAULT_PSTREAM ${_FF_DEFAULT_PSTREAM} CACHE STRING "Default Pstream library implementation [dummy|mpi|pvm|gamma]" )
247 mark_as_advanced( FF_DEFAULT_PSTREAM )
249 # ask user whether she wants to build Doxygen docs
250 option( FF_ENABLE_DOXYGEN_DOCS "Build the Doxygen documentation" OFF )
251 if( FF_ENABLE_DOXYGEN_DOCS )
252 find_package( Doxygen REQUIRED )
253 endif( FF_ENABLE_DOXYGEN_DOCS )
254 mark_as_advanced( FF_ENABLE_DOXYGEN_DOCS )
263 # tools for building the include tree
264 include( createIncludeWrappers )
265 include_directories( ${CMAKE_BINARY_DIR}/include )
267 # descend into the sources...
268 add_subdirectory( bin )
269 add_subdirectory( etc )
270 add_subdirectory( data )
271 add_subdirectory( src )
272 add_subdirectory( applications )
273 add_subdirectory( doc )
275 # export the library dependencies to the build tree
276 ff_export_targets_to_build_tree()
278 # export build settings and library dependencies
279 include( CMakeExportBuildSettings )
280 cmake_export_build_settings( ${LIBRARY_OUTPUT_PATH}/FreeFOAMBuildSettings.cmake )
282 # create FreeFOAMConfig.cmake for the build tree
283 set( CONFIG_DEFINITIONS -DNoRepository -D${FF_OS} -D${FF_PRECISION} )
285 list( APPEND CONFIG_DEFINITIONS -Ddarwin )
287 set( CONFIG_HEADER_PATH ${CMAKE_BINARY_DIR}/include )
288 set( CONFIG_LIBRARY_PATH ${LIBRARY_OUTPUT_PATH} )
289 set( CONFIG_USE_FILE_PATH ${CMAKE_SOURCE_DIR} )
291 ${CMAKE_SOURCE_DIR}/FreeFOAMConfig.cmake.in
292 ${CMAKE_BINARY_DIR}/FreeFOAMConfig.cmake
296 # create FreeFOAMConfig.cmake for the install tree
297 set( CONFIG_HEADER_PATH ${FF_INSTALL_HEADER_PATH} )
298 set( CONFIG_LIBRARY_PATH ${FF_INSTALL_LIB_PATH} )
299 set( CONFIG_USE_FILE_PATH ${FF_INSTALL_LIB_PATH} )
301 ${CMAKE_SOURCE_DIR}/FreeFOAMConfig.cmake.in
302 ${CMAKE_BINARY_DIR}/InstallFiles/FreeFOAMConfig.cmake
306 # install the CMake config files
309 ${CMAKE_BINARY_DIR}/InstallFiles/FreeFOAMConfig.cmake
310 ${LIBRARY_OUTPUT_PATH}/FreeFOAMBuildSettings.cmake
311 DESTINATION ${FF_INSTALL_LIB_PATH}
315 # install the FreeFOAMLibraryDepends.cmake file
316 install( EXPORT FreeFOAMLibraryDepends
317 DESTINATION ${FF_INSTALL_LIB_PATH}
323 include( FreeFOAMCPack )
325 # ------------------------- vim: set sw=2 sts=2 et: --------------- end-of-file