CMakeLists.txt 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 a post-build custom-command to the lib.
  53. # It 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(COMMAND ${CREATE_FILE_EXE}
  59. ARGS "${Complex_BINARY_DIR}/Library/postbuild.txt"
  60. TARGET CMakeTestLibraryShared)
  61. ADD_CUSTOM_COMMAND(COMMAND ${CMAKE_COMMAND}
  62. ARGS -E copy
  63. "${Complex_BINARY_DIR}/Library/postbuild.txt"
  64. "${Complex_BINARY_DIR}/Library/postbuild2.txt"
  65. TARGET CMakeTestLibraryShared)
  66. #
  67. # Add a custom target.
  68. # It runs ${CREATE_FILE_EXE} which will create a file.
  69. # The 'complex' executable will then test if this file exists and remove it.
  70. #
  71. ADD_CUSTOM_TARGET(custom_target1
  72. ALL
  73. ${CREATE_FILE_EXE}
  74. "${Complex_BINARY_DIR}/Library/custom_target1.txt")
  75. ADD_DEPENDENCIES(custom_target1 create_file)
  76. #
  77. # Extra coverage
  78. #
  79. ABSTRACT_FILES(
  80. file2
  81. )
  82. INSTALL_FILES(/tmp .h ${Complex_BINARY_DIR}/cmTestConfigure.h)
  83. INSTALL_FILES(/tmp .cxx ${Complex_BINARY_DIR}/cmTestConfigure.h)