CMakeLists.txt 4.9 KB

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