1 # - Use module for @PROJECT_NAME@
2 # Sets up a CMake project to use @PROJECT_NAME@. It is assumend that
3 # @PROJECT_NAME@Config.cmake has already been loaded.
5 # Typical usage might look like this:
7 # cmake_minimum_required(VERSION 2.8)
8 # project(some_project CXX)
9 # find_package(@PROJECT_NAME@ REQUIRED)
10 # include(${FOAM_USE_FILE})
11 # foam_add_library(some_library lib_src.C)
12 # foam_add_executable(some_solver sol_src.C)
13 # target_link_libraries(some_solver some_library FOAM_finiteVolume)
15 # Note that all functions are prefixed by foam_ and that linking against
16 # @PROJECT_NAME@ libraries requires prefixing FOAM_ to their name in order to
21 # Some of the libraries in @PROJECT_NAME@ are only used through abstract base
22 # classes, e.g. a lot of solvers use the Foam::incompressible::turbulenceModel
23 # abstract base class, and never explicitly reference a symbol from the
24 # FOAM_incompressibleRASModels library. This has the consequence, that if the
25 # --as-needed linker flag is used (on recent Linux systems it even is the
26 # default), the linker drops the FOAM_incompressibleRASModels, although it has
27 # been specified since no symbol from the library is being used. To prevent
28 # this from happening, for some of the libraries special source files are
29 # provided which can be used to force the linker to not drop the library. The
30 # following table gives an overview over the provided variables and the library
33 # FOAM_FORCE_LINK_COMPRESSIBLE_RAS_MODELS - FOAM_compressibleRASModels
34 # FOAM_FORCE_LINK_COMPRESSIBLE_LES_MODELS - FOAM_compressibleLESModels
35 # FOAM_FORCE_LINK_INCOMPRESSIBLE_RAS_MODELS - FOAM_incompressibleRASModels
36 # FOAM_FORCE_LINK_INCOMPRESSIBLE_LES_MODELS - FOAM_incompressibleLESModels
37 # FOAM_FORCE_LINK_GENERIC_PATCH_FIELDS - FOAM_genericPatchFields
38 # FOAM_FORCE_LINK_RADIATION - FOAM_radiation
39 # FOAM_FORCE_LINK_COAL_COMBUSTION - FOAM_coalCombustion
40 # FOAM_FORCE_LINK_INTERFACE_PROPERTIES - FOAM_interfaceProperties
42 # As an example, to force linking against FOAM_incompressibleRASModels, one
43 # would use something like this:
45 # foam_add_executable(some_solver
47 # ${FOAM_FORCE_LINK_INCOMPRESSIBLE_RAS_MODELS})
49 # target_link_libraries(some_solver
50 # FOAM_incompressibleRASModels)
52 # BRIEF FUNCTION DESCRIPTIONS
54 # This module defines the following functions to help building and installing
55 # @PROJECT_NAME@ libraries and executables. The Descriptions given are only
56 # very brief, refer to the full documentations below for detailed instructions.
59 # Create a @PROJECT_NAME@ library
60 # - foam_add_executable
61 # Create a @PROJECT_NAME@ executable
62 # - foam_add_target_to_build_tree_export
63 # Add target to the build-tree export-set. This is only used if other
64 # CMake-based projects want to import this target directly from the
66 # - foam_export_to_build_tree
67 # Create the export-set in the build-tree.
68 # - foam_install_targets
69 # Install @PROJECT_NAME@ targets.
70 # - foam_create_include_wrappers
71 # Creates include-wrapper files in ${CMAKE_BINARY_DIR}/include, making
72 # it possible to have include-statements of the form:
73 # #include <libName/fileName.H>
74 # - foam_check_and_compile_flex
75 # Checks a list of source files whether they contain any .L (flex++)
76 # sources. If they are found, it creates targets to compile these
77 # and replaces their occurences in the source file list by the C++
79 # - foam_link_loadable_library
80 # Creates a symbolic link to the (framework) library into the plugins
81 # directory, allowing it to be loaded using dlopen.
82 # - foam_add_executable_to_doc_index
83 # Adds an executable to the Doxygen documentation index. This index
84 # is consulted by @PROJECT_NAME@ executables when they are being called
85 # with the -help option.
86 # - foam_write_doc_index
87 # Writes above described documentation index to a file.
88 # - foam_queue_manpage
89 # Enqueues a manpage for generation either from Doxygen source or from
90 # the header comments in a source file.
91 # - foam_create_manpages
92 # Generates the manpages enqueued with foam_queue_manpage().
93 # - foam_dependent_variables
94 # Makes a list of variables depend on another variable. When the
95 # cache-value of this variable changes, the dependent variables are
96 # removed from the cache and are undefined.
97 # - foam_configure_files
98 # Configure a list of files using transformation rules which can be
99 # different for the build- and install-tree. Also allows renaming of the
101 # - foam_install_configured_files
102 # Install files created using foam_configure_files().
103 # - foam_parse_arguments
104 # Common function useful for argument parsing when writing custom macros
107 # Create images from Asymptote sources.
108 # - foam_fix_apple_gcc_bug
109 # Work around buggy Apple g++-4.2 where -O3 generates bad code. This is
110 # an internal function.
112 # DETAILED FUNCTION DOCUMENTATION
114 # FOAM_ADD_LIBRARY(<target> [STATIC | SHARED | MODULE]
115 # [<src> ...] [PUBLIC_HEADERS <hdr> ...]
116 # [[EXPORT <export_set>] | SKIP_EXPORT])
118 # Adds a @PROJECT_NAME@ library with the target name <target>. Optionally, you
119 # can specify STATIC, SHARED or MODULE to determine the library-type that is
120 # build. Refer to the documenation of add_library() for the details. <src> ...
121 # are all source files. Files following PUBLIC_HEADERS are header files which
122 # are to be installed. If no sources are given, the function requires that the
123 # file ${CMAKE_CURRENT_SOURCE_DIR}/files.cmake exists which defines the list
124 # SRCS, containing the names of the source files, and optionally HDRS, listing
125 # the names of the public headers.
127 # If the variable FOAM_HAS_FLEX_SOURCES evaluates to TRUE and the list of files
128 # contains files having a .L suffix, this macro automatically generates rules to
129 # compile them using flex.
131 # The option EXPORT <export-set> specifies an export-set name which is different
132 # from ${PROJECT_NAME}LibraryDepends. The default can be changed by setting the
133 # variable FOAM_EXPORT_SET_NAME. If SKIP_EXPORT_SET is specified, this library
134 # is not included in any export-set. The default can be changed by setting
135 # FOAM_ENABLE_EXPORT_SET.
137 # If you require include-wrappers, set FOAM_CREATE_INCLUDE_WRAPPERS to TRUE.
138 # To build all libraries as Frameworks on Mac OS X, set FOAM_BUILD_FRAMEWORKS
139 # to TRUE. The Framework version is initialized with FOAM_VERSION_FULL and
140 # the install-name directory with FOAM_FRAMEWORK_INSTALL_NAME_DIR. The first
141 # defaults to FALSE, the others are not set if not defined.
143 # FOAM_ADD_EXECUTABLE(<target> [OUTPUT_NAME <name>] [APP_SECTION <id>]
144 # [DOC_SRC <src>] [SKIP_DOC_INDEX] [SKIP_MANPAGE]
147 # Adds a @PROJECT_NAME@ executable with the target name <target> and the output
148 # name ${FOAM_EXE_PREFIX}<target>, which can be customized using the
149 # OUTPUT_NAME <name> argument. It is important to note that setting the
150 # OUTPUT_NAME target property directly results in a wrong man-page name.
151 # <src> ... are all source files. If none are given, the function requires that
152 # the file ${CMAKE_CURRENT_SOURCE_DIR}/files.cmake exists which defines the
153 # list SRCS, containing the names of the source files.
155 # If the variable FOAM_HAS_FLEX_SOURCES evaluates to TRUE and the list of files
156 # contains files having a .L suffix, this macro automatically generates rules to
157 # compile them using flex.
159 # APP_SECTION <id> specifies the section ID under which the brief description of
160 # the application is to be listed. If not specified, defaults to the setting of
161 # the FOAM_APP_SECTION variable, and if that is not defined, the application is
162 # not registered at all.
164 # DOC_SRC <src> names the file used to auto-generate the manpage. If not
165 # specified, this defaults to the first file in the sources list.
167 # The options SKIP_DOC_INDEX and SKIP_MANPAGE suppress the inclusion in the
168 # Doxygen documentation index and the creation of the manpage, respectively.
169 # The first option can also be set by setting the variable
170 # FOAM_ENABLE_DOC_INDEX to FALSE, the creation of manual pages can be disabled
171 # by setting FOAM_MANPAGE_FORMATS to the empty list of FALSE.
173 # FOAM_ADD_TARGET_TO_BUILD_TREE_EXPORT(<export_set> <target> ...)
175 # Adds <target> to the build-tree export set <export_set>.
177 # FOAM_EXPORT_TO_BUILD_TREE(<export_set> [<namespace>])
179 # Exports all targets in set <export_set> to the build tree. Optionally the a
180 # <namespace> can be specified which is prefixed to the exported library names.
181 # This defaults to _FOAM and can be overriden by FOAM_EXPORT_NAMESPACE.
183 # FOAM_INSTALL_TARGETS(<target> ...
184 # [EXPORT <export_set> | SKIP_EXPORT] [EXPORT_EXECUTABLES]
185 # [[ARCHIVE|LIBRARY|RUNTIME|FRAMEWORK|PRIVATE_HEADER|PUBLIC_HEADER]
186 # [DESTINATION <dir>] [COMPONENT <component>]...])
188 # Installs @PROJECT_NAME@ targets. To override the export-set (default is
189 # ${PROJECT_NAME}LibraryDepends) use EXPORT_SET <export_set> or define the
190 # variable FOAM_EXPORT_SET_NAME. If you do not want to include this target
191 # in the export-set, specify SKIP_EXPORT or define FOAM_ENABLE_EXPORT_SET.
192 # Executables are by default not exported, specify EXPORT_EXECUTABLES or set
193 # FOAM_EXPORT_EXECUTABLES to TRUE to change this.
195 # To override the default installation locations, use XXX DESTINATION <dir>
196 # and for a different install-component, use XXX COMPONENT <component>. If you
197 # specify both, use XXX DESTINATION <dir> COMPONENT <component>. The defaults
200 # TYPE DEFAULT DESTINATION OVERRIDE VARIABLE
201 # ----------------------------------------------------------------------
202 # ARCHIVE lib/${PROJECT_NAME} FOAM_INSTALL_ARCHIVE_PATH
203 # LIBRARY lib/${PROJECT_NAME} FOAM_INSTALL_LIBRARY_PATH
204 # RUNTIME libexec/${PROJECT_NAME} FOAM_INSTALL_RUNTIME_PATH
205 # FRAMEWORK /Library/Frameworks FOAM_INSTALL_FRAMEWORK_PATH
206 # PRIVATE_HEADER include/${PROJECT_NAME} FOAM_INSTALL_HEADER_PATH
207 # PUBLIC_HEADER include/${PROJECT_NAME} FOAM_INSTALL_HEADER_PATH
209 # TYPE DEFAULT COMPONENT OVERRIDE VARIABLE
210 # --------------------------------------------------------------------------
211 # ARCHIVE dev FOAM_INSTALL_ARCHIVE_COMPONENT
212 # LIBRARY shlibs FOAM_INSTALL_LIBRARY_COMPONENT
213 # RUNTIME bin FOAM_INSTALL_RUNTIME_COMPONENT
214 # FRAMEWORK shlibs FOAM_INSTALL_FRAMEWORK_COMPONENT
215 # PRIVATE_HEADER dev FOAM_INSTALL_HEADER_COMPONENT
216 # PUBLIC_HEADER dev FOAM_INSTALL_HEADER_COMPONENT
218 # The default installation destinations for PRIVATE_HEADER and PUBLIC_HEADER are
219 # automatically appended by /<OUTPUT_NAME> (also if the override-variable is
222 # FOAM_CREATE_INCLUDE_WRAPPERS(<libraryName> <header1> ...)
224 # Creates in ${CMAKE_BINARY_DIR}/include an include-tree which contains
225 # "include-wrappers", i.e. files only containing an #include statement
226 # referring to the actual file in the source tree. All header files belonging
227 # to the library ${libraryName} are thus mapped into the include-scheme
228 # ${libraryName}/${headerName}. This structure makes FreeFOAM installable and
229 # is also useful for Mac OS X frameworks which use the same naming scheme.
230 # Further it makes the build much more robust as the strong dependence on the
231 # include-path is removed. User-code should normally not have to call this
234 # FOAM_CHECK_AND_COMPILE_FLEX(<src_list>)
236 # Checks a list of source files for flex++ sources and compiles them. The
237 # function replaces the .L file in the sources list by the generated .C file.
238 # This file gets created in the ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES}
239 # directory. The output name is generated by replacing .L with .C and stripping
240 # all directory components from the .L file. The flex target is named using the
241 # NAME_WE component, suffixed with _Lexer. The function will add FLEX_CXX_FLAGS
242 # to the COMPILE_FLAGS of the FLEX_TARGET call.
244 # It is an error if *.L sources are discovered and FOAM_HAS_FLEX_SOURCES
245 # does not evaluate to TRUE. User-code should not have to call this function
248 # FOAM_LINK_LOADABLE_LIBRARY(<target>)
250 # This function creates a symbolic link to a (framework) library into the
251 # plugins directory such that it can be loaded using dlopen (or similar) for
254 # FOAM_ADD_EXECUTABLE_TO_DOC_INDEX(<target> <doc_file>)
256 # Add an application <target> to the documentation-index file, where the
257 # documentation header comments are in the file <doc_file>.
259 # DO NOT call this function after you called FOAM_WRITE_DOC_INDEX(), it won't
262 # FOAM_WRITE_DOC_INDEX()
264 # Create the documentation index file. Call this function after all calls to
265 # FOAM_ADD_EXECUTABLE_TO_DOC_INDEX(). This will create:
267 # ${CMAKE_BINARY_DIR}/data/DoxyDocIndex.in
268 # ${CMAKE_BINARY_DIR}/data/DoxyDocIndex
269 # ${CMAKE_BINARY_DIR}/InstallFiles/data/DoxyDocIndex
271 # FOAM_QUEUE_MANPAGE(<name> <src> [<dep> ...])
273 # Enqueue a manpage <name> for creation, either from AsciiDoc source or from
274 # the documentation comments. This function checks whether the list
275 # FOAM_MANPAGE_FORMATS evaluates to TRUE, otherwise it is a no-op. If the file
276 # <src> is an AsciiDoc source, it's name must be of the format
277 # <base_name>.<sect>.in.txt, where <base_name> is an arbitrary string that must
278 # not match <name> and <sect> is the man-section number. If the file is not an
279 # AsciiDoc source file, the manual page number is always 1. The files listed in
280 # <dep> are additional dependencies on which <src> depends (e.g. through
283 # It is an error to call this function after foam_create_manpages().
285 # FOAM_CREATE_MANPAGES()
287 # The macro will for each of the formats listed in FOAM_MANPAGE_FORMATS create
288 # a manual page that has been enqueued with foam_queue_manpage(). Currently
289 # only "manpage" and "xhtml" are supported, where the former is generated in
290 # ${CMAKE_BINARY_DIR}/doc/man/man<sect> and installed in
291 # ${FOAM_INSTALL_MAN_PATH}/man<sect>, the latter is generated in
292 # ${CMAKE_BINARY_DIR}/doc/html/man/man<sect> and installed to
293 # ${FOAM_INSTALL_DOC_PATH}/doc/html/man/man<sect>.
295 # This function must be called after all calls to foam_queue_manpage(). It is
296 # an error to call this function more than once.
298 # FOAM_DEPENDENT_VARIABLES(<var> [<depvar> ...])
300 # Purge dependend cache-variables <depvar> when the independent variable <var>
301 # changes. This macro caches the value of a variable and detects changes upon
302 # the next run (e.g. when the user changed an option). If the value changed, the
303 # dependent variables are unset and removed from the cache.
305 # FOAM_CONFIGURE_FILES(<installFilesVar>
307 # [DESTDIR <dir>] [BASENAME] <file> ...] ...)
309 # Configure utility files for build and install tree. Configures all files into
311 # ${CMAKE_BINARY_DIR}/<file> with build tree settings
312 # ${CMAKE_BINARY_DIR}/InstallFiles/<file> with install tree settings
314 # using CONFIGURE_FILE() with @ONLY. If a .in suffix is present, it will be
315 # removed. The variable FOAM_STRIP_SUFFIXES may be set to a list of regular
316 # expresions matching suffixes (e.g. "\\.in$") to override this choice. Only
317 # the first suffix that is found to be present will be removed, so if you want
318 # to remove e.g. ".py.in" it is not enough to have "\\.in$;\\.py$", you need
319 # "\\.py\\.in$" BEFORE the "\\.in$" element (if you have any).
321 # The DESTDIR option can be used to define a sub-directory, such that the
322 # configured paths become
324 # ${CMAKE_BINARY_DIR}/<dir>/<file>
325 # ${CMAKE_BINARY_DIR}/InstallFiles/<dir>/<file>
327 # If after a DESTDIR <dir> option the BASENAME option is used, all directory
328 # components will be stripped from the following files (up to the next DESTDIR
329 # or COPYONLY) before constructing the path. Files after the COPYONLY are not
330 # configured and will only be copied into ${CMAKE_BINARY_DIR}/${destDir}/ (to
331 # save space and speed things up).
333 # The variable <installFilesVar> will contain the names of the files for the
334 # install-tree. This variable can be used for the INSTALL(FILES ...) command or,
335 # perhaps better suited, FOAM_INSTALL_CONFIGURED_FILES().
337 # In order to determine which variables to define for the configure-step, this
338 # function uses the variable FOAM_CONFIGURE_FILES_VARIABLES which is a list
339 # containing 3-tuples. The first element is the variable name, followed by the
340 # value for the build-tree and the last element is the value for the install-tree.
341 # The next element in the list starts a new triplet. The character ; must be
342 # escaped as \; in order to not be treated as a list-element separator. The name
343 # of the variable must be a valid idenitifier will be substituted in the files
344 # if it references as @VAR_NAME@ (@ONLY option of CONFIGURE_FILE).
346 # If you need a file to have a different output name than the source file has
347 # (i.e. the part of the name before the suffix), you can do so by providing a
348 # string of the format "<sourceName>==<destinationName>" instead of just the
349 # source-name. This can also be used to modify the sub-directory part. Beware,
350 # that suffix-stripping is still performed on the output name.
352 # FOAM_INSTALL_CONFIGURED_FILES([FILES|PROGRAMS]
354 # DESTINATION <dir> [COMPONENT <component>])
356 # Install files configured with FOAM_CONFIGURE_FILES(). This is similar to
357 # INSTALL(FILES ...) and INSTALL(PROGRAMS ...), except for the handling
358 # of the installation directory. For each file its relative path to
359 # ${CMAKE_BINARY_DIR}/InstallFiles or ${CMAKE_BINARY_DIR} is computed (it MUST
360 # be a child of one of these directories) and this name is then appended to the
361 # destination <dir>. This simplifies installing files that should end up in
362 # different sub-directories of the destination directory <dir>.
364 # FOAM_PARSE_ARGUMENTS(<prefix> <arg_names> <option_names> [<arg1> ...])
366 # This is a helper function to parse optional arguments in macros/functions It
367 # has been adapted from the public CMake wiki
368 # (http://www.cmake.org/Wiki/CMakeMacroParseArguments). For each argument
369 # <opt_name> in <arg1> ... the function checks whether an entry with the same
370 # name in <option_names> exists. If so, it sets the variable
371 # <prefix>_<opt_name> to TRUE, otherwise to FALSE. For all items <arg_name> in
372 # the argument list that corresponds to a <arg_spec> entry in <arg_specs>, the
373 # variable <prefix>_<arg_name> will be filled by the list of all following
374 # arguments up to the next <arg_name> or the end of all arguments. All options
375 # will be removed from these lists. The special variable <prefix>_DEFAULT_ARGS
376 # will contain all arguments occuring before the first argument in <arg_names>.
377 # <arg_spec> takes to form <arg_name>[:<n_args>], where <n_args> specifies the
378 # exact number of arguments that must follow <arg_name> in the argument list.
379 # If :<n_args> is left ommited, an arbitrary number of arguments are accepted
380 # (i.e. greedy mode). Arguments not consumed (i.e. after the last accepted
381 # argument and before the next <arg_name> or the end of the argument list) are
382 # added to <prefix>_DEFAULT_ARGS.
384 # FOAM_COMPILE_ASY(<outvar> <formats> <file> ...)
386 # Compiles the Aymptote sources into images. <outvar> will hold the names of
387 # the produced files. <formats> is a list of graphics formats supported by asy
388 # (such as pdf, eps, png, etc.). <file> is one or more Asymptote source files.
389 # Files listed in the OBJECT_DEPENDS source file property are copied to the
390 # temporary work directory and added as a dependeny of the command.
392 # FOAM_FIX_APPLE_GCC_BUG()
394 # This is an internal function used to work around in the g++-4.2 compiler that
395 # comes with Xcode. Do not call it directly.
398 #-------------------------------------------------------------------------------
399 # ______ _ ____ __ __
400 # | ____| _| |_ / __ \ /\ | \/ |
401 # | |__ _ __ ___ ___ / \| | | | / \ | \ / |
402 # | __| '__/ _ \/ _ ( (| |) ) | | |/ /\ \ | |\/| |
403 # | | | | | __/ __/\_ _/| |__| / ____ \| | | |
404 # |_| |_| \___|\___| |_| \____/_/ \_\_| |_|
406 # FreeFOAM: The Cross-Platform CFD Toolkit
408 # Copyright (C) 2008-2012 Michael Wild <themiwi@users.sf.net>
409 # Gerber van der Graaf <gerber_graaf@users.sf.net>
410 #-------------------------------------------------------------------------------
412 # This file is part of FreeFOAM.
414 # FreeFOAM is free software: you can redistribute it and/or modify it
415 # under the terms of the GNU General Public License as published by the
416 # Free Software Foundation, either version 3 of the License, or (at your
417 # option) any later version.
419 # FreeFOAM is distributed in the hope that it will be useful, but WITHOUT
420 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
421 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
424 # You should have received a copy of the GNU General Public License
425 # along with FreeFOAM. If not, see <http://www.gnu.org/licenses/>.
426 #-------------------------------------------------------------------------------
428 # helper function to set a variable to a default value if it is not defined
429 function(_use_foam_set_default var defval)
430 if(NOT DEFINED ${var})
431 set(${var} "${defval}" PARENT_SCOPE)
436 _use_foam_set_default(FOAM_ENABLE_EXPORT FALSE)
437 _use_foam_set_default(FOAM_EXPORT_EXECUTABLES FALSE)
438 _use_foam_set_default(FOAM_BUILD_FRAMEWORKS FALSE)
439 _use_foam_set_default(FOAM_ENABLE_DOC_INDEX FALSE)
440 _use_foam_set_default(FOAM_ENABLE_MANPAGES FALSE)
441 _use_foam_set_default(FOAM_EXE_PREFIX "@FOAM_EXE_PREFIX@")
442 include(${FOAM_UTILITIES_FILE})
444 foam_fix_apple_gcc_bug()
446 # set up header search path
447 if(APPLE AND FOAM_WITH_FRAMEWORKS)
448 add_definitions("-F${FOAM_FRAMEWORK_DIR}")
450 include_directories(${FOAM_INCLUDE_DIRS})
453 # set up library search path
454 link_directories(${FOAM_LIBRARY_DIRS})
457 add_definitions(${FOAM_DEFINITIONS})
459 # build shared libraries
460 set(BUILD_SHARED_LIBS SHARED)
462 # ------------------------- vim: set sw=2 sts=2 et: --------------- end-of-file