CMakeLists.txt 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # a simple C only test case
  2. cmake_minimum_required (VERSION 2.6)
  3. PROJECT (MacroTest)
  4. SET(CMAKE_C_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_C_FLAGS}")
  5. MACRO(FAILED testname)
  6. MESSAGE(SEND_ERROR "${testname} failed ${ARGN}")
  7. ENDMACRO(FAILED)
  8. MACRO(PASS testname)
  9. MESSAGE("${testname} passed ${ARGN}")
  10. ENDMACRO(PASS)
  11. # test ARGC
  12. MACRO(weird_name)
  13. IF("${ARGC}" EQUAL "3")
  14. PASS("ARGC")
  15. ELSE("${ARGC}" EQUAL "3")
  16. FAILED("ARGC" "Got: ${ARGC}")
  17. ENDIF("${ARGC}" EQUAL "3")
  18. ENDMACRO(weird_name)
  19. WeIrD_nAmE(a1 a2 a3)
  20. # test ARGN
  21. MACRO(test_argn_macro argument)
  22. IF("${ARGN}" EQUAL "3")
  23. PASS("ARGN")
  24. ELSE("${ARGN}" EQUAL "3")
  25. FAILED("ARGN" "Got: ${ARGN}")
  26. ENDIF("${ARGN}" EQUAL "3")
  27. ENDMACRO(test_argn_macro)
  28. Test_Argn_Macro(ignored 3)
  29. # case test
  30. MACRO(strange_macro m)
  31. SET("${m}" strange_macro)
  32. ENDMACRO(strange_macro m)
  33. STRANGE_MACRO(var)
  34. set(second_var "second_var")
  35. IF("${var}" STREQUAL "strange_macro" AND "${second_var}" STREQUAL "second_var")
  36. PASS("Case Test" "(${var} ${second_var})")
  37. ELSE("${var}" STREQUAL "strange_macro" AND "${second_var}" STREQUAL "second_var")
  38. FAILED("Case test" "(${var} ${second_var})")
  39. ENDIF("${var}" STREQUAL "strange_macro" AND "${second_var}" STREQUAL "second_var")
  40. # test backing up command
  41. MACRO(ADD_EXECUTABLE exec)
  42. _ADD_EXECUTABLE("mini${exec}" ${ARGN})
  43. ENDMACRO(ADD_EXECUTABLE)
  44. INCLUDE(CheckCSourceCompiles)
  45. Check_C_Source_Compiles(
  46. "
  47. #include <stdio.h>
  48. #ifdef __CLASSIC_C__
  49. int main(){
  50. int ac;
  51. char*av[];
  52. #else
  53. int main(int ac, char*av[]){
  54. #endif
  55. if(ac > 1000){return *av[0];}
  56. return 0;
  57. }"
  58. SOME_CHECK)
  59. IF(SOME_CHECK)
  60. MESSAGE("CheckCSourceCompiles works")
  61. ELSE(SOME_CHECK)
  62. MESSAGE(FATAL_ERROR "CheckCSourceCompiles does not work")
  63. ENDIF(SOME_CHECK)
  64. INCLUDE(CheckCXXSourceCompiles)
  65. Check_CXX_Source_Compiles(
  66. "
  67. #include <stdio.h>
  68. int main(int ac, char*av[]){
  69. if(ac > 1000){return *av[0];}
  70. return 0;
  71. }"
  72. SOME_CHECK)
  73. IF(SOME_CHECK)
  74. MESSAGE("CheckCXXSourceCompiles works")
  75. ELSE(SOME_CHECK)
  76. MESSAGE(FATAL_ERROR "CheckCXXSourceCompiles does not work")
  77. ENDIF(SOME_CHECK)
  78. ADD_EXECUTABLE(MacroTest macroTest.c)