CMakeLists.txt 2.9 KB

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