ENH: Reworked the symlink handling of loadable libraries
[freefoam.git] / CMake / FOAMUse.cmake.in
blobc08fcf0dc57dd3eec32355678adfbac6a5c3b574
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
17 # avoid name-clashes.
19 # BRIEF FUNCTION DESCRIPTIONS
21 # This module defines the following functions to help building and installing
22 # @PROJECT_NAME@ libraries and executables. The Descriptions given are only
23 # very brief, refer to the full documentations below for detailed instructions.
25 #  - foam_add_library:
26 #        Create a @PROJECT_NAME@ library
27 #  - foam_add_executable
28 #        Create a @PROJECT_NAME@ executable
29 #  - foam_add_target_to_build_tree_export
30 #        Add target to the build-tree export-set. This is only used if other
31 #        CMake-based projects want to import this target directly from the
32 #        build-tree.
33 #  - foam_export_to_build_tree
34 #        Create the export-set in the build-tree.
35 #  - foam_install_targets
36 #        Install @PROJECT_NAME@ targets.
37 #  - foam_create_include_wrappers
38 #        Creates include-wrapper files in ${CMAKE_BINARY_DIR}/include, making
39 #        it possible to have include-statements of the form:
40 #          #include <libName/fileName.H>
41 #  - foam_check_and_compile_flex
42 #        Checks a list of source files whether they contain any .L (flex++)
43 #        sources. If they are found, it creates targets to compile these
44 #        and replaces their occurences in the source file list by the C++
45 #        output file.
46 #  - foam_link_loadable_library
47 #        Creates a symbolic link to the (framework) library into the plugins
48 #        directory, allowing it to be loaded using dlopen.
49 #  - foam_add_executable_to_doc_index
50 #        Adds an executable to the Doxygen documentation index. This index
51 #        is consulted by @PROJECT_NAME@ executables when they are being called
52 #        with the -help option.
53 #  - foam_write_doc_index
54 #        Writes above described documentation index to a file.
55 #  - foam_create_manpage
56 #        Creates a manpage either from Doxygen source or from the header
57 #        comments in a source file.
58 #  - foam_dependent_variables
59 #        Makes a list of variables depend on another variable. When the
60 #        cache-value of this variable changes, the dependent variables are
61 #        removed from the cache and are undefined.
62 #  - foam_configure_files
63 #        Configure a list of files using transformation rules which can be
64 #        different for the build- and install-tree. Also allows renaming of the
65 #        file.
66 #  - foam_install_configured_files
67 #        Install files created using foam_configure_files().
68 #  - foam_parse_arguments
69 #        Common function useful for argument parsing when writing custom macros
70 #        and functions.
71 #  - foam_compile_asy
72 #        Create images from Asymptote sources.
73 #  - foam_fix_apple_gcc_bug
74 #        Work around buggy Apple g++-4.2 where -O3 generates bad code. This is
75 #        an internal function.
77 # DETAILED FUNCTION DOCUMENTATION
79 #  FOAM_ADD_LIBRARY(<target> [STATIC | SHARED | MODULE]
80 #                   [<src> ...] [PUBLIC_HEADERS <hdr> ...]
81 #                   [[EXPORT <export_set>] | SKIP_EXPORT])
83 # Adds a @PROJECT_NAME@ library with the target name <target>. Optionally, you
84 # can specify STATIC, SHARED or MODULE to determine the library-type that is
85 # build. Refer to the documenation of add_library() for the details. <src> ...
86 # are all source files. Files following PUBLIC_HEADERS are header files which
87 # are to be installed. If no sources are given, the function requires that the
88 # file ${CMAKE_CURRENT_SOURCE_DIR}/files.cmake exists which defines the list
89 # SRCS, containing the names of the source files, and optionally HDRS, listing
90 # the names of the public headers.
92 # If the variable FOAM_HAS_FLEX_SOURCES evaluates to TRUE and the list of files
93 # contains files having a .L suffix, this macro automatically generates rules to
94 # compile them using flex.
96 # The option EXPORT <export-set> specifies an export-set name which is different
97 # from ${PROJECT_NAME}LibraryDepends. The default can be changed by setting the
98 # variable FOAM_EXPORT_SET_NAME. If SKIP_EXPORT_SET is specified, this library
99 # is not included in any export-set. The default can be changed by setting
100 # FOAM_ENABLE_EXPORT_SET.
102 # If you require include-wrappers, set FOAM_CREATE_INCLUDE_WRAPPERS to TRUE.
103 # To build all libraries as Frameworks on Mac OS X, set FOAM_BUILD_FRAMEWORKS
104 # to TRUE. The Framework version is initialized with FOAM_VERSION_FULL and
105 # the install-name directory with FOAM_FRAMEWORK_INSTALL_NAME_DIR. The first
106 # defaults to FALSE, the others are not set if not defined.
108 #  FOAM_ADD_EXECUTABLE(<target> [OUTPUT_NAME <name>] [APP_SECTION <id>]
109 #                      [DOC_SRC <src>] [SKIP_DOC_INDEX] [SKIP_MANPAGE]
110 #                      [<src> ...])
112 # Adds a @PROJECT_NAME@ executable with the target name <target> and the output
113 # name ${FOAM_EXE_PREFIX}<target>, which can be customized using the
114 # OUTPUT_NAME <name> argument. It is important to note that setting the
115 # OUTPUT_NAME target property directly results in a wrong man-page name.
116 # <src> ... are all source files. If none are given, the function requires that
117 # the file ${CMAKE_CURRENT_SOURCE_DIR}/files.cmake exists which defines the
118 # list SRCS, containing the names of the source files.
120 # If the variable FOAM_HAS_FLEX_SOURCES evaluates to TRUE and the list of files
121 # contains files having a .L suffix, this macro automatically generates rules to
122 # compile them using flex.
124 # APP_SECTION <id> specifies the section ID under which the brief description of
125 # the application is to be listed. If not specified, defaults to the setting of
126 # the FOAM_APP_SECTION variable, and if that is not defined, the application is
127 # not registered at all.
129 # DOC_SRC <src> names the file used to auto-generate the manpage. If not
130 # specified, this defaults to the first file in the sources list.
132 # The options SKIP_DOC_INDEX and SKIP_MANPAGE suppress the inclusion in the
133 # Doxygen documentation index and the creation of the manpage, respectively.
134 # The first option can also be set by setting the variable
135 # FOAM_ENABLE_DOC_INDEX to FALSE, the creation of manual pages can be disabled
136 # by setting FOAM_MANPAGE_FORMATS to the empty list of FALSE.
138 #  FOAM_ADD_TARGET_TO_BUILD_TREE_EXPORT(<export_set> <target> ...)
140 # Adds <target> to the build-tree export set <export_set>.
142 #  FOAM_EXPORT_TO_BUILD_TREE(<export_set> [<namespace>])
144 # Exports all targets in set <export_set> to the build tree. Optionally the a
145 # <namespace> can be specified which is prefixed to the exported library names.
146 # This defaults to _FOAM and can be overriden by FOAM_EXPORT_NAMESPACE.
148 #  FOAM_INSTALL_TARGETS(<target> ...
149 #    [EXPORT <export_set> | SKIP_EXPORT] [EXPORT_EXECUTABLES]
150 #    [[ARCHIVE|LIBRARY|RUNTIME|FRAMEWORK|PRIVATE_HEADER|PUBLIC_HEADER]
151 #    [DESTINATION <dir>] [COMPONENT <component>]...])
153 # Installs @PROJECT_NAME@ targets. To override the export-set (default is
154 # ${PROJECT_NAME}LibraryDepends) use EXPORT_SET <export_set> or define the
155 # variable FOAM_EXPORT_SET_NAME. If you do not want to include this target
156 # in the export-set, specify SKIP_EXPORT or define FOAM_ENABLE_EXPORT_SET.
157 # Executables are by default not exported, specify EXPORT_EXECUTABLES or set
158 # FOAM_EXPORT_EXECUTABLES to TRUE to change this.
160 # To override the default installation locations, use XXX DESTINATION <dir>
161 # and for a different install-component, use XXX COMPONENT <component>. If you
162 # specify both, use XXX DESTINATION <dir> COMPONENT <component>. The defaults
163 # are as follows:
165 #  TYPE             DEFAULT DESTINATION       OVERRIDE VARIABLE
166 #  ----------------------------------------------------------------------
167 #  ARCHIVE          lib/${PROJECT_NAME}       FOAM_INSTALL_ARCHIVE_PATH
168 #  LIBRARY          lib/${PROJECT_NAME}       FOAM_INSTALL_LIBRARY_PATH
169 #  RUNTIME          libexec/${PROJECT_NAME}   FOAM_INSTALL_RUNTIME_PATH
170 #  FRAMEWORK        /Library/Frameworks       FOAM_INSTALL_FRAMEWORK_PATH
171 #  PRIVATE_HEADER   include/${PROJECT_NAME}   FOAM_INSTALL_HEADER_PATH
172 #  PUBLIC_HEADER    include/${PROJECT_NAME}   FOAM_INSTALL_HEADER_PATH
174 #  TYPE             DEFAULT COMPONENT         OVERRIDE VARIABLE
175 #  --------------------------------------------------------------------------
176 #  ARCHIVE          dev                       FOAM_INSTALL_ARCHIVE_COMPONENT
177 #  LIBRARY          shlibs                    FOAM_INSTALL_LIBRARY_COMPONENT
178 #  RUNTIME          bin                       FOAM_INSTALL_RUNTIME_COMPONENT
179 #  FRAMEWORK        shlibs                    FOAM_INSTALL_FRAMEWORK_COMPONENT
180 #  PRIVATE_HEADER   dev                       FOAM_INSTALL_HEADER_COMPONENT
181 #  PUBLIC_HEADER    dev                       FOAM_INSTALL_HEADER_COMPONENT
183 # The default installation destinations for PRIVATE_HEADER and PUBLIC_HEADER are
184 # automatically appended by /<OUTPUT_NAME> (also if the override-variable is
185 # defined).
187 #  FOAM_CREATE_INCLUDE_WRAPPERS(<libraryName> <header1> ...)
189 # Creates in ${CMAKE_BINARY_DIR}/include an include-tree which contains
190 # "include-wrappers", i.e. files only containing an #include statement
191 # referring to the actual file in the source tree. All header files belonging
192 # to the library ${libraryName} are thus mapped into the include-scheme
193 # ${libraryName}/${headerName}. This structure makes FreeFOAM installable and
194 # is also useful for Mac OS X frameworks which use the same naming scheme.
195 # Further it makes the build much more robust as the strong dependence on the
196 # include-path is removed. User-code should normally not have to call this
197 # function.
199 #  FOAM_CHECK_AND_COMPILE_FLEX(<src_list>)
201 # Checks a list of source files for flex++ sources and compiles them. The
202 # function replaces the .L file in the sources list by the generated .C file.
203 # This file gets created in the ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES}
204 # directory. The output name is generated by replacing .L with .C and stripping
205 # all directory components from the .L file. The flex target is named using the
206 # NAME_WE component, suffixed with _Lexer. The function will add FLEX_CXX_FLAGS
207 # to the COMPILE_FLAGS of the FLEX_TARGET call.
209 # It is an error if *.L sources are discovered and FOAM_HAS_FLEX_SOURCES
210 # does not evaluate to TRUE. User-code should not have to call this function
211 # explicitly.
213 #  FOAM_LINK_LOADABLE_LIBRARY(<target>)
215 # This function creates a symbolic link to a (framework) library into the
216 # plugins directory such that it can be loaded using dlopen (or similar) for
217 # <target>.
219 #  FOAM_ADD_EXECUTABLE_TO_DOC_INDEX(<target> <doc_file>)
221 # Add an application <target> to the documentation-index file, where the
222 # documentation header comments are in the file <doc_file>.
224 # DO NOT call this function after you called FOAM_WRITE_DOC_INDEX(), it won't
225 # have any effect!
227 #  FOAM_WRITE_DOC_INDEX()
229 # Create the documentation index file. Call this function after all calls to
230 # FOAM_ADD_EXECUTABLE_TO_DOC_INDEX(). This will create:
232 #  ${CMAKE_BINARY_DIR}/data/DoxyDocIndex.in
233 #  ${CMAKE_BINARY_DIR}/data/DoxyDocIndex
234 #  ${CMAKE_BINARY_DIR}/InstallFiles/data/DoxyDocIndex
236 #  FOAM_CREATE_MANPAGE(<name> <src> [<dep> ...])
238 # Create a manpage <name> either from AsciiDoc source or from the documentation
239 # comments. This function checks whether the list FOAM_MANPAGE_FORMATS
240 # evaluates to TRUE, otherwise it is a no-op. If the file <src> is an AsciiDoc
241 # source, it's name must be of the format <base_name>.<sect>.in.txt, where
242 # <base_name> is an arbitrary string that must not match <name> and <sect> is
243 # the man-section number. If the file is not an AsciiDoc source file, the
244 # manual page number is always 1. The macro will then for each of the formats
245 # listed in FOAM_MANPAGE_FORMATS create a manual page. Currently only "manpage"
246 # and "xhtml" are supported, where the former is generated in
247 # ${CMAKE_BINARY_DIR}/doc/man/man<sect> and installed in
248 # ${FOAM_INSTALL_MAN_PATH}/man<sect>, the latter is generated in
249 # ${CMAKE_BINARY_DIR}/doc/html/man<sect> and installed to
250 # ${FOAM_INSTALL_DOC_PATH}/doc/html/man<sect>. The files listed in <dep> are
251 # additional dependencies on which <src> depends (e.g. through include macros).
253 #  FOAM_DEPENDENT_VARIABLES(<var> [<depvar> ...])
255 # Purge dependend cache-variables <depvar> when the independent variable <var>
256 # changes. This macro caches the value of a variable and detects changes upon
257 # the next run (e.g. when the user changed an option). If the value changed, the
258 # dependent variables are unset and removed from the cache.
260 #  FOAM_CONFIGURE_FILES(<installFilesVar>
261 #                       [[COPYONLY]
262 #                         [DESTDIR <dir>] [BASENAME] <file> ...] ...)
264 # Configure utility files for build and install tree. Configures all files into
266 #   ${CMAKE_BINARY_DIR}/<file> with build tree settings
267 #   ${CMAKE_BINARY_DIR}/InstallFiles/<file> with install tree settings
269 # using CONFIGURE_FILE() with @ONLY. If a .in suffix is present, it will be
270 # removed. The variable FOAM_STRIP_SUFFIXES may be set to a list of regular
271 # expresions matching suffixes (e.g. "\\.in$") to override this choice. Only
272 # the first suffix that is found to be present will be removed, so if you want
273 # to remove e.g. ".py.in" it is not enough to have "\\.in$;\\.py$", you need
274 # "\\.py\\.in$" BEFORE the "\\.in$" element (if you have any).
276 # The DESTDIR option can be used to define a sub-directory, such that the
277 # configured paths become
279 #   ${CMAKE_BINARY_DIR}/<dir>/<file>
280 #   ${CMAKE_BINARY_DIR}/InstallFiles/<dir>/<file>
282 # If after a DESTDIR <dir> option the BASENAME option is used, all directory
283 # components will be stripped from the following files (up to the next DESTDIR
284 # or COPYONLY) before constructing the path. Files after the COPYONLY are not
285 # configured and will only be copied into ${CMAKE_BINARY_DIR}/${destDir}/ (to
286 # save space and speed things up).
288 # The variable <installFilesVar> will contain the names of the files for the
289 # install-tree. This variable can be used for the INSTALL(FILES ...) command or,
290 # perhaps better suited, FOAM_INSTALL_CONFIGURED_FILES().
292 # In order to determine which variables to define for the configure-step, this
293 # function uses the variable FOAM_CONFIGURE_FILES_VARIABLES which is a list
294 # containing 3-tuples. The first element is the variable name, followed by the
295 # value for the build-tree and the last element is the value for the build-tree.
296 # The next element in the list starts a new triplet. The character ; must be
297 # escaped as \; in order to not be treated as a list-element separator. The name
298 # of the variable must be a valid idenitifier will be substituted in the files
299 # if it references as @VAR_NAME@ (@ONLY option of CONFIGURE_FILE).
301 # If you need a file to have a different output name than the source file has
302 # (i.e. the part of the name before the suffix), you can do so by providing a
303 # string of the format "<sourceName>==<destinationName>" instead of just the
304 # source-name. This can also be used to modify the sub-directory part. Beware,
305 # that suffix-stripping is still performed on the output name.
307 #  FOAM_INSTALL_CONFIGURED_FILES([FILES|PROGRAMS]
308 #                                <file> ...
309 #                                DESTINATION <dir> [COMPONENT <component>])
311 # Install files configured with FOAM_CONFIGURE_FILES(). This is similar to
312 # INSTALL(FILES ...) and INSTALL(PROGRAMS ...), except for the handling
313 # of the installation directory. For each file its relative path to
314 # ${CMAKE_BINARY_DIR}/InstallFiles or ${CMAKE_BINARY_DIR} is computed (it MUST
315 # be a child of one of these directories) and this name is then appended to the
316 # destination <dir>. This simplifies installing files that should end up in
317 # different sub-directories of the destination directory <dir>.
319 #  FOAM_PARSE_ARGUMENTS(<prefix> <arg_names> <option_names> [<arg1> ...])
321 # This is a helper function to parse optional arguments in macros/functions It
322 # has been adapted from the public CMake wiki
323 # (http://www.cmake.org/Wiki/CMakeMacroParseArguments). For each argument
324 # <opt_name> in <arg1> ... the function checks whether an entry with the same
325 # name in <option_names> exists. If so, it sets the variable
326 # <prefix>_<opt_name> to TRUE, otherwise to FALSE. For all items <arg_name> in
327 # the argument list that corresponds to a <arg_spec> entry in <arg_specs>, the
328 # variable <prefix>_<arg_name> will be filled by the list of all following
329 # arguments up to the next <arg_name> or the end of all arguments. All options
330 # will be removed from these lists. The special variable <prefix>_DEFAULT_ARGS
331 # will contain all arguments occuring before the first argument in <arg_names>.
332 # <arg_spec> takes to form <arg_name>[:<n_args>], where <n_args> specifies the
333 # exact number of arguments that must follow <arg_name> in the argument list.
334 # If :<n_args> is left ommited, an arbitrary number of arguments are accepted
335 # (i.e. greedy mode). Arguments not consumed (i.e. after the last accepted
336 # argument and before the next <arg_name> or the end of the argument list) are
337 # added to <prefix>_DEFAULT_ARGS.
339 #  FOAM_COMPILE_ASY(<outvar> <formats> <file> ...)
341 # Compiles the Aymptote sources into images. <outvar> will hold the names of
342 # the produced files. <formats> is a list of graphics formats supported by asy
343 # (such as pdf, eps, png, etc.). <file> is one or more Asymptote source files.
345 #  FOAM_FIX_APPLE_GCC_BUG()
347 # This is an internal function used to work around in the g++-4.2 compiler that
348 # comes with Xcode. Do not call it directly.
351 #-------------------------------------------------------------------------------
352 #               ______                _     ____          __  __
353 #              |  ____|             _| |_  / __ \   /\   |  \/  |
354 #              | |__ _ __ ___  ___ /     \| |  | | /  \  | \  / |
355 #              |  __| '__/ _ \/ _ ( (| |) ) |  | |/ /\ \ | |\/| |
356 #              | |  | | |  __/  __/\_   _/| |__| / ____ \| |  | |
357 #              |_|  |_|  \___|\___|  |_|   \____/_/    \_\_|  |_|
359 #                   FreeFOAM: The Cross-Platform CFD Toolkit
361 # Copyright (C) 2008-2010 Michael Wild <themiwi@users.sf.net>
362 #                         Gerber van der Graaf <gerber_graaf@users.sf.net>
363 #-------------------------------------------------------------------------------
364 # License
365 #   This file is part of FreeFOAM.
367 #   FreeFOAM is free software; you can redistribute it and/or modify it
368 #   under the terms of the GNU General Public License as published by the
369 #   Free Software Foundation; either version 2 of the License, or (at your
370 #   option) any later version.
372 #   FreeFOAM is distributed in the hope that it will be useful, but WITHOUT
373 #   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
374 #   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
375 #   for more details.
377 #   You should have received a copy of the GNU General Public License
378 #   along with FreeFOAM; if not, write to the Free Software Foundation,
379 #   Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
380 #-------------------------------------------------------------------------------
382 # helper function to set a variable to a default value if it is not defined
383 function(_use_foam_set_default var defval)
384   if(NOT DEFINED ${var})
385     set(${var} "${defval}" PARENT_SCOPE)
386   endif()
387 endfunction()
389 # include macros
390 _use_foam_set_default(FOAM_ENABLE_EXPORT FALSE)
391 _use_foam_set_default(FOAM_EXPORT_EXECUTABLES FALSE)
392 _use_foam_set_default(FOAM_BUILD_FRAMEWORKS FALSE)
393 _use_foam_set_default(FOAM_ENABLE_DOC_INDEX FALSE)
394 _use_foam_set_default(FOAM_ENABLE_MANPAGES FALSE)
395 _use_foam_set_default(FOAM_EXE_PREFIX "@FOAM_EXE_PREFIX@")
396 include(${FOAM_UTILITIES_FILE})
398 foam_fix_apple_gcc_bug()
400 # set up header search path
401 if(APPLE AND FOAM_WITH_FRAMEWORKS)
402   add_definitions("-F${FOAM_FRAMEWORK_DIR}")
403 else()
404   include_directories(${FOAM_INCLUDE_DIRS})
405 endif()
407 # set up library search path
408 link_directories(${FOAM_LIBRARY_DIRS})
410 # defines
411 add_definitions(${FOAM_DEFINITIONS})
413 # build shared libraries
414 set(BUILD_SHARED_LIBS SHARED)
416 # ------------------------- vim: set sw=2 sts=2 et: --------------- end-of-file