CMakeLists.txt 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. cmake_minimum_required (VERSION 2.7.20090711)
  2. project(ExportImport C CXX)
  3. if(NOT DEFINED CMAKE_TEST_MAKEPROGRAM AND NOT CMAKE_GENERATOR MATCHES "Visual Studio")
  4. set(CMAKE_TEST_MAKEPROGRAM "${CMAKE_MAKE_PROGRAM}")
  5. endif()
  6. # Wipe out the install tree to make sure the exporter works.
  7. add_custom_command(
  8. OUTPUT ${ExportImport_BINARY_DIR}/CleanupProject
  9. COMMAND ${CMAKE_COMMAND} -E remove_directory ${ExportImport_BINARY_DIR}/Root
  10. )
  11. add_custom_target(CleanupTarget ALL DEPENDS ${ExportImport_BINARY_DIR}/CleanupProject)
  12. set_property(
  13. SOURCE ${ExportImport_BINARY_DIR}/CleanupProject
  14. PROPERTY SYMBOLIC 1
  15. )
  16. if(CMAKE_CONFIGURATION_TYPES)
  17. set(NESTED_CONFIG_TYPE -C "${CMAKE_CFG_INTDIR}")
  18. else()
  19. if(CMAKE_BUILD_TYPE)
  20. set(NESTED_CONFIG_TYPE -C "${CMAKE_BUILD_TYPE}")
  21. else()
  22. set(NESTED_CONFIG_TYPE)
  23. endif()
  24. endif()
  25. if(MINGW OR MSYS)
  26. # Test CMAKE_GNUtoMS whether we have VS or not.
  27. set(ExportImport_GNUtoMS 1)
  28. endif()
  29. configure_file(${ExportImport_SOURCE_DIR}/InitialCache.cmake.in
  30. ${ExportImport_BINARY_DIR}/InitialCache.cmake @ONLY)
  31. # Build and install the exporter.
  32. add_custom_command(
  33. OUTPUT ${ExportImport_BINARY_DIR}/ExportProject
  34. COMMAND ${CMAKE_CTEST_COMMAND} ${NESTED_CONFIG_TYPE}
  35. --build-and-test
  36. ${ExportImport_SOURCE_DIR}/Export
  37. ${ExportImport_BINARY_DIR}/Export
  38. --build-noclean
  39. --build-project Export
  40. --build-target install
  41. --build-generator ${CMAKE_GENERATOR}
  42. --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}"
  43. --build-options -C${ExportImport_BINARY_DIR}/InitialCache.cmake
  44. VERBATIM
  45. )
  46. add_custom_target(ExportTarget ALL DEPENDS ${ExportImport_BINARY_DIR}/ExportProject)
  47. add_dependencies(ExportTarget CleanupTarget)
  48. set_property(
  49. SOURCE ${ExportImport_BINARY_DIR}/ExportProject
  50. PROPERTY SYMBOLIC 1
  51. )
  52. # Build and install the importer.
  53. add_custom_command(
  54. OUTPUT ${ExportImport_BINARY_DIR}/ImportProject
  55. COMMAND ${CMAKE_CTEST_COMMAND} ${NESTED_CONFIG_TYPE}
  56. --build-and-test
  57. ${ExportImport_SOURCE_DIR}/Import
  58. ${ExportImport_BINARY_DIR}/Import
  59. --build-noclean
  60. --build-project Import
  61. --build-generator ${CMAKE_GENERATOR}
  62. --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}"
  63. --build-options -C${ExportImport_BINARY_DIR}/InitialCache.cmake
  64. VERBATIM
  65. )
  66. add_custom_target(ImportTarget ALL DEPENDS ${ExportImport_BINARY_DIR}/ImportProject)
  67. add_dependencies(ImportTarget ExportTarget)
  68. set_property(
  69. SOURCE ${ExportImport_BINARY_DIR}/ImportProject
  70. PROPERTY SYMBOLIC 1
  71. )
  72. add_executable(ExportImport main.c)
  73. add_dependencies(ExportImport ImportTarget)