Back to home page

EIC code displayed by LXR

 
 

    


Warning, /geant4/cmake/Templates/UseGeant4_internal.cmake is written in an unsupported language. File is not indexed.

0001 # - Internal Use file for Geant4
0002 # This file is designed for inclusion by the UseGeant4.cmake file, but
0003 # only in the build tree. It contains functions and macros that are only
0004 # intended to help in building the Geant4 tests.
0005 #
0006 # IT SHOULD NOT BE INSTALLED!
0007 
0008 #-----------------------------------------------------------------------
0009 # Special internal functions for building tests.
0010 #-----------------------------------------------------------------------
0011 #-----------------------------------------------------------------------
0012 # function geant4_add_test(<name> COMMAND cmd [arg1... ]
0013 #                          [PRECMD cmd [arg1...]] [POSTCMD cmd [arg1...]]
0014 #                           [OUTPUT outfile] [ERROR errfile]
0015 #                           [WORKING_DIRECTORY directory]
0016 #                           [ENVIRONMENT var1=val1 var2=val2 ...
0017 #                           [DEPENDS test1 ...]
0018 #                           [TIMEOUT seconds]
0019 #                           [DEBUG]
0020 #                           [SOURCE_DIR dir] [BINARY_DIR dir]
0021 #                           [BUILD target] [PROJECT project]
0022 #                           [PASSREGEX exp] [FAILREGEX epx]
0023 #                           [LABELS label1 label2 ...])
0024 #
0025 function(geant4_add_test test)
0026   if(NOT CMAKE_PROJECT_NAME STREQUAL Geant4)
0027     message(WARNING "geant4_add_test is only for internal Geant4 usage, test '${test}' is disabled")
0028     return()
0029   endif()
0030 
0031   cmake_parse_arguments(ARG
0032     "DEBUG"
0033     "TIMEOUT;BUILD;OUTPUT;ERROR;SOURCE_DIR;BINARY_DIR;PROJECT;PASSREGEX;FAILREGEX;WORKING_DIRECTORY"
0034     "COMMAND;PRECMD;POSTCMD;ENVIRONMENT;DEPENDS;LABELS"
0035     ${ARGN})
0036 
0037   if(CMAKE_CONFIGURATION_TYPES)
0038     set(_cfg $<CONFIGURATION>/)
0039   endif()
0040 
0041   # COMMAND AND BUILD: split test
0042   # - In this case, we have to create a -build and a -run test with the latter depending on the former
0043   # NOT COMMAND AND BUILD: pure build
0044   # COMMAND AND NOT BUILD: pure test
0045   if(ARG_COMMAND AND ARG_BUILD)
0046     set(_is_split_test TRUE)
0047   endif()
0048 
0049   #- Handle COMMAND argument
0050   list(LENGTH ARG_COMMAND _len)
0051   if(_len LESS 1)
0052     if(NOT ARG_BUILD)
0053       message(FATAL_ERROR "GEANT4_ADD_TEST: command is mandatory (without build)")
0054     endif()
0055   else()
0056     list(GET ARG_COMMAND 0 _prg)
0057     list(REMOVE_AT ARG_COMMAND 0)
0058     if(NOT IS_ABSOLUTE ${_prg})
0059       if(TARGET ${_prg})
0060         set(_prg "$<TARGET_FILE:${_prg}>")
0061       else()
0062         set(_prg ${CMAKE_CURRENT_BINARY_DIR}/${_cfg}${_prg})
0063       endif()
0064     elseif(EXISTS ${_prg})
0065       # Calling a prexisting/system program
0066     else()
0067       get_filename_component(_path ${_prg} PATH)
0068       get_filename_component(_file ${_prg} NAME)
0069       set(_prg ${_path}/${_cfg}${_file})
0070     endif()
0071     set(_cmd ${_prg} ${ARG_COMMAND})
0072     string(REPLACE ";" "#" _cmd "${_cmd}")
0073     string(REPLACE "=" "@" _cmd "${_cmd}")
0074   endif()
0075 
0076   set(_command ${CMAKE_COMMAND} -DTST=${test} -DCMD=${_cmd})
0077 
0078   #- Handle PRE and POST commands
0079   if(ARG_PRECMD)
0080     set(_pre ${ARG_PRECMD})
0081     string(REPLACE ";" "#" _pre "${_pre}")
0082     set(_command ${_command} -DPRE=${_pre})
0083   endif()
0084   if(ARG_POSTCMD)
0085     set(_post ${ARG_POSTCMD})
0086     string(REPLACE ";" "#" _post "${_post}")
0087     set(_command ${_command} -DPOST=${_post})
0088   endif()
0089 
0090   #- Handle OUTPUT, ERROR, DEBUG arguments
0091   if(ARG_OUTPUT)
0092     set(_command ${_command} -DOUT=${ARG_OUTPUT})
0093   endif()
0094 
0095   if(ARG_ERROR)
0096     set(_command ${_command} -DERR=${ARG_ERROR})
0097   endif()
0098 
0099   if(ARG_DEBUG)
0100     set(_command ${_command} -DDBG=ON)
0101   endif()
0102 
0103   if(ARG_WORKING_DIRECTORY)
0104     set(_command ${_command} -DCWD=${ARG_WORKING_DIRECTORY})
0105   endif()
0106 
0107   if(ARG_TIMEOUT)
0108     set(_command ${_command} -DTIM=${ARG_TIMEOUT})
0109   endif()
0110 
0111   #- Handle ENVIRONMENT argument
0112   if(ARG_ENVIRONMENT)
0113     string(REPLACE ";" "#" _env "${ARG_ENVIRONMENT}")
0114     string(REPLACE "=" "@" _env "${_env}")
0115     set(_command ${_command} -DENV=${_env})
0116   endif()
0117 
0118   #- Locate the test driver
0119   # This is one of the few cases where we require ..._SOURCE_DIR to be scoped to Geant4
0120   # because we may have called geant4_add_test after a project() call, as in the integration tests
0121   set(_driver ${Geant4_SOURCE_DIR}/cmake/Modules/G4TestDriver.cmake)
0122   if(NOT EXISTS ${_driver})
0123     message(FATAL_ERROR "geant4_add_test: G4TestDriver.cmake not found!")
0124   endif()
0125   set(_command ${_command} -P ${_driver})
0126 
0127   #- Now we can actually add the test
0128   if(ARG_BUILD)
0129     if(NOT ARG_SOURCE_DIR)
0130       set(ARG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
0131     endif()
0132     if(NOT ARG_BINARY_DIR)
0133       set(ARG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
0134     endif()
0135     if(NOT ARG_PROJECT)
0136        if(NOT PROJECT_NAME STREQUAL "Geant4")
0137          set(ARG_PROJECT ${PROJECT_NAME})
0138        else()
0139          set(ARG_PROJECT ${ARG_BUILD})
0140        endif()
0141     endif()
0142 
0143     set(__build_test_name "${test}")
0144     set(__run_test_name "")
0145 
0146     if(_is_split_test)
0147       set(__build_test_name "${test}-build")
0148       set(__run_test_name "${test}")
0149     endif()
0150 
0151     # Build part of the test
0152     # Again, note that we scope Geant4_DIR to Geant4_BINARY_DIR so we don't accidentally pickup
0153     # local or higher scopes
0154     add_test(NAME ${__build_test_name} COMMAND ${CMAKE_CTEST_COMMAND}
0155         --build-and-test  ${ARG_SOURCE_DIR} ${ARG_BINARY_DIR}
0156         --build-generator ${CMAKE_GENERATOR}
0157         --build-makeprogram ${CMAKE_MAKE_PROGRAM}
0158         --build-target ${ARG_BUILD}
0159         --build-project ${ARG_PROJECT}
0160         --build-config $<CONFIGURATION>
0161         --build-noclean
0162         --build-options
0163           --no-warn-unused-cli
0164           -DGeant4_DIR=${Geant4_BINARY_DIR}
0165           -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
0166           -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
0167           -DCMAKE_C_FLAGS_DEBUG=${CMAKE_C_FLAGS_DEBUG}
0168           -DCMAKE_C_FLAGS_MINSIZEREL=${CMAKE_C_FLAGS_MINSIZEREL}
0169           -DCMAKE_C_FLAGS_RELEASE=${CMAKE_C_FLAGS_RELEASE}
0170           -DCMAKE_C_FLAGS_RELWITHDEBINFO=${CMAKE_C_FLAGS_RELWITHDEBINFO}
0171           -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
0172           -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
0173           -DCMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG}
0174           -DCMAKE_CXX_FLAGS_MINSIZEREL=${CMAKE_CXX_FLAGS_MINSIZEREL}
0175           -DCMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE}
0176           -DCMAKE_CXX_FLAGS_RELWITHDEBINFO=${CMAKE_CXX_FLAGS_RELWITHDEBINFO}
0177           -DCMAKE_CXX_FLAGS_FULLRELWITHDEBINFO=${CMAKE_CXX_FLAGS_FULLRELWITHDEBINFO}
0178           -DCMAKE_DISABLE_FIND_PACKAGE_ROOT=$<BOOL:${CMAKE_DISABLE_FIND_PACKAGE_ROOT}>
0179     )
0180     set_property(TEST ${__build_test_name} PROPERTY ENVIRONMENT Geant4_DIR=${Geant4_BINARY_DIR})
0181 
0182     # Build part of the test should have additional regex, and *must* have same labels
0183     if(ARG_FAILREGEX)
0184       set_property(TEST ${__build_test_name} PROPERTY FAIL_REGULAR_EXPRESSION "warning:|(${ARG_FAILREGEX})")
0185     else()
0186       set_property(TEST ${__build_test_name} PROPERTY FAIL_REGULAR_EXPRESSION "warning:")
0187     endif()
0188 
0189     if(ARG_LABELS)
0190       set_property(TEST ${__build_test_name} PROPERTY LABELS ${ARG_LABELS})
0191     else()
0192       set_property(TEST ${__build_test_name} PROPERTY LABELS Nightly)
0193     endif()
0194 
0195     # (Optional) Run part of the test
0196     if(__run_test_name)
0197       add_test(NAME ${__run_test_name} COMMAND ${_command})
0198       set_property(TEST ${__run_test_name} PROPERTY DEPENDS ${__build_test_name})
0199       if(ARG_FAILREGEX)
0200         set_property(TEST ${__run_test_name} PROPERTY FAIL_REGULAR_EXPRESSION ${ARG_FAILREGEX})
0201       endif()
0202 
0203       # If WORKING_DIRECTORY supplied, make sure testdriver is run in
0204       # that directory, otherwise use specific binary dir
0205       if(ARG_WORKING_DIRECTORY)
0206         set_property(TEST ${__run_test_name} PROPERTY WORKING_DIRECTORY "${ARG_WORKING_DIRECTORY}")
0207       else()
0208         set_property(TEST ${__run_test_name} PROPERTY WORKING_DIRECTORY "${ARG_BINARY_DIR}")
0209       endif()
0210     endif()
0211   else()
0212     add_test(NAME ${test} COMMAND ${_command})
0213     if(ARG_FAILREGEX)
0214       set_property(TEST ${test} PROPERTY FAIL_REGULAR_EXPRESSION ${ARG_FAILREGEX})
0215     endif()
0216 
0217     # If WORKING_DIRECTORY supplied, make sure testdriver is run in
0218     # that directory.
0219     if(ARG_WORKING_DIRECTORY)
0220       set_property(TEST ${test} PROPERTY WORKING_DIRECTORY "${ARG_WORKING_DIRECTORY}")
0221     endif()
0222   endif()
0223 
0224   #- Handle TIMOUT and DEPENDS arguments
0225   if(ARG_TIMEOUT)
0226     set_property(TEST ${test} PROPERTY TIMEOUT ${ARG_TIMEOUT})
0227   endif()
0228 
0229   if(ARG_DEPENDS)
0230     # MUST be append because a split test may set this earlier
0231     set_property(TEST ${test} APPEND PROPERTY DEPENDS ${ARG_DEPENDS})
0232   endif()
0233 
0234   if(ARG_PASSREGEX)
0235     set_property(TEST ${test} PROPERTY PASS_REGULAR_EXPRESSION ${ARG_PASSREGEX})
0236   endif()
0237 
0238   if(ARG_LABELS)
0239     set_property(TEST ${test} PROPERTY LABELS ${ARG_LABELS})
0240   else()
0241     set_property(TEST ${test} PROPERTY LABELS Nightly)
0242   endif()
0243 endfunction()
0244