CMakeLists.txt 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. # a simple CXX only test case
  2. cmake_minimum_required (VERSION 2.6)
  3. project (Properties)
  4. # these first three tests really test both properties and the management of
  5. # cmSourceFile objects by CMake.
  6. # test properties on a build tree file that is relative (yuck)
  7. configure_file(properties.h.in "${Properties_BINARY_DIR}/properties.h")
  8. set_source_files_properties(properties.h PROPERTIES TEST1 1)
  9. get_source_file_property(RESULT1 properties.h TEST1)
  10. # test properties on a headerfile in the source tree
  11. # accessed without an extenion (also yuck)
  12. set_source_files_properties(properties2 PROPERTIES TEST2 1)
  13. get_source_file_property(RESULT2 properties2 TEST2)
  14. # test properties on a relative source that is not generated
  15. set_source_files_properties(SubDir/properties3.cxx PROPERTIES TEST3 1)
  16. get_source_file_property(RESULT3 SubDir/properties3.cxx TEST3)
  17. include_directories("${Properties_SOURCE_DIR}" "${Properties_BINARY_DIR}")
  18. # test generic property interfaces
  19. get_property(GLOBALRESULT GLOBAL PROPERTY GLOBALTEST DEFINED)
  20. if (GLOBALRESULT)
  21. message(SEND_ERROR "Error: global prop defined when it should not be, "
  22. "result is GLOBALRESULT=${GLOBALRESULT}")
  23. endif (GLOBALRESULT)
  24. define_property(GLOBAL PROPERTY GLOBALTEST
  25. BRIEF_DOCS "A test property"
  26. FULL_DOCS "A long description of this test property"
  27. )
  28. get_property(GLOBALRESULT GLOBAL PROPERTY GLOBALTEST DEFINED)
  29. if (NOT GLOBALRESULT)
  30. message(SEND_ERROR "Error: global prop not defined "
  31. "result is GLOBALRESULT=${GLOBALRESULT}")
  32. endif (NOT GLOBALRESULT)
  33. set_property(GLOBAL PROPERTY GLOBALTEST 1)
  34. set_property(DIRECTORY PROPERTY DIRECTORYTEST 1)
  35. set_property(SOURCE SubDir/properties3.cxx PROPERTY SOURCETEST 1)
  36. get_property(GLOBALRESULT GLOBAL PROPERTY GLOBALTEST)
  37. get_property(DIRECTORYRESULT DIRECTORY PROPERTY DIRECTORYTEST)
  38. get_property(SOURCERESULT
  39. SOURCE SubDir/properties3.cxx
  40. PROPERTY SOURCETEST
  41. )
  42. if (RESULT1 AND RESULT2 AND RESULT3 AND GLOBALRESULT AND
  43. DIRECTORYRESULT AND SOURCERESULT)
  44. add_executable (Properties SubDir/properties3.cxx properties)
  45. else (RESULT1 AND RESULT2 AND RESULT3 AND GLOBALRESULT AND
  46. DIRECTORYRESULT AND SOURCERESULT)
  47. message(SEND_ERROR
  48. "Error: test results are RESULT1=${RESULT1} RESULT2=${RESULT2} "
  49. "RESULT3=${RESULT3} GLOBALRESULT=${GLOBALRESULT} "
  50. "DIRECTORYRESULT=${DIRECTORYRESULT} "
  51. "SOURCERESULT=${SOURCERESULT}")
  52. endif (RESULT1 AND RESULT2 AND RESULT3 AND GLOBALRESULT AND
  53. DIRECTORYRESULT AND SOURCERESULT)
  54. # test the target property
  55. set_property(TARGET Properties PROPERTY TARGETTEST 1)
  56. get_property(TARGETRESULT TARGET Properties PROPERTY TARGETTEST)
  57. if (NOT TARGETRESULT)
  58. message(SEND_ERROR
  59. "Error: target result is TARGETRESULT=${TARGETRESULT}")
  60. endif (NOT TARGETRESULT)
  61. # test get_property SET
  62. get_property(TARGETRESULT TARGET Properties PROPERTY TARGETTEST SET)
  63. if (NOT TARGETRESULT)
  64. message(SEND_ERROR
  65. "Error: target prop not set, result is TARGETRESULT=${TARGETRESULT}")
  66. endif (NOT TARGETRESULT)
  67. # test unsetting a property
  68. set_property(TARGET Properties PROPERTY TARGETTEST)
  69. get_property(TARGETRESULT TARGET Properties PROPERTY TARGETTEST SET)
  70. if (TARGETRESULT)
  71. message(SEND_ERROR "Error: target prop not unset, "
  72. "result is TARGETRESULT=${TARGETRESULT}")
  73. endif (TARGETRESULT)
  74. # test the target SOURCES property
  75. get_property(Properties_SOURCES TARGET Properties PROPERTY SOURCES)
  76. set_source_files_properties(${Properties_SOURCES} PROPERTIES TEST4 1)
  77. get_source_file_property(RESULT4 properties.h TEST4)
  78. if(NOT RESULT4)
  79. message(SEND_ERROR "Error: target result is"
  80. " RESULT4=${RESULT4}"
  81. " Properties_SOURCES=[${Properties_SOURCES}]")
  82. endif(NOT RESULT4)
  83. # test CACHE properties
  84. macro(check_cache_props)
  85. foreach(prop VALUE TYPE HELPSTRING ADVANCED)
  86. get_property(result CACHE SOME_ENTRY PROPERTY ${prop})
  87. if(NOT "x${result}" STREQUAL "x${expect_${prop}}")
  88. message(SEND_ERROR "CACHE property ${prop} is [${result}], not [${expect_${prop}}]")
  89. endif()
  90. endforeach(prop)
  91. endmacro(check_cache_props)
  92. set(expect_VALUE "ON")
  93. set(expect_TYPE "BOOL")
  94. set(expect_HELPSTRING "sample cache entry")
  95. set(expect_ADVANCED 0)
  96. set(SOME_ENTRY "${expect_VALUE}" CACHE ${expect_TYPE} "${expect_HELPSTRING}" FORCE)
  97. mark_as_advanced(CLEAR SOME_ENTRY)
  98. check_cache_props()
  99. set(expect_VALUE "Some string")
  100. set(expect_TYPE "STRING")
  101. set(expect_HELPSTRING "sample cache entry help")
  102. set(expect_ADVANCED 1)
  103. set_property(CACHE SOME_ENTRY PROPERTY TYPE "${expect_TYPE}")
  104. set_property(CACHE SOME_ENTRY PROPERTY HELPSTRING "${expect_HELPSTRING}")
  105. set_property(CACHE SOME_ENTRY PROPERTY VALUE "${expect_VALUE}")
  106. set_property(CACHE SOME_ENTRY PROPERTY ADVANCED "${expect_ADVANCED}")
  107. check_cache_props()