CMakeLists.txt 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. #
  10. # Create static library
  11. # SOURCE_FILES_REMOVE is used for Coverage. empty.h is included for coverage
  12. #
  13. AUX_SOURCE_DIRECTORY(ExtraSources LibrarySources)
  14. SOURCE_FILES(LibrarySources
  15. file2
  16. empty
  17. create_file.cxx
  18. GENERATED
  19. nonexisting_file)
  20. SOURCE_FILES_REMOVE(LibrarySources create_file.cxx GENERATED nonexisting_file)
  21. ADD_LIBRARY(CMakeTestLibrary ${LibrarySources})
  22. IF(WIN32)
  23. IF(NOT CYGWIN)
  24. IF(NOT BORLAND)
  25. IF(NOT MINGW)
  26. TARGET_LINK_LIBRARIES(CMakeTestLibrary
  27. debug
  28. user32.lib)
  29. TARGET_LINK_LIBRARIES(CMakeTestLibrary
  30. optimized
  31. kernel32.lib)
  32. ENDIF(NOT MINGW)
  33. ENDIF(NOT BORLAND)
  34. ENDIF(NOT CYGWIN)
  35. ENDIF(WIN32)
  36. #
  37. # Create shared library
  38. #
  39. SOURCE_FILES(SharedLibrarySources sharedFile)
  40. ADD_LIBRARY(CMakeTestLibraryShared SHARED ${SharedLibrarySources})
  41. ADD_LIBRARY(CMakeTestModule MODULE moduleFile.c)
  42. SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST_C_FLAGS")
  43. ADD_LIBRARY(CMakeTestCLibraryShared SHARED testConly.c)
  44. SET_TARGET_PROPERTIES(CMakeTestCLibraryShared PROPERTIES FOO BAR)
  45. SET_TARGET_PROPERTIES(CMakeTestCLibraryShared PROPERTIES LINK_FLAGS "-lm")
  46. GET_TARGET_PROPERTY(FOO_BAR_VAR CMakeTestCLibraryShared FOO)
  47. IF(${FOO_BAR_VAR} MATCHES "BAR")
  48. ELSE(${FOO_BAR_VAR} MATCHES "BAR")
  49. MESSAGE(SEND_ERROR "SET_TARGET_PROPERTIES or GET_TARGET_PROPERTY failed, FOO_BAR_VAR should be BAR, but is ${FOO_BAR_VAR}")
  50. ENDIF(${FOO_BAR_VAR} MATCHES "BAR")
  51. #
  52. # Attach pre-build/pre-link/post-build custom-commands to the lib.
  53. # Each runs ${CREATE_FILE_EXE} which will create a file.
  54. # The 'complex' executable will then test if this file exists and remove it.
  55. #
  56. ADD_DEPENDENCIES(CMakeTestLibraryShared create_file)
  57. MESSAGE("complex bin dir is ${Complex_BINARY_DIR}")
  58. ADD_CUSTOM_COMMAND(TARGET CMakeTestLibraryShared PRE_BUILD
  59. COMMAND ${CREATE_FILE_EXE}
  60. ARGS "${Complex_BINARY_DIR}/Library/prebuild.txt")
  61. ADD_CUSTOM_COMMAND(TARGET CMakeTestLibraryShared PRE_BUILD
  62. COMMAND ${CREATE_FILE_EXE}
  63. ARGS "${Complex_BINARY_DIR}/Library/prelink.txt")
  64. ADD_CUSTOM_COMMAND(TARGET CMakeTestLibraryShared POST_BUILD
  65. COMMAND ${CREATE_FILE_EXE}
  66. ARGS "${Complex_BINARY_DIR}/Library/postbuild.txt")
  67. ADD_CUSTOM_COMMAND(TARGET CMakeTestLibraryShared POST_BUILD
  68. COMMAND ${CMAKE_COMMAND}
  69. ARGS -E copy
  70. "${Complex_BINARY_DIR}/Library/postbuild.txt"
  71. "${Complex_BINARY_DIR}/Library/postbuild2.txt")
  72. #
  73. # Add a custom target.
  74. # It runs ${CREATE_FILE_EXE} which will create a file.
  75. # The 'complex' executable will then test if this file exists and remove it.
  76. #
  77. ADD_CUSTOM_TARGET(custom_target1
  78. ALL
  79. ${CREATE_FILE_EXE}
  80. "${Complex_BINARY_DIR}/Library/custom_target1.txt")
  81. ADD_DEPENDENCIES(custom_target1 create_file)
  82. #
  83. # Extra coverage
  84. #
  85. ABSTRACT_FILES(
  86. file2
  87. )
  88. INSTALL_FILES(/tmp .h ${Complex_BINARY_DIR}/cmTestConfigure.h)
  89. INSTALL_FILES(/tmp .cxx ${Complex_BINARY_DIR}/cmTestConfigure.h)