CMakeLists.txt 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 extension (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 ()
  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 ()
  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 ()
  46. message(SEND_ERROR
  47. "Error: test results are RESULT1=${RESULT1} RESULT2=${RESULT2} "
  48. "RESULT3=${RESULT3} GLOBALRESULT=${GLOBALRESULT} "
  49. "DIRECTORYRESULT=${DIRECTORYRESULT} "
  50. "SOURCERESULT=${SOURCERESULT}")
  51. endif ()
  52. # test the target property
  53. set_property(TARGET Properties PROPERTY TARGETTEST 1)
  54. get_property(TARGETRESULT TARGET Properties PROPERTY TARGETTEST)
  55. if (NOT TARGETRESULT)
  56. message(SEND_ERROR
  57. "Error: target result is TARGETRESULT=${TARGETRESULT}")
  58. endif ()
  59. # test APPEND and APPEND_STRING set_property()
  60. set_property(TARGET Properties PROPERTY FOO foo)
  61. set_property(TARGET Properties PROPERTY BAR bar)
  62. set_property(TARGET Properties APPEND PROPERTY FOO 123)
  63. set_property(TARGET Properties APPEND_STRING PROPERTY BAR 456)
  64. get_property(APPEND_RESULT TARGET Properties PROPERTY FOO)
  65. if (NOT "${APPEND_RESULT}" STREQUAL "foo;123")
  66. message(SEND_ERROR
  67. "Error: target result is APPEND_RESULT=${APPEND_RESULT}")
  68. endif ()
  69. get_property(APPEND_STRING_RESULT TARGET Properties PROPERTY BAR)
  70. if (NOT "${APPEND_STRING_RESULT}" STREQUAL "bar456")
  71. message(SEND_ERROR
  72. "Error: target result is APPEND_STRING_RESULT=${APPEND_STRING_RESULT}")
  73. endif ()
  74. # test get_property SET
  75. get_property(TARGETRESULT TARGET Properties PROPERTY TARGETTEST SET)
  76. if (NOT TARGETRESULT)
  77. message(SEND_ERROR
  78. "Error: target prop not set, result is TARGETRESULT=${TARGETRESULT}")
  79. endif ()
  80. # test unsetting a property
  81. set_property(TARGET Properties PROPERTY TARGETTEST)
  82. get_property(TARGETRESULT TARGET Properties PROPERTY TARGETTEST SET)
  83. if (TARGETRESULT)
  84. message(SEND_ERROR "Error: target prop not unset, "
  85. "result is TARGETRESULT=${TARGETRESULT}")
  86. endif ()
  87. # test the target SOURCES property
  88. get_property(Properties_SOURCES TARGET Properties PROPERTY SOURCES)
  89. set_source_files_properties(${Properties_SOURCES} PROPERTIES TEST4 1)
  90. get_source_file_property(RESULT4 properties.h TEST4)
  91. if(NOT RESULT4)
  92. message(SEND_ERROR "Error: target result is"
  93. " RESULT4=${RESULT4}"
  94. " Properties_SOURCES=[${Properties_SOURCES}]")
  95. endif()
  96. # test CACHE properties
  97. macro(check_cache_props)
  98. foreach(prop VALUE TYPE HELPSTRING ADVANCED STRINGS)
  99. get_property(result CACHE SOME_ENTRY PROPERTY ${prop})
  100. if(NOT "x${result}" STREQUAL "x${expect_${prop}}")
  101. message(SEND_ERROR "CACHE property ${prop} is [${result}], not [${expect_${prop}}]")
  102. endif()
  103. endforeach()
  104. endmacro()
  105. set(expect_VALUE "ON")
  106. set(expect_TYPE "BOOL")
  107. set(expect_HELPSTRING "sample cache entry")
  108. set(expect_ADVANCED 0)
  109. set(expect_STRINGS "")
  110. set(SOME_ENTRY "${expect_VALUE}" CACHE ${expect_TYPE} "${expect_HELPSTRING}" FORCE)
  111. mark_as_advanced(CLEAR SOME_ENTRY)
  112. set_property(CACHE SOME_ENTRY PROPERTY STRINGS "")
  113. check_cache_props()
  114. set(expect_VALUE "Some string")
  115. set(expect_TYPE "STRING")
  116. set(expect_HELPSTRING "sample cache entry help")
  117. set(expect_ADVANCED 1)
  118. set(expect_STRINGS "Some string;Some other string;Some third string")
  119. set_property(CACHE SOME_ENTRY PROPERTY TYPE "${expect_TYPE}")
  120. set_property(CACHE SOME_ENTRY PROPERTY HELPSTRING "${expect_HELPSTRING}")
  121. set_property(CACHE SOME_ENTRY PROPERTY VALUE "${expect_VALUE}")
  122. set_property(CACHE SOME_ENTRY PROPERTY ADVANCED "${expect_ADVANCED}")
  123. set_property(CACHE SOME_ENTRY PROPERTY STRINGS "${expect_STRINGS}")
  124. check_cache_props()
  125. add_subdirectory(SubDir2)