CMakeLists.txt 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. remove_definitions(-DCMAKE_IS_REALLY_FUN)
  2. #
  3. # Small utility used to create file
  4. # UTILITY_SOURCE is used for coverage and for getting the exact name
  5. # of the executable.
  6. #
  7. utility_source(CREATE_FILE_EXE create_file "." create_file.cxx)
  8. add_executable(create_file create_file.cxx)
  9. set_target_properties(create_file PROPERTIES RUNTIME_OUTPUT_DIRECTORY ".")
  10. #
  11. # Create static library
  12. # SOURCE_FILES_REMOVE is used for Coverage. empty.h is included for coverage
  13. #
  14. aux_source_directory(ExtraSources LibrarySources)
  15. set(LibrarySources ${LibrarySources}
  16. file2
  17. empty
  18. create_file.cxx
  19. GENERATED
  20. nonexisting_file)
  21. remove(LibrarySources create_file.cxx GENERATED nonexisting_file)
  22. add_library(CMakeTestLibrary ${LibrarySources})
  23. if(WIN32 AND NOT CYGWIN AND NOT BORLAND AND NOT MINGW AND NOT CMAKE_C_COMPILER_ID STREQUAL "OrangeC")
  24. target_link_libraries(CMakeTestLibrary debug user32.lib)
  25. target_link_libraries(CMakeTestLibrary optimized kernel32.lib)
  26. endif()
  27. #
  28. # Create shared library
  29. #
  30. set(SharedLibrarySources sharedFile)
  31. add_library(CMakeTestLibraryShared SHARED ${SharedLibrarySources})
  32. string(APPEND CMAKE_C_FLAGS " -DTEST_C_FLAGS")
  33. add_library(CMakeTestCLibraryShared SHARED testConly.c)
  34. define_property(
  35. TARGET PROPERTY FOO
  36. BRIEF_DOCS "a test property"
  37. FULL_DOCS "A simple test property that means nothing and is used for nothing"
  38. )
  39. set_target_properties(CMakeTestCLibraryShared PROPERTIES FOO BAR)
  40. if(NOT BEOS AND NOT WIN32 AND NOT HAIKU) # No libm on BeOS.
  41. set_target_properties(CMakeTestCLibraryShared PROPERTIES LINK_FLAGS "-lm")
  42. endif()
  43. get_target_property(FOO_BAR_VAR CMakeTestCLibraryShared FOO)
  44. if(${FOO_BAR_VAR} MATCHES "BAR")
  45. else()
  46. message(SEND_ERROR "SET_TARGET_PROPERTIES or GET_TARGET_PROPERTY failed, FOO_BAR_VAR should be BAR, but is ${FOO_BAR_VAR}")
  47. endif()
  48. # Create static and shared lib of same name.
  49. if(CMAKE_EXE_LINK_STATIC_CXX_FLAGS)
  50. add_library(CMakeTestLinkStatic STATIC TestLink.c)
  51. add_library(CMakeTestLinkShared SHARED TestLink.c)
  52. set_target_properties(CMakeTestLinkStatic CMakeTestLinkShared
  53. PROPERTIES OUTPUT_NAME CMakeTestLink)
  54. endif()
  55. #
  56. # Attach pre-build/pre-link/post-build custom-commands to the lib.
  57. # Each runs ${CREATE_FILE_EXE} which will create a file.
  58. # The 'complex' executable will then test if this file exists and remove it.
  59. #
  60. add_dependencies(CMakeTestLibraryShared create_file)
  61. message("complex bin dir is ${Complex_BINARY_DIR}")
  62. add_custom_command(TARGET CMakeTestLibraryShared PRE_BUILD
  63. COMMAND ${CREATE_FILE_EXE}
  64. ARGS "${Complex_BINARY_DIR}/Library/prebuild.txt")
  65. add_custom_command(TARGET CMakeTestLibraryShared PRE_BUILD
  66. COMMAND ${CREATE_FILE_EXE}
  67. ARGS "${Complex_BINARY_DIR}/Library/prelink.txt")
  68. add_custom_command(TARGET CMakeTestLibraryShared POST_BUILD
  69. COMMAND ${CREATE_FILE_EXE}
  70. ARGS "${Complex_BINARY_DIR}/Library/postbuild.txt")
  71. add_custom_command(TARGET CMakeTestLibraryShared POST_BUILD
  72. COMMAND ${CMAKE_COMMAND}
  73. ARGS -E copy
  74. "${Complex_BINARY_DIR}/Library/postbuild.txt"
  75. "${Complex_BINARY_DIR}/Library/postbuild2.txt")
  76. #
  77. # Add a custom target.
  78. # It runs ${CREATE_FILE_EXE} which will create a file.
  79. # The 'complex' executable will then test if this file exists and remove it.
  80. #
  81. add_custom_target(custom_target1
  82. ALL
  83. ${CREATE_FILE_EXE}
  84. "${Complex_BINARY_DIR}/Library/custom_target1.txt")
  85. add_dependencies(custom_target1 create_file)
  86. #
  87. # Extra coverage
  88. #
  89. set_source_files_properties(file2 PROPERTIES ABSTRACT 1)
  90. install_files(/tmp .h ${Complex_BINARY_DIR}/cmTestConfigure.h)
  91. install_files(/tmp .cxx ${Complex_BINARY_DIR}/cmTestConfigure.h)
  92. # Test creating a library that is not built by default.
  93. add_library(notInAllLib EXCLUDE_FROM_ALL notInAllLib.cxx)
  94. # Create an imported target for if(TARGET) test in Executable dir.
  95. # That test should not see this target.
  96. add_library(LibImportedTarget UNKNOWN IMPORTED)
  97. # Test generation of preprocessed sources.
  98. if("${CMAKE_GENERATOR}" MATCHES "Makefile" AND CMAKE_MAKE_PROGRAM)
  99. if(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE)
  100. # Skip running this part of the test on certain platforms
  101. # until they are fixed.
  102. set(MAYBE_ALL ALL)
  103. list(LENGTH CMAKE_OSX_ARCHITECTURES ARCH_COUNT)
  104. if(ARCH_COUNT GREATER 1)
  105. # OSX does not support preprocessing more than one architecture.
  106. set(MAYBE_ALL)
  107. endif()
  108. # Custom target to try preprocessing invocation.
  109. add_custom_target(test_preprocess ${MAYBE_ALL}
  110. COMMAND ${CMAKE_COMMAND} -E rm -f CMakeFiles/create_file.dir/create_file.i
  111. COMMAND ${CMAKE_MAKE_PROGRAM} create_file.i
  112. COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/test_preprocess.cmake
  113. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  114. )
  115. endif()
  116. endif()