macro(test_castem2 test_arg)
  foreach(rm ${IEEE754_ROUNDING_MODES})
    if(CMAKE_CONFIGURATION_TYPES)
      foreach(conf ${CMAKE_CONFIGURATION_TYPES})
	set(test "castem2${test_arg}_${rm}_${conf}_mtest")
	set(file "castem2${test_arg}-${rm}-${conf}.mtest")
	get_property(MFrontCastemBehavioursBuildPath TARGET MFrontCastemBehaviours PROPERTY LOCATION_${conf})
	if(HAVE_CASTEM)
	  get_property(MFrontMaterialPropertiesCastemBuildPath TARGET MFrontMaterialProperties-castem PROPERTY LOCATION_${conf})
	endif(HAVE_CASTEM)
	configure_file(castem2${test_arg}.mtest.in ${file} @ONLY)
	add_test(NAME ${test}
	  CONFIGURATIONS ${conf}
	  COMMAND mtest --verbose=level0 --xml-output=true --result-file-output=false ${file})
	if((CMAKE_HOST_WIN32) AND (NOT MSYS))
          set_property(TEST ${test}
            PROPERTY DEPENDS "MFrontCastemBehaviours MFrontMaterialProperties-castem mtest"
	    PROPERTY ENVIRONMENT "PATH=$<TARGET_FILE_DIR:TFELMTest>\;$<TARGET_FILE_DIR:TFELMFront>\;$<TARGET_FILE_DIR:MFrontLogStream>\;$<TARGET_FILE_DIR:TFELMaterial>\;$<TARGET_FILE_DIR:TFELNUMODIS>\;$<TARGET_FILE_DIR:TFELMathParser>\;$<TARGET_FILE_DIR:TFELGlossary>\;$<TARGET_FILE_DIR:TFELSystem>\;$<TARGET_FILE_DIR:TFELUtilities>\;$<TARGET_FILE_DIR:TFELException>\;$<TARGET_FILE_DIR:TFELTests>\;$<TARGET_FILE_DIR:TFELConfig>\;$<TARGET_FILE_DIR:TFELUnicodeSupport>\;$ENV{PATH}")
	elseif((CMAKE_HOST_WIN32) AND (NOT MSYS))
          set_property(TEST ${test}
            PROPERTY DEPENDS "MFrontCastemBehaviours MFrontMaterialProperties-castem mtest")
	endif((CMAKE_HOST_WIN32) AND (NOT MSYS))
	if(TFEL_APPEND_SUFFIX)
	  install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${file}
	    DESTINATION "share/doc/mfront-${TFEL_SUFFIX}/tests/behaviours/castem2"
	    CONFIGURATIONS ${conf}
	    COMPONENT mtest)
	else(TFEL_APPEND_SUFFIX)
	  install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${file}
	    DESTINATION "share/doc/mfront/tests/behaviours/castem2"
	    CONFIGURATIONS ${conf}
	    COMPONENT mtest)
	endif(TFEL_APPEND_SUFFIX)
      endforeach(conf ${CMAKE_CONFIGURATION_TYPES})
    else(CMAKE_CONFIGURATION_TYPES)
      set(test "castem2${test_arg}_${rm}_mtest")
      set(file "castem2${test_arg}-${rm}.mtest")
      get_property(MFrontCastemBehavioursBuildPath TARGET MFrontCastemBehaviours PROPERTY LOCATION_${conf})
      if(HAVE_CASTEM)
	get_property(MFrontMaterialPropertiesCastemBuildPath TARGET MFrontMaterialProperties-castem PROPERTY LOCATION)
      endif(HAVE_CASTEM)
      configure_file(castem2${test_arg}.mtest.in ${file} @ONLY)
      add_test(NAME ${test}
	COMMAND mtest --verbose=level0 --xml-output=true --result-file-output=false ${file})
      set_tests_properties(${test} PROPERTIES DEPENDS MFrontCastemBehaviours)
      set_tests_properties(${test} PROPERTIES DEPENDS mtest)
      if(TFEL_APPEND_SUFFIX)
	install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${file}
	  DESTINATION "share/doc/mfront-${TFEL_SUFFIX}/tests/behaviours/castem2"
	  COMPONENT mtest)
      else(TFEL_APPEND_SUFFIX)
	install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${file}
	  DESTINATION "share/doc/mfront/tests/behaviours/castem2"
	  COMPONENT mtest)
      endif(TFEL_APPEND_SUFFIX)
    endif(CMAKE_CONFIGURATION_TYPES)
  endforeach(rm ${IEEE754_ROUNDING_MODES})
