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 set( FF_PRECISION DP CACHE STRING "Precision with which to compile FreeFOAM. [DP|SP]" )
53 # select whether we want to build framewors on Mac OS X
55 option( FF_BUILD_FRAMEWORK "Build frameworks on Mac OS X" ON )
57 set( FF_BUILD_FRAMEWORK OFF )
60 # we want shared libraries
61 set( BUILD_SHARED_LIBS SHARED )
63 # use a prefix for executables
64 set (EXECUTABLE_PREFIX "ff_" CACHE STRING "Prefix prepended to all program and script names")
66 # installation directories
67 set( FF_INSTALL_BIN_PATH bin CACHE STRING "Executables installation path (absolute or relative to CMAKE_INSTALL_PREFIX)" )
68 if( APPLE AND FF_BUILD_FRAMEWORK )
69 set( FF_INSTALL_LIB_PATH /Library/Frameworks CACHE STRING "Framework installation path (absolute or relative to CMAKE_INSTALL_PREFIX)" )
70 else( APPLE AND FF_BUILD_FRAMEWORK )
71 set( FF_INSTALL_LIB_PATH lib/${CMAKE_PROJECT_NAME}/${FF_VERSION} CACHE STRING "Library installation path (absolute or relative to CMAKE_INSTALL_PREFIX)" )
72 endif( APPLE AND FF_BUILD_FRAMEWORK )
73 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)" )
74 set( FF_INSTALL_CONFIG_PATH etc/${CMAKE_PROJECT_NAME}/${FF_VERSION} CACHE STRING "Configuration files installation path (absolute or relative to CMAKE_INSTALL_PREFIX)" )
75 set( FF_INSTALL_DATA_PATH share/${CMAKE_PROJECT_NAME}/${FF_VERSION} CACHE STRING "Data files installation path (absolute or relative to CMAKE_INSTALL_PREFIX)" )
76 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)" )
77 set( FF_INSTALL_PVFOAMREADER_PATH lib/${CMAKE_PROJECT_NAME}/${FF_VERSION}/plugins/PVFoamReader CACHE STRING "ParaView2 OpenFOAM-reader plugin installation path" )
78 set( FF_INSTALL_PV3FOAMREADER_PATH lib/${CMAKE_PROJECT_NAME}/${FF_VERSION}/plugins/PV3FoamReader CACHE STRING "ParaView3 OpenFOAM-reader plugin installation path" )
79 set( FF_INSTALL_USERDFOAM_PATH lib/${CMAKE_PROJECT_NAME}/${FF_VERSION}/plugins/userd-foam CACHE STRING "Ensight OpenFOAM-reader plugin installation path" )
82 foreach( _p FF_INSTALL_BIN_PATH FF_INSTALL_LIB_PATH FF_INSTALL_HEADER_PATH
83 FF_INSTALL_CONFIG_PATH FF_INSTALL_DATA_PATH FF_INSTALL_DOC_PATH )
84 if( NOT IS_ABSOLUTE ${${_p}} )
85 set( ${_p} "${CMAKE_INSTALL_PREFIX}/${${_p}}" )
86 endif( NOT IS_ABSOLUTE ${${_p}} )
89 # select html documentation browser (try a few well known ones for default)
90 # have to loop, because find_program( HTML_DOC_BROWSER NAMES ... ) garbles things up
91 foreach( browser open kde-open gnome-open x-www-browser www-browser firefox epiphany konqueror w3m lynx open )
92 find_program( HTML_DOC_BROWSER ${browser}
93 DOC "Program to open an HTML file" )
94 if( HTML_DOC_BROWSER )
95 set( FF_HTML_DOC_BROWSER_COMMAND "${HTML_DOC_BROWSER} %f" CACHE STRING "Command to open an HTML file" )
97 endif( HTML_DOC_BROWSER )
99 if( NOT HTML_DOC_BROWSER )
100 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." )
101 endif( NOT HTML_DOC_BROWSER )
102 mark_as_advanced( HTML_DOC_BROWSER FF_HTML_DOC_BROWSER_COMMAND )
104 # set up the RPATH for installation
105 set( CMAKE_INSTALL_RPATH ${FF_INSTALL_LIB_PATH} )
107 # we want executables and libraries in one place
108 set( EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin CACHE PATH
109 "Single output directory for building all executables." )
110 set( LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib/FreeFOAM/${FF_VERSION} CACHE PATH
111 "Single output directory for building all libraries." )
113 # determine computer system
114 include( FFDetermineArch )
116 # find parallel libraries
117 option( FF_USE_MPI "Build ${CMAKE_PROJECT} against MPI parallel libraries" ON )
119 find_package( MPI REQUIRED )
121 option( FF_USE_PVM "Build ${CMAKE_PROJECT} against PVM parallel libraries" OFF )
123 find_package( PVM REQUIRED )
125 if( CMAKE_SYSTEM_NAME STREQUAL Linux )
126 option( FF_USE_GAMMA "Build ${CMAKE_PROJECT} against GAMMA parallel libraries" OFF )
128 find_package( GAMMA REQUIRED )
129 endif( FF_USE_GAMMA )
130 endif( CMAKE_SYSTEM_NAME STREQUAL Linux )
131 if( MPI_FOUND OR PVM_FOUND OR GAMMA_FOUND )
132 set( FF_USE_PARALLEL TRUE )
133 endif( MPI_FOUND OR PVM_FOUND OR GAMMA_FOUND )
136 find_package( FLEX REQUIRED )
137 set( FLEX_CXX_FLAGS "-+" CACHE STRING "Flags used by the flex compiler for flex++ targets." )
138 mark_as_advanced( FLEX_CXX_FLAGS )
141 find_package( ZLIB REQUIRED )
143 message( SEND_ERROR "zlib is required! Override ZLIB_* settings [advanced]." )
144 endif( NOT ZLIB_FOUND )
147 include( FFLinkLoadableLibrary )
148 include( FFExportTargetsToBuildTree )
150 # find metis (recent distros have it in their repository, so default to search for that)
151 option( FF_BUILD_PRIVATE_METIS "Download and compile private METIS library instead of searching the system for it" OFF )
152 if( FF_BUILD_PRIVATE_METIS )
153 find_package( Threads REQUIRED )
154 add_subdirectory( ThirdParty/METIS )
155 else( FF_BUILD_PRIVATE_METIS )
156 find_package( Metis REQUIRED )
157 if( NOT METIS_FOUND )
158 message( SEND_ERROR "metis is required! Override METIS_* settings [advanced]." )
159 endif( NOT METIS_FOUND )
160 if( METIS_REQUIRES_MPI AND NOT FF_USE_MPI )
161 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." )
162 endif( METIS_REQUIRES_MPI AND NOT FF_USE_MPI )
163 endif( FF_BUILD_PRIVATE_METIS )
165 # find ParMetis (recent distros have it in their repository, so default to search for that)
167 option( FF_BUILD_PRIVATE_PARMETIS "Download and compile private ParMetis library instead of searching the system for it" OFF )
168 if( FF_BUILD_PRIVATE_PARMETIS )
169 add_subdirectory( ThirdParty/ParMetis )
170 else( FF_BUILD_PRIVATE_PARMETIS )
171 find_package( ParMetis REQUIRED )
172 if( NOT PARMETIS_FOUND )
173 message( SEND_ERROR "ParMetis is required! Override PARMETIS_* settings [advanced]." )
174 endif( NOT PARMETIS_FOUND )
175 endif( FF_BUILD_PRIVATE_PARMETIS )
177 message( STATUS "NOTE: Not using ParMetis because FF_USE_MPI not selected." )
180 # find mgridgen (not commonly available, default to private build)
181 option( FF_BUILD_PRIVATE_PARMGRIDGEN "Download and compile private PARMGRIDGEN library instead of searching the system for it" ON )
182 if( FF_BUILD_PRIVATE_PARMGRIDGEN )
183 add_subdirectory( ThirdParty/PARMGRIDGEN )
184 else( FF_BUILD_PRIVATE_PARMGRIDGEN )
185 if( FF_PRECISION STREQUAL SP )
186 set( MGRIDGEN_USE_REAL ON )
187 endif( FF_PRECISION STREQUAL SP )
188 find_package( MGRIDGEN REQUIRED )
189 if( NOT MGRIDGEN_FOUND )
190 message( SEND_ERROR "MGRIDGEN is required! Override MGRIDGEN_* settings [advanced]." )
191 endif( NOT MGRIDGEN_FOUND )
192 endif( FF_BUILD_PRIVATE_PARMGRIDGEN )
194 # find ccmio (not commonly available, default to private build)
195 option( FF_BUILD_PRIVATE_CCMIO "Download and compile private CCMIO library instead of searching the system for it" ON )
196 if( FF_BUILD_PRIVATE_CCMIO )
197 add_subdirectory( ThirdParty/ccmio )
198 else( FF_BUILD_PRIVATE_CCMIO )
199 find_package( Ccmio REQUIRED )
200 if( NOT CCMIO_FOUND )
201 message( SEND_ERROR "ccmio is required! Override CCMIO_* settings [advanced]." )
202 endif( NOT CCMIO_FOUND )
203 endif( FF_BUILD_PRIVATE_CCMIO )
205 # ask user whether she wants to build ParaView plugins
206 option( FF_BUILD_PARAVIEW_PLUGINS "Build the ParaView plugins. Requires a ParaView build tree." ON )
207 if( FF_BUILD_PARAVIEW_PLUGINS )
208 # find ParaView, which also find the VTK which has been used to build ParaView
209 find_package( ParaView REQUIRED )
210 endif( FF_BUILD_PARAVIEW_PLUGINS )
212 # figure out default Pstream library
214 set( _FF_DEFAULT_PSTREAM mpi )
216 set( _FF_DEFAULT_PSTREAM pvm )
217 elseif( FF_USE_GAMMA )
218 set( _FF_DEFAULT_PSTREAM gamma )
220 set( _FF_DEFAULT_PSTREAM dummy )
222 set( FF_DEFAULT_PSTREAM ${_FF_DEFAULT_PSTREAM} CACHE STRING "Default Pstream library implementation [dummy|mpi|pvm|gamma]" )
223 mark_as_advanced( FF_DEFAULT_PSTREAM )
232 # tools for building the include tree
233 include( createIncludeWrappers )
234 include_directories( ${CMAKE_BINARY_DIR}/include )
236 # descend into the sources...
237 add_subdirectory( bin )
238 add_subdirectory( etc )
239 add_subdirectory( data )
240 add_subdirectory( src )
241 add_subdirectory( applications )
243 # export the library dependencies to the build tree
244 ff_export_targets_to_build_tree()
246 # export build settings and library dependencies
247 include( CMakeExportBuildSettings )
248 cmake_export_build_settings( ${LIBRARY_OUTPUT_PATH}/FreeFOAMBuildSettings.cmake )
250 # create FreeFOAMConfig.cmake for the build tree
251 set( CONFIG_DEFINITIONS -DNoRepository -D${FF_OS} -D${FF_PRECISION} )
253 list( APPEND CONFIG_DEFINITIONS -Ddarwin )
255 set( CONFIG_HEADER_PATH ${CMAKE_BINARY_DIR}/include )
256 set( CONFIG_LIBRARY_PATH ${LIBRARY_OUTPUT_PATH} )
257 set( CONFIG_USE_FILE_PATH ${CMAKE_SOURCE_DIR} )
259 ${CMAKE_SOURCE_DIR}/FreeFOAMConfig.cmake.in
260 ${CMAKE_BINARY_DIR}/FreeFOAMConfig.cmake
264 # create FreeFOAMConfig.cmake for the install tree
265 set( CONFIG_HEADER_PATH ${FF_INSTALL_HEADER_PATH} )
266 set( CONFIG_LIBRARY_PATH ${FF_INSTALL_LIB_PATH} )
267 set( CONFIG_USE_FILE_PATH ${FF_INSTALL_LIB_PATH} )
269 ${CMAKE_SOURCE_DIR}/FreeFOAMConfig.cmake.in
270 ${CMAKE_BINARY_DIR}/InstallFiles/FreeFOAMConfig.cmake
274 # install the CMake config files
277 ${CMAKE_BINARY_DIR}/InstallFiles/FreeFOAMConfig.cmake
278 ${LIBRARY_OUTPUT_PATH}/FreeFOAMBuildSettings.cmake
279 DESTINATION ${FF_INSTALL_LIB_PATH}
283 # install the FreeFOAMLibraryDepends.cmake file
284 install( EXPORT FreeFOAMLibraryDepends
285 DESTINATION ${FF_INSTALL_LIB_PATH}
291 include( FreeFOAMCPack )
293 # ------------------------- vim: set sw=2 sts=2 et: --------------- end-of-file