CMakeLists.txt 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. # var undef case
  73. FUNCTION(undef_var m)
  74. SET(${m})
  75. RAISE_SCOPE(${m})
  76. ENDFUNCTION(undef_var)
  77. SET(FUNCTION_UNDEFINED 1)
  78. undef_var(FUNCTION_UNDEFINED)
  79. IF(DEFINED FUNCTION_UNDEFINED)
  80. FAILED("Function Undefine Test" "(${FUNCTION_UNDEFINED})")
  81. ELSE(DEFINED FUNCTION_UNDEFINED)
  82. PASS("Function Undefine Test" "(${FUNCTION_UNDEFINED})")
  83. ENDIF(DEFINED FUNCTION_UNDEFINED)
  84. # Subdirectory scope raise.
  85. SET(SUBDIR_UNDEFINED 1)
  86. ADD_SUBDIRECTORY(SubDirScope)
  87. IF(DEFINED SUBDIR_UNDEFINED)
  88. FAILED("Subdir Undefine Test" "(${SUBDIR_UNDEFINED})")
  89. ELSE(DEFINED SUBDIR_UNDEFINED)
  90. PASS("Subdir Undefine Test" "(${SUBDIR_UNDEFINED})")
  91. ENDIF(DEFINED SUBDIR_UNDEFINED)
  92. IF(DEFINED SUBDIR_DEFINED)
  93. PASS("Subdir Define Test" "(${SUBDIR_DEFINED})")
  94. ELSE(DEFINED SUBDIR_DEFINED)
  95. FAILED("Subdir Define Test" "(${SUBDIR_DEFINED})")
  96. ENDIF(DEFINED SUBDIR_DEFINED)
  97. ADD_EXECUTABLE(FunctionTest functionTest.c)