endmacro(test_castem2)

test_castem2(elasticity)
test_castem2(elasticity2)
if(HAVE_CASTEM)
  test_castem2(elasticity3)
  foreach(rm ${IEEE754_ROUNDING_MODES})
    if(CMAKE_CONFIGURATION_TYPES)
      foreach(conf ${CMAKE_CONFIGURATION_TYPES})
	set_tests_properties(castem2elasticity3_${rm}_${conf}_mtest
	  PROPERTIES DEPENDS MFrontMaterialProperties-castem)
      endforeach(conf ${CMAKE_CONFIGURATION_TYPES})
    else(CMAKE_CONFIGURATION_TYPES)
      set_tests_properties(castem2elasticity3_${rm}_mtest
	PROPERTIES DEPENDS MFrontMaterialProperties-castem)
    endif(CMAKE_CONFIGURATION_TYPES)
  endforeach(rm ${IEEE754_ROUNDING_MODES})
endif(HAVE_CASTEM)
test_castem2(elasticity4)
test_castem2(elasticity5)
test_castem2(elasticity6)
test_castem2(elasticity7)
test_castem2(elasticity8)
test_castem2(elasticity9)
test_castem2(elasticity10)
test_castem2(elasticity11)
test_castem2(elasticity12)
test_castem2(elasticity13)
test_castem2(elasticity14)
test_castem2(elasticity15)
test_castem2(elasticity16)
test_castem2(druckerprager)
test_castem2(druckerprager2)
test_castem2(norton)
test_castem2(norton2)
test_castem2(implicitnorton)
test_castem2(implicitnorton3)
test_castem2(stressrelaxation)
test_castem2(strainhardeningcreep)
test_castem2(plasticity)
test_castem2(plasisocin)
test_castem2(viscoplasisocin)
test_castem2(chaboche)
test_castem2(chaboche2)
test_castem2(monocrystal)
test_castem2(monocrystal-2)
test_castem2(implicitmonocrystal)
test_castem2(implicitmonocrystal-2)
test_castem2(monocrystal_dd_cfc)
test_castem2(monocrystal_dd_cfc_numericaljacobian)
test_castem2(monocrystal_dd_cfc_irradiation)
test_castem2(monocrystal_dd_cc)
test_castem2(monocrystal_dd_cc_numericaljacobian)
test_castem2(monocrystal_dd_cc_irradiation_numericaljacobian)
test_castem2(implicithayhurst)
test_castem2(gursontvergaardneedlemanplasticflow)
test_castem2(gursontvergaardneedlemanviscoplasticflow)
test_castem2(ellipticcreep)
test_castem2(burger)
test_castem2(tssf)
test_castem2(saintvenantkirchhoffelasticity-uniaxialloading-sig11-1D)
test_castem2(saintvenantkirchhoffelasticity-uniaxialloading-sig22-1D)
test_castem2(saintvenantkirchhoffelasticity-uniaxialloading-sig33-1D)
test_castem2(saintvenantkirchhoffelasticity-uniaxialloading-sig11-2D)
test_castem2(saintvenantkirchhoffelasticity-uniaxialloading-sig22-2D)
test_castem2(saintvenantkirchhoffelasticity-uniaxialloading-sig33-2D)
test_castem2(saintvenantkirchhoffelasticity-uniaxialloading-sig11-3D)
test_castem2(saintvenantkirchhoffelasticity-uniaxialloading-sig22-3D)
test_castem2(saintvenantkirchhoffelasticity-uniaxialloading-sig33-3D)
test_castem2(saintvenantkirchhoffelasticity-uniaxialloading-1-1D)
test_castem2(saintvenantkirchhoffelasticity-uniaxialloading-2-1D)
test_castem2(saintvenantkirchhoffelasticity-uniaxialloading-3-1D)
test_castem2(saintvenantkirchhoffelasticity-uniaxialloading-1-2D)
test_castem2(saintvenantkirchhoffelasticity-uniaxialloading-2-2D)
test_castem2(saintvenantkirchhoffelasticity-uniaxialloading-3-2D)
test_castem2(saintvenantkirchhoffelasticity-shear-1-2D)
test_castem2(saintvenantkirchhoffelasticity-shear-2-2D)
test_castem2(saintvenantkirchhoffelasticity-uniaxialloading-1-3D)
test_castem2(saintvenantkirchhoffelasticity-uniaxialloading-2-3D)
test_castem2(saintvenantkirchhoffelasticity-uniaxialloading-3-3D)
test_castem2(saintvenantkirchhoffelasticity-shear-1-3D)
test_castem2(saintvenantkirchhoffelasticity-shear-2-3D)
test_castem2(saintvenantkirchhoffelasticity-shear-3-3D)
test_castem2(saintvenantkirchhoffelasticity-shear-4-3D)
test_castem2(saintvenantkirchhoffelasticity-shear-5-3D)
test_castem2(saintvenantkirchhoffelasticity-shear-6-3D)
test_castem2(finiterotationsmallstrainelasticity-uniaxialloading-1-1D)
test_castem2(finiterotationsmallstrainelasticity-uniaxialloading-2-1D)
test_castem2(finiterotationsmallstrainelasticity-uniaxialloading-3-1D)
test_castem2(finiterotationsmallstrainelasticity-uniaxialloading-1-2D)
test_castem2(finiterotationsmallstrainelasticity-uniaxialloading-2-2D)
test_castem2(finiterotationsmallstrainelasticity-uniaxialloading-3-2D)
test_castem2(finiterotationsmallstrainelasticity-shear-1-2D)
test_castem2(finiterotationsmallstrainelasticity-shear-2-2D)
test_castem2(finiterotationsmallstrainelasticity-uniaxialloading-1-3D)
test_castem2(finiterotationsmallstrainelasticity-uniaxialloading-2-3D)
test_castem2(finiterotationsmallstrainelasticity-uniaxialloading-3-3D)
test_castem2(finiterotationsmallstrainelasticity-shear-1-3D)
test_castem2(finiterotationsmallstrainelasticity-shear-2-3D)
test_castem2(finiterotationsmallstrainelasticity-shear-3-3D)
test_castem2(finiterotationsmallstrainelasticity-shear-4-3D)
test_castem2(finiterotationsmallstrainelasticity-shear-5-3D)
test_castem2(finiterotationsmallstrainelasticity-shear-6-3D)
test_castem2(finiterotationsmallstrainelasticity2-uniaxialloading-1-1D)
test_castem2(finiterotationsmallstrainelasticity2-uniaxialloading-2-1D)
test_castem2(finiterotationsmallstrainelasticity2-uniaxialloading-3-1D)
test_castem2(finiterotationsmallstrainelasticity2-uniaxialloading-1-2D)
test_castem2(finiterotationsmallstrainelasticity2-uniaxialloading-2-2D)
test_castem2(finiterotationsmallstrainelasticity2-uniaxialloading-3-2D)
test_castem2(finiterotationsmallstrainelasticity2-shear-1-2D)
test_castem2(finiterotationsmallstrainelasticity2-shear-2-2D)
test_castem2(finiterotationsmallstrainelasticity2-uniaxialloading-1-3D)
test_castem2(finiterotationsmallstrainelasticity2-uniaxialloading-2-3D)
test_castem2(finiterotationsmallstrainelasticity2-uniaxialloading-3-3D)
test_castem2(finiterotationsmallstrainelasticity2-shear-1-3D)
test_castem2(finiterotationsmallstrainelasticity2-shear-2-3D)
test_castem2(finiterotationsmallstrainelasticity2-shear-3-3D)
test_castem2(finiterotationsmallstrainelasticity2-shear-4-3D)
test_castem2(finiterotationsmallstrainelasticity2-shear-5-3D)
test_castem2(finiterotationsmallstrainelasticity2-shear-6-3D)

test_castem2(elasticity_malls-uniaxialloading-1-1D)
test_castem2(elasticity_malls-uniaxialloading-1-2D)
test_castem2(elasticity_malls-uniaxialloading-1-3D)
test_castem2(elasticity_malls-uniaxialloading-2-1D)
test_castem2(elasticity_malls-uniaxialloading-2-2D)
test_castem2(elasticity_malls-uniaxialloading-2-3D)
test_castem2(elasticity_malls-uniaxialloading-3-1D)
test_castem2(elasticity_malls-uniaxialloading-3-2D)
test_castem2(elasticity_malls-uniaxialloading-3-3D)
test_castem2(mieheapellambrechtlogarithmicstrainelasticity-uniaxialloading-1-1D)
test_castem2(mieheapellambrechtlogarithmicstrainelasticity-uniaxialloading-1-2D)
test_castem2(mieheapellambrechtlogarithmicstrainelasticity-uniaxialloading-1-3D)
test_castem2(mieheapellambrechtlogarithmicstrainelasticity-uniaxialloading-2-1D)
test_castem2(mieheapellambrechtlogarithmicstrainelasticity-uniaxialloading-2-2D)
test_castem2(mieheapellambrechtlogarithmicstrainelasticity-uniaxialloading-2-3D)
test_castem2(mieheapellambrechtlogarithmicstrainelasticity-uniaxialloading-3-1D)
test_castem2(mieheapellambrechtlogarithmicstrainelasticity-uniaxialloading-3-2D)
test_castem2(mieheapellambrechtlogarithmicstrainelasticity-uniaxialloading-3-3D)
test_castem2(mieheapellambrechtlogarithmicstrainelasticity2-uniaxialloading-1-1D)
test_castem2(mieheapellambrechtlogarithmicstrainelasticity2-uniaxialloading-1-2D)
test_castem2(mieheapellambrechtlogarithmicstrainelasticity2-uniaxialloading-1-3D)
test_castem2(mieheapellambrechtlogarithmicstrainelasticity2-uniaxialloading-2-1D)
test_castem2(mieheapellambrechtlogarithmicstrainelasticity2-uniaxialloading-2-2D)
test_castem2(mieheapellambrechtlogarithmicstrainelasticity2-uniaxialloading-2-3D)
test_castem2(mieheapellambrechtlogarithmicstrainelasticity2-uniaxialloading-3-1D)
test_castem2(mieheapellambrechtlogarithmicstrainelasticity2-uniaxialloading-3-2D)
test_castem2(mieheapellambrechtlogarithmicstrainelasticity2-uniaxialloading-3-3D)
test_castem2(mieheapellambrechtlogarithmicstrainelasticity3-uniaxialloading-1-1D)
test_castem2(mieheapellambrechtlogarithmicstrainelasticity3-uniaxialloading-1-2D)
test_castem2(mieheapellambrechtlogarithmicstrainelasticity3-uniaxialloading-1-3D)
test_castem2(mieheapellambrechtlogarithmicstrainelasticity3-uniaxialloading-2-1D)
test_castem2(mieheapellambrechtlogarithmicstrainelasticity3-uniaxialloading-2-2D)
test_castem2(mieheapellambrechtlogarithmicstrainelasticity3-uniaxialloading-2-3D)
test_castem2(mieheapellambrechtlogarithmicstrainelasticity3-uniaxialloading-3-1D)
test_castem2(mieheapellambrechtlogarithmicstrainelasticity3-uniaxialloading-3-2D)
test_castem2(mieheapellambrechtlogarithmicstrainelasticity3-uniaxialloading-3-3D)
test_castem2(mieheapellambrechtlogarithmicstrainnortoncreep-uniaxialloading-1-1D)
test_castem2(mieheapellambrechtlogarithmicstrainnortoncreep-uniaxialloading-1-2D)
test_castem2(mieheapellambrechtlogarithmicstrainnortoncreep-uniaxialloading-1-3D)
test_castem2(mieheapellambrechtlogarithmicstrainnortoncreep-uniaxialloading-2-1D)
test_castem2(mieheapellambrechtlogarithmicstrainnortoncreep-uniaxialloading-2-2D)
test_castem2(mieheapellambrechtlogarithmicstrainnortoncreep-uniaxialloading-2-3D)
test_castem2(mieheapellambrechtlogarithmicstrainnortoncreep-uniaxialloading-3-1D)
test_castem2(mieheapellambrechtlogarithmicstrainnortoncreep-uniaxialloading-3-2D)
test_castem2(mieheapellambrechtlogarithmicstrainnortoncreep-uniaxialloading-3-3D)
