CMakeLists.txt 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # This CMakeLists.txt file exists solely to drive the one found in the "src"
  2. # subdir as an ExternalProject build. The project in "src" cannot build when
  3. # there is a space in the directory name, so we copy that directory to a place
  4. # guaranteed not to have a space in the name, build it there, and then copy the
  5. # resulting output directory back up here into this CMake test's build tree.
  6. #
  7. if(NOT DEFINED CMAKE_BUILDNAME)
  8. string(REGEX REPLACE "^.*/([^/]+)/[^/]+/([^/]+)$" "\\1" CMAKE_BUILDNAME "${CMAKE_CURRENT_BINARY_DIR}")
  9. string(REGEX REPLACE "^.*/([^/]+)/[^/]+/([^/]+)$" "\\2" THIS_TESTNAME "${CMAKE_CURRENT_BINARY_DIR}")
  10. string(REPLACE " " "_" CMAKE_BUILDNAME "${CMAKE_BUILDNAME}")
  11. endif()
  12. message(STATUS "CMAKE_BUILDNAME='${CMAKE_BUILDNAME}'")
  13. message(STATUS "THIS_TESTNAME='${THIS_TESTNAME}'")
  14. cmake_minimum_required(VERSION 2.8)
  15. project(${THIS_TESTNAME})
  16. include(ExternalProject)
  17. if(NOT DEFINED HOME)
  18. if(DEFINED ENV{CTEST_REAL_HOME})
  19. set(HOME "$ENV{CTEST_REAL_HOME}")
  20. else()
  21. set(HOME "$ENV{HOME}")
  22. endif()
  23. if(NOT HOME AND WIN32)
  24. # Try for USERPROFILE as HOME equivalent:
  25. string(REPLACE "\\" "/" HOME "$ENV{USERPROFILE}")
  26. endif()
  27. # But just use root of SystemDrive if HOME contains any spaces:
  28. # (Default on XP and earlier...)
  29. if(HOME MATCHES " " AND WIN32)
  30. string(REPLACE "\\" "/" HOME "$ENV{SystemDrive}")
  31. endif()
  32. if(HOME MATCHES " ")
  33. set(HOME "")
  34. endif()
  35. endif()
  36. message(STATUS "HOME='${HOME}'")
  37. if(NOT DEFINED url)
  38. set(url "${CMAKE_CURRENT_SOURCE_DIR}/src")
  39. endif()
  40. message(STATUS "url='${url}'")
  41. set(base_dir "${HOME}/.cmake/Dashboards/${CMAKE_BUILDNAME}/${THIS_TESTNAME}")
  42. set(binary_dir "${base_dir}/build")
  43. set(source_dir "${base_dir}/src")
  44. # Source dir for this project exists in the CMake source tree, but we cannot
  45. # use it in-place since there might be a space in its directory name.
  46. # Source dir is therefore copied under a '.cmake/Dashboards'
  47. # dir in your HOME directory to give it a name with no spaces.
  48. #
  49. ExternalProject_Add(clean-${PROJECT_NAME}
  50. DOWNLOAD_COMMAND ""
  51. CONFIGURE_COMMAND ${CMAKE_COMMAND} -E remove_directory "${source_dir}"
  52. BUILD_COMMAND ${CMAKE_COMMAND} -E remove_directory "${binary_dir}"
  53. INSTALL_COMMAND ""
  54. )
  55. ExternalProject_Add(download-${PROJECT_NAME}
  56. URL "${url}"
  57. SOURCE_DIR "${source_dir}"
  58. CONFIGURE_COMMAND ""
  59. BUILD_COMMAND ""
  60. INSTALL_COMMAND ""
  61. DEPENDS clean-${PROJECT_NAME}
  62. )
  63. ExternalProject_Add(build-${PROJECT_NAME}
  64. DOWNLOAD_COMMAND ""
  65. SOURCE_DIR "${source_dir}"
  66. BINARY_DIR "${binary_dir}"
  67. INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory
  68. "${binary_dir}/${CMAKE_CFG_INTDIR}"
  69. "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}"
  70. DEPENDS download-${PROJECT_NAME}
  71. )