CMakeLists.txt 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # a simple C only test case
  2. PROJECT (FunctionTest)
  3. SET(CMAKE_C_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_C_FLAGS}")
  4. FUNCTION(FAILED testname)
  5. MESSAGE(SEND_ERROR "${testname} failed ${ARGN}")
  6. ENDFUNCTION(FAILED)
  7. FUNCTION(PASS testname)
  8. MESSAGE("${testname} passed ${ARGN}")
  9. ENDFUNCTION(PASS)
  10. # test scope
  11. SET(COUNT 3)
  12. FUNCTION(scope_test)
  13. SET(COUNT 4)
  14. ENDFUNCTION(scope_test)
  15. scope_test()
  16. IF(COUNT EQUAL "3")
  17. PASS("scope")
  18. ELSE(COUNT EQUAL "3")
  19. FAILED("COUNT Got: ${COUNT}")
  20. ENDIF(COUNT EQUAL "3")
  21. # test ARGC
  22. FUNCTION(weird_name)
  23. IF("${ARGC}" EQUAL "3")
  24. PASS("ARGC")
  25. ELSE("${ARGC}" EQUAL "3")
  26. FAILED("ARGC" "Got: ${ARGC}")
  27. ENDIF("${ARGC}" EQUAL "3")
  28. ENDFUNCTION(weird_name)
  29. WeIrD_nAmE(a1 a2 a3)
  30. # test ARGN
  31. FUNCTION(test_argn_function argument)
  32. IF("${ARGN}" EQUAL "3")
  33. PASS("ARGN")
  34. ELSE("${ARGN}" EQUAL "3")
  35. FAILED("ARGN" "Got: ${ARGN}")
  36. ENDIF("${ARGN}" EQUAL "3")
  37. ENDFUNCTION(test_argn_function)
  38. Test_Argn_Function(ignored 3)
  39. # test recursion and return via raise_scope
  40. function (factorial argument result)
  41. if (argument LESS 2)
  42. set (${result} 1)
  43. else (argument LESS 2)
  44. math (EXPR temp "${argument} - 1")
  45. factorial (${temp} tresult)
  46. math (EXPR ${result} "${argument}*${tresult}")
  47. endif (argument LESS 2)
  48. raise_scope (${result})
  49. endfunction (factorial)
  50. factorial (5 fresult)
  51. if (fresult EQUAL 120)
  52. pass("factorial")
  53. else (fresult EQUAL 120)
  54. failed ("factorial, computed ${fresult} instead of 120")
  55. endif (fresult EQUAL 120)
  56. # case test
  57. FUNCTION(strange_function m)
  58. SET(${m} strange_function)
  59. RAISE_SCOPE(${m})
  60. ENDFUNCTION(strange_function m)
  61. STRANGE_FUNCTION(var)
  62. set(second_var "second_var")
  63. IF("${var}" STREQUAL "strange_function" AND "${second_var}" STREQUAL "second_var")
  64. PASS("Case Test" "(${var} ${second_var})")
  65. ELSE("${var}" STREQUAL "strange_function" AND "${second_var}" STREQUAL "second_var")
  66. FAILED("Case test" "(${var} ${second_var})")
  67. ENDIF("${var}" STREQUAL "strange_function" AND "${second_var}" STREQUAL "second_var")
  68. # test backing up command
  69. FUNCTION(ADD_EXECUTABLE exec)
  70. _ADD_EXECUTABLE(mini${exec} ${ARGN})
  71. ENDFUNCTION(ADD_EXECUTABLE)
  72. ADD_EXECUTABLE(FunctionTest functionTest.c)