ENH: No verbose a2x output when building UserGuide
[freefoam.git] / CMake / FOAMInternal.cmake
blob46a1133a86a02f893f85a7101a3aba46fee95175
1 # - Internal function for FreeFOAM
3 #  FOAM_OPTION(<var> <short> <description> <value>)
5 # Like OPTION(<var> <description> <value>), but also adds the variable <var>
6 # with the short description <short> to the feature-summary table.
8 #  FOAM_INSTALLATION_PATH(<var> <path> <short> <description>)
10 # Like SET(<var> <path> CACHE PATH <description>), but also adds the variable
11 # <var> with the short description <short> to the feature-summary table.
12 # Further if the value of <var> is not an absolute path, it computes the
13 # absolute path and assigns it to the <var> in the parent scope.
15 #  FOAM_CONDITIONAL_COMPONENT(<name> <enabled> <subdir> <reason>)
17 # Like ADD_SUBDIRECTORY(<subdir>) but if <enabled> evaulates to FALSE, <name>
18 # is entered as being disabled because of <reason> into the feature-summary
19 # table.
21 #  FOAM_PRINT_FEATURE_SUMMARY()
23 # Prints summaries of enabled/disabled features, installation paths and
24 # disabled components.
26 #  FOAM_TARGET_LINK_LIBRARIES(<target> item1 [item2 [...]]
27 #                             [[debug|optimized|general] <item>] ...)
29 # Like target_link_libraries() but explicitly sets the LINK_INTERFACE_LIBRARIES
30 # property to exclude the third-party libraries.
32 #  FOAM_ADD_TUTORIAL_TESTS()
34 # Adds the individual cases of the tutorial in the current source directory as
35 # tests. It runs the configured Allrun script in the directory with the --cases
36 # option to obtain a list of cases, and adds each of them as a test. Each case
37 # depends on its predecessor.
40 #-------------------------------------------------------------------------------
41 #               ______                _     ____          __  __
42 #              |  ____|             _| |_  / __ \   /\   |  \/  |
43 #              | |__ _ __ ___  ___ /     \| |  | | /  \  | \  / |
44 #              |  __| '__/ _ \/ _ ( (| |) ) |  | |/ /\ \ | |\/| |
45 #              | |  | | |  __/  __/\_   _/| |__| / ____ \| |  | |
46 #              |_|  |_|  \___|\___|  |_|   \____/_/    \_\_|  |_|
48 #                   FreeFOAM: The Cross-Platform CFD Toolkit
50 # Copyright (C) 2008-2010 Michael Wild <themiwi@users.sf.net>
51 #                         Gerber van der Graaf <gerber_graaf@users.sf.net>
52 #-------------------------------------------------------------------------------
53 # License
54 #   This file is part of FreeFOAM.
56 #   FreeFOAM is free software; you can redistribute it and/or modify it
57 #   under the terms of the GNU General Public License as published by the
58 #   Free Software Foundation; either version 2 of the License, or (at your
59 #   option) any later version.
61 #   FreeFOAM is distributed in the hope that it will be useful, but WITHOUT
62 #   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
63 #   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
64 #   for more details.
66 #   You should have received a copy of the GNU General Public License
67 #   along with FreeFOAM; if not, write to the Free Software Foundation,
68 #   Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
70 # Description
71 #   Internal CMake functions for FreeFOAM
73 #-------------------------------------------------------------------------------
75 function(foam_option var short description value)
76   _foam_set_feature_property("OPTION" ${var} "${short}")
77   option(${var} "${description}" ${value})
78   mark_as_advanced(${var})
79 endfunction()
81 function(foam_installation_path var value short description)
82   _foam_set_feature_property("PATH" ${var} "${short}")
83   set(${var} ${value} CACHE PATH "${description}")
84   mark_as_advanced(${var})
85   set(${var}_ORIG ${${var}} PARENT_SCOPE)
86   # make absolute path
87   if(NOT IS_ABSOLUTE "${${var}}")
88     set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}" PARENT_SCOPE)
89   endif()
90 endfunction()
92 macro(foam_conditional_component name enabled subdir description)
93   if(${enabled})
94     add_subdirectory(${subdir})
95   else()
96     _foam_set_feature_property("COMPONENT" ${name} "${description}")
97   endif()
98 endmacro()
100 function(_foam_set_feature_property type var short)
101   set_property(GLOBAL APPEND PROPERTY FOAM_FEATURES ${var})
102   set_property(GLOBAL PROPERTY FOAM_FEATURES_${var}_COMMENT "${short}")
103   set_property(GLOBAL PROPERTY FOAM_FEATURES_${var}_TYPE "${type}")
104 endfunction()
106 function(foam_print_feature_summary)
107   set(OPTION_msg "Feature Summary:")
108   set(PATH_msg "Installation Directories:")
109   set(COMPONENT_msg "Disabled Components:")
110   get_property(features GLOBAL PROPERTY FOAM_FEATURES)
111   set(OPTION_len 0)
112   set(OPTION_space)
113   set(PATH_len 0)
114   set(PATH_space)
115   set(COMPONENT_len 0)
116   set(COMPONENT_space)
117   foreach(f ${features})
118     get_property(desc GLOBAL PROPERTY FOAM_FEATURES_${f}_COMMENT)
119     get_property(type GLOBAL PROPERTY FOAM_FEATURES_${f}_TYPE)
120     if(NOT type STREQUAL "COMPONENT")
121       string(LENGTH "${desc}" l)
122     else()
123       string(LENGTH "${f}" l)
124     endif()
125     if(l GREATER ${${type}_len})
126       set(${type}_len ${l})
127       set(${type}_space "${desc}")
128     endif()
129   endforeach()
130   string(REGEX REPLACE "." " " OPTION_space "${OPTION_space}")
131   string(REGEX REPLACE "." " " PATH_space "${PATH_space}")
132   string(REGEX REPLACE "." " " COMPONENT_space "${COMPONENT_space}")
133   foreach(f ${features})
134     get_property(desc GLOBAL PROPERTY FOAM_FEATURES_${f}_COMMENT)
135     get_property(type GLOBAL PROPERTY FOAM_FEATURES_${f}_TYPE)
136     if(NOT type STREQUAL "COMPONENT")
137       string(LENGTH "${desc}" l)
138     else()
139       string(LENGTH "${f}" l)
140     endif()
141     math(EXPR l "${${type}_len} - ${l}")
142     string(SUBSTRING "${${type}_space}" 0 ${l} s)
143     if(type STREQUAL "OPTION")
144       if(${${f}})
145         set(value ON)
146       else()
147         set(value OFF)
148       endif()
149     else()
150       set(value "${${f}}")
151     endif()
152     if(NOT type STREQUAL "COMPONENT")
153       set(${type}_msg "${${type}_msg}\n     ${desc}${s}  ${value}")
154     else()
155       set(${type}_msg "${${type}_msg}\n     ${f}${s}  ${desc}")
156     endif()
157   endforeach()
158   message(STATUS "${OPTION_msg}\n")
159   message(STATUS "${PATH_msg}\n")
160   message(STATUS "${COMPONENT_msg}\n")
161 endfunction()
163 function(foam_target_link_libraries target)
164   set(libs "${ARGN}")
165   target_link_libraries(${target} ${libs})
166   get_property(tp_libs GLOBAL PROPERTY FOAM_THIRDPARTY_LIBRARIES)
167   if(tp_libs)
168     list(REMOVE_ITEM libs ${tp_libs})
169     set_target_properties(${target} PROPERTIES
170       LINK_INTERFACE_LIBRARIES "${libs}")
171   endif()
172 endfunction()
174 function(foam_add_tutorial_tests)
175   if(NOT BUILD_TESTING)
176     return()
177   endif()
178   set(allrun_script
179     "${CMAKE_CURRENT_BINARY_DIR}/Allrun${FOAM_PY_SCRIPT_SUFFIX}")
180   if(NOT EXISTS ${allrun_script})
181     message(FATAL_ERROR
182       "No Allrun script configured in ${CMAKE_CURRENT_SOURCE_DIR}")
183     return()
184   endif()
185   execute_process(
186     COMMAND "${PYTHON_EXECUTABLE}" "${allrun_script}" --cases
187     WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
188     RESULT_VARIABLE result
189     OUTPUT_VARIABLE cases
190     ERROR_VARIABLE errmsg
191     OUTPUT_STRIP_TRAILING_WHITESPACE
192     )
193   if(result)
194     message(SEND_ERROR "Error running Allrun --cases:\n${errmsg}")
195     return()
196   endif()
197   string(REPLACE "\n" ";" cases "${cases}")
198   set(last_c)
199   if(NOT FOAM_ENABLE_FULL_TUTORIAL_TESTS)
200     set(testarg --test)
201   else()
202     set(testarg)
203   endif()
204   foreach(c ${cases})
205     add_test(NAME ${c} COMMAND ${PYTHON_EXECUTABLE} ${allrun_script}
206       ${testarg} --verbose ${c})
207     if(last_c)
208       set_tests_properties(${c} PROPERTIES DEPENDS ${last_c})
209     endif()
210     set(last_c ${c})
211   endforeach()
212   foreach(c ${cases})
213     add_test(NAME ${c}_clean COMMAND ${PYTHON_EXECUTABLE} ${allrun_script}
214       --clean)
215     set_tests_properties(${c}_clean PROPERTIES DEPENDS ${last_c})
216   endforeach()
217 endfunction()
219 # ------------------------- vim: set sw=2 sts=2 et: --------------- end-of-file