1 # /*-------------------------------------------------------------------------*\
3 # \\ / F ield | foam-extend: Open Source CFD
4 # \\ / O peration | Version: 4.0
5 # \\ / A nd | Web: http://www.foam-extend.org
6 # \\/ M anipulation | For copyright notice see file Copyright
7 # -----------------------------------------------------------------------------
9 # This file is part of foam-extend.
11 # foam-extend is free software: you can redistribute it and/or modify it
12 # under the terms of the GNU General Public License as published by the
13 # Free Software Foundation, either version 3 of the License, or (at your
14 # option) any later version.
16 # foam-extend is distributed in the hope that it will be useful, but
17 # WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 # General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
25 # CMakeLists.txt file for implementing a test harness for the compilation
26 # and test of foam-extend-3.2 using Kitware CTest/CMake/CDash
28 # The results will be submitted to the CDash server identified by the file
32 # Martin Beaudoin, Hydro-Quebec, 2010. All rights reserved
35 # \*-------------------------------------------------------------------------*/
37 cmake_minimum_required (VERSION 2.8)
39 PROJECT(foam-extend-4.0)
41 #-----------------------------------------------------------------------------
46 # Set the variable named ${var} to the host hostname
48 function(GetHostName var)
49 set( thisHostName "unknown")
54 OUTPUT_VARIABLE thisHostname
59 OUTPUT_VARIABLE thisHostname
62 set(${var} ${thisHostname} PARENT_SCOPE)
66 # GetGitStatus(status ecode)
68 # Get the git status for the local git repository of the source code
69 # The variable named ${status} will get the git status
70 # The variable named ${ecode} will get the command error code
72 function(GetGitStatus _status _ecode)
73 set( git_status "unknown")
78 WORKING_DIRECTORY ${FOAM_ROOT}
79 OUTPUT_VARIABLE git_status
80 RESULT_VARIABLE git_ecode
83 set(${_status} ${git_status} PARENT_SCOPE)
84 set(${_ecode} ${git_ecode} PARENT_SCOPE)
88 # GetGitBranchName(var)
90 # Set the variable named ${var} to the git branch name of the source code
92 function(GetGitBranchName var)
93 set( retValue "unknown")
96 COMMAND git branch --no-color
97 WORKING_DIRECTORY ${FOAM_ROOT}
98 OUTPUT_VARIABLE listOfGitBranches
100 # Create list of strings
101 string(REPLACE "\n" ";" listOfGitBranches ${listOfGitBranches})
103 # Iterate over list, find the string beginning with "* "
104 foreach(branch ${listOfGitBranches})
105 string(REGEX MATCH "\\* .*$" matchString ${branch})
106 string(LENGTH "${matchString}" lengthMatchString)
107 if(lengthMatchString GREATER 0)
108 # We have match. Cleanup and set retValue
109 string(REPLACE "* " "" retValue ${matchString})
113 set(${var} ${retValue} PARENT_SCOPE)
117 # GetGitRevNumber(var)
119 # Set the variable named ${var} to the git revision number of the source code
121 function(GetGitRevNumber var)
122 set( retValue "unknown")
125 COMMAND git rev-parse --short=12 HEAD
126 WORKING_DIRECTORY ${FOAM_ROOT}
127 OUTPUT_VARIABLE git_rev_number
130 # Minimal check that we do have a valid string
131 string(LENGTH "${git_rev_number}" lengthString)
132 if(lengthString GREATER 0)
133 set(retValue ${git_rev_number})
136 set(${var} ${retValue} PARENT_SCOPE)
139 # CleanUpStringForCDash(var)
141 # Cleanup the variable named ${value} for characters not supported
142 # for CDash identifiers. Return the modified value in retVar
144 function(CleanUpStringForCDash value retVar)
145 string(REPLACE "/" "_" value "${value}")
146 string(REPLACE " " "_" value ${value})
147 set(${retVar} ${value} PARENT_SCOPE)
150 #-----------------------------------------------------------------------------
153 # Initialization of CTest specific variables
155 ## Run ctest in parallel if environment variable WM_NCOMPPROCS is set
156 IF (NOT $ENV{WM_NCOMPPROCS} STREQUAL "")
157 # Will run ctest in parallel over $WM_NCOMPPROCS processors
158 set(CMAKE_CTEST_COMMAND ${CMAKE_CTEST_COMMAND} --parallel $ENV{WM_NCOMPPROCS})
159 MESSAGE("Running tests in parallel using $ENV{WM_NCOMPPROCS} processors")
162 # Initialize the site name
164 IF (NOT $ENV{CDASH_SUBMIT_LOCAL_HOST_ID} STREQUAL "")
165 # We can override the site name with the environment variable
166 # $CDASH_SUBMIT_LOCAL_HOST_ID
168 SITENAME $ENV{CDASH_SUBMIT_LOCAL_HOST_ID}
169 CACHE STRING "Name of the local site"
172 # Grab the hostname FQN; will be used for the sitename
173 GetHostName(SITENAME)
177 MESSAGE("Initializing the name of this local site to: ${SITENAME}")
181 CACHE STRING "Name of the local site"
184 #Grab the FOAM installation directory.
186 FOAM_ROOT $ENV{WM_PROJECT_DIR}
187 CACHE INTERNAL "FOAM root directory."
190 # Construct the build name.
191 # No need to add $WM_PROJECT_VERSION to the name of the build,
192 # the test harness name should have taken care of that.
194 BUILDNAME $ENV{WM_OPTIONS}
195 CACHE STRING "Build ID"
198 # We allow overriding the git branch and revision information with some
199 # user-supplied information using the CDASH_SCM_INFO environment variable.
201 # Mercurial or other SCM users should be using this environment variable
202 # in order to provide branch and revision information for the buildname.
204 # Git users should use this environment variable in order to provide
205 # additionnal information instead of just the branch and revision number.
207 # Otherwise, the buildname will be appended with the following information:
208 # -git-branch=the_git_branch_name-git-rev=the_git_revision_number
210 BUILDNAME_SCM_INFO $ENV{CDASH_SCM_INFO}
211 CACHE STRING "SCM info for CDash buildname"
214 # Find out the version of the compiler being used.
215 # Add this information to the buildname
216 # This is for gcc or icc because they both support the -dumpversion option
217 EXEC_PROGRAM($ENV{WM_CC}
219 OUTPUT_VARIABLE COMPILER_VERSION
221 SET(BUILDNAME "${BUILDNAME}-$ENV{WM_CC}${COMPILER_VERSION}")
223 # We will support more compilers eventually.
226 # Timeout for running every single test: 4 hours: 4 x 3600 seconds
228 # DART_TESTING_TIMEOUT 14400
229 # CACHE STRING "Maximum time allowed (4 hours) before CTest will kill the test."
231 # Timeout for running all this: 20 minutes : 1200 seconds (for debug)
233 DART_TESTING_TIMEOUT 1200
234 CACHE STRING "Maximum time allowed (20 minutes) before CTest will kill the test."
238 CMAKE_VERBOSE_MAKEFILE TRUE
243 #-----------------------------------------------------------------------------
244 set (UPDATE_TYPE git)
251 if(NOT BUILDNAME_SCM_INFO STREQUAL "")
252 SET(BUILDNAME "${BUILDNAME}-${BUILDNAME_SCM_INFO}")
255 message("The git command was found: ${GIT_EXECUTABLE}")
257 # Check if the source code is under a valid git repository
258 GetGitStatus(GIT_STATUS GIT_ECODE)
261 # We have a valid git repository.
262 # Grab the branch and revision info. Add to the build name
263 GetGitBranchName(GIT_BRANCH_NAME)
264 message("Git branch: ${GIT_BRANCH_NAME}")
266 GetGitRevNumber(GIT_REV_NUMBER)
267 message("Git revision: ${GIT_REV_NUMBER}")
269 SET(BUILDNAME "${BUILDNAME}-git-branch=${GIT_BRANCH_NAME}")
270 SET(BUILDNAME "${BUILDNAME}-git-rev=${GIT_REV_NUMBER}")
274 WORKING_DIRECTORY ${FOAM_ROOT}
275 OUTPUT_VARIABLE HG_STATUS
276 RESULT_VARIABLE HG_ECODE
280 # We have a valid git repository. Grab the branch and revision info.
281 # Add to the build name
282 message("No git-branch. Mercurial?")
285 OUTPUT_VARIABLE GIT_BRANCH_NAME
289 OUTPUT_VARIABLE GIT_REV_NUMBER
292 ARGS log --template='git_{gitnode|short}' -l 1
293 OUTPUT_VARIABLE GIT_REAL_REV_NUMBER
295 string(REPLACE " " "_" GIT_BRANCH_NAME ${GIT_BRANCH_NAME})
296 string(REPLACE "+" ":modified" GIT_REV_NUMBER ${GIT_REV_NUMBER})
297 SET(GIT_REV_NUMBER "${GIT_REV_NUMBER}_${GIT_REAL_REV_NUMBER}")
298 message("Git branch (mercurial): ${GIT_BRANCH_NAME} Revision: ${GIT_REV_NUMBER}")
300 SET(BUILDNAME "${BUILDNAME}-hg-branch=${GIT_BRANCH_NAME}")
301 SET(BUILDNAME "${BUILDNAME}-hg-rev=${GIT_REV_NUMBER}")
303 # Not a git or mercurial repository: no branch nor revision information available
304 SET(BUILDNAME "${BUILDNAME}-git-branch=unknown")
305 SET(BUILDNAME "${BUILDNAME}-git-rev=unknown")
309 # Git is not available: no branch nor revision information supplied
310 SET(BUILDNAME "${BUILDNAME}-git-branch=unknown")
311 SET(BUILDNAME "${BUILDNAME}-git-rev=unknown")
314 # Some last minute cleanup
315 # Seems like no '/' or ' 'are allowed in the BUILDNAME or in the SITE name
316 CleanUpStringForCDash(${BUILDNAME} BUILDNAME)
317 CleanUpStringForCDash(${SITE} SITE)
319 message("Build name: ${BUILDNAME}")
320 message("Site name: ${SITE}")
324 #-----------------------------------------------------------------------------
326 # Compile FOAM, libs and apps
327 add_custom_target (foam-extend-$ENV{WM_PROJECT_VERSION} ALL
328 ${FOAM_ROOT}/Allwmake
332 TARGET foam-extend-$ENV{WM_PROJECT_VERSION}
333 PROPERTY LABELS foam-extend-$ENV{WM_PROJECT_VERSION}
336 # Compile the FOAM unit tests located under applications/test
337 # This part will not be compiled and run by default.
338 # This would be a good candidate for a sub-project
339 add_custom_target (foam-extend-$ENV{WM_PROJECT_VERSION}_unitTests
340 wmake all ${FOAM_ROOT}/applications/test
344 #-----------------------------------------------------------------------------
346 #Enable testing and dashboard
350 SET (CTEST_UPDATE_COMMAND ${GIT_EXECUTABLE})
353 CTEST_CUSTOM_MAXIMUM_NUMBER_OF_ERRORS 1000
354 CACHE INTERNAL "Max number of errors"
357 CTEST_CUSTOM_MAXIMUM_NUMBER_OF_WARNINGS 1000
358 CACHE INTERNAL "Max number of warnings"
363 # Modify this variable if you want the full length test case simulations
364 # Beware, this might take a long time to execute.
365 # Otherwise, the default behaviour is to run each tutorial for 1 "timestep"
366 #SET(RUN_FROM_ONE_TIMESTEP 0)
367 SET(RUN_FROM_ONE_TIMESTEP 1)
369 IF(RUN_FROM_ONE_TIMESTEP)
370 SET(testIdSuffix "_oneTimeStep")
371 ENDIF(RUN_FROM_ONE_TIMESTEP)
373 # FOAM will run against this test suite:
375 # Add the suite of FOAM tutorials
377 INCLUDE($ENV{FOAM_TEST_HARNESS_DIR}/CMakeFiles/FOAM_Tutorials.cmake)
379 IF(RUN_FROM_ONE_TIMESTEP)
380 # Modify the cases controlDict file in order to run for only one time step
381 MESSAGE("${testRunTimeDirectory}: Modifying the controlDict files for running only one time step in directory: ${TEST_CASE_DIR}")
383 # Need to supply a bash shell to run the script under Windows
385 COMMAND bash -c "$ENV{FOAM_TEST_HARNESS_DIR}/scripts/prepareCasesForOneTimeStep.sh ${TEST_CASE_DIR}"
390 COMMAND $ENV{FOAM_TEST_HARNESS_DIR}/scripts/prepareCasesForOneTimeStep.sh ${TEST_CASE_DIR}
394 ENDIF(RUN_FROM_ONE_TIMESTEP)