CMakeLists.txt 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. cmake_minimum_required (VERSION 2.7.20090711)
  2. project(ExportImport C CXX)
  3. if(NOT DEFINED CMake_TEST_NESTED_MAKE_PROGRAM AND NOT CMAKE_GENERATOR MATCHES "Visual Studio")
  4. set(CMake_TEST_NESTED_MAKE_PROGRAM "${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-platform "${CMAKE_GENERATOR_PLATFORM}"
  43. --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}"
  44. --build-options -C${ExportImport_BINARY_DIR}/InitialCache.cmake
  45. VERBATIM
  46. )
  47. add_custom_target(ExportTarget ALL DEPENDS ${ExportImport_BINARY_DIR}/ExportProject)
  48. add_dependencies(ExportTarget CleanupTarget)
  49. set_property(
  50. SOURCE ${ExportImport_BINARY_DIR}/ExportProject
  51. PROPERTY SYMBOLIC 1
  52. )
  53. # Build and install the importer.
  54. add_custom_command(
  55. OUTPUT ${ExportImport_BINARY_DIR}/ImportProject
  56. COMMAND ${CMAKE_CTEST_COMMAND} ${NESTED_CONFIG_TYPE}
  57. --build-and-test
  58. ${ExportImport_SOURCE_DIR}/Import
  59. ${ExportImport_BINARY_DIR}/Import
  60. --build-noclean
  61. --build-project Import
  62. --build-generator ${CMAKE_GENERATOR}
  63. --build-generator-platform "${CMAKE_GENERATOR_PLATFORM}"
  64. --build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}"
  65. --build-options -C${ExportImport_BINARY_DIR}/InitialCache.cmake
  66. VERBATIM
  67. )
  68. add_custom_target(ImportTarget ALL DEPENDS ${ExportImport_BINARY_DIR}/ImportProject)
  69. add_dependencies(ImportTarget ExportTarget)
  70. set_property(
  71. SOURCE ${ExportImport_BINARY_DIR}/ImportProject
  72. PROPERTY SYMBOLIC 1
  73. )
  74. add_executable(ExportImport main.c)
  75. add_dependencies(ExportImport ImportTarget)