CMakeLists.txt 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. TARGET_LINK_LIBRARIES(CMakeTestLibrary
  25. debug
  26. user32.lib)
  27. TARGET_LINK_LIBRARIES(CMakeTestLibrary
  28. optimized
  29. kernel32.lib)
  30. ENDIF(NOT BORLAND)
  31. ENDIF(NOT CYGWIN)
  32. ENDIF(WIN32)
  33. #
  34. # Create shared library
  35. #
  36. SOURCE_FILES(SharedLibrarySources sharedFile)
  37. ADD_LIBRARY(CMakeTestLibraryShared SHARED ${SharedLibrarySources})
  38. ADD_LIBRARY(CMakeTestModule MODULE moduleFile.c)
  39. SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST_C_FLAGS")
  40. ADD_LIBRARY(CMakeTestCLibraryShared SHARED testConly.c)
  41. SET_TARGET_PROPERTIES(CMakeTestCLibraryShared PROPERTIES FOO BAR)
  42. SET_TARGET_PROPERTIES(CMakeTestCLibraryShared PROPERTIES LINK_FLAGS "-lm")
  43. GET_TARGET_PROPERTY(FOO_BAR_VAR CMakeTestCLibraryShared FOO)
  44. IF(${FOO_BAR_VAR} MATCHES "BAR")
  45. ELSE(${FOO_BAR_VAR} MATCHES "BAR")
  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(${FOO_BAR_VAR} MATCHES "BAR")
  48. #
  49. # Attach a post-build custom-command to the lib.
  50. # It runs ${CREATE_FILE_EXE} which will create a file.
  51. # The 'complex' executable will then test if this file exists and remove it.
  52. #
  53. ADD_DEPENDENCIES(CMakeTestLibraryShared create_file)
  54. MESSAGE("complex bin dir is ${Complex_BINARY_DIR}")
  55. ADD_CUSTOM_COMMAND(COMMAND ${CREATE_FILE_EXE}
  56. ARGS "${Complex_BINARY_DIR}/Library/postbuild.txt"
  57. TARGET CMakeTestLibraryShared)
  58. ADD_CUSTOM_COMMAND(COMMAND ${CMAKE_COMMAND}
  59. ARGS -E copy
  60. "${Complex_BINARY_DIR}/Library/postbuild.txt"
  61. "${Complex_BINARY_DIR}/Library/postbuild2.txt"
  62. TARGET CMakeTestLibraryShared)
  63. #
  64. # Add a custom target.
  65. # It runs ${CREATE_FILE_EXE} which will create a file.
  66. # The 'complex' executable will then test if this file exists and remove it.
  67. #
  68. ADD_CUSTOM_TARGET(custom_target1
  69. ALL
  70. ${CREATE_FILE_EXE}
  71. "${Complex_BINARY_DIR}/Library/custom_target1.txt")
  72. ADD_DEPENDENCIES(custom_target1 create_file)
  73. #
  74. # Extra coverage
  75. #
  76. ABSTRACT_FILES(
  77. file2
  78. )
  79. INSTALL_FILES(/tmp .h ${Complex_BINARY_DIR}/cmTestConfigure.h)
  80. INSTALL_FILES(/tmp .cxx ${Complex_BINARY_DIR}/cmTestConfigure.h)