CMakeLists.txt 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. # But just use root of SystemDrive if USERPROFILE contains any spaces:
  27. # (Default on XP and earlier...)
  28. if(HOME MATCHES " ")
  29. string(REPLACE "\\" "/" HOME "$ENV{SystemDrive}")
  30. endif()
  31. endif()
  32. endif()
  33. message(STATUS "HOME='${HOME}'")
  34. if(NOT DEFINED url)
  35. set(url "${CMAKE_CURRENT_SOURCE_DIR}/src")
  36. endif()
  37. message(STATUS "url='${url}'")
  38. set(base_dir "${HOME}/.cmake/Dashboards/${CMAKE_BUILDNAME}/${THIS_TESTNAME}")
  39. set(binary_dir "${base_dir}/build")
  40. set(source_dir "${base_dir}/src")
  41. # Source dir for this project exists in the CMake source tree, but we cannot
  42. # use it in-place since there might be a space in its directory name.
  43. # Source dir is therefore copied under a '.cmake/Dashboards'
  44. # dir in your HOME directory to give it a name with no spaces.
  45. #
  46. ExternalProject_Add(clean-${PROJECT_NAME}
  47. DOWNLOAD_COMMAND ""
  48. CONFIGURE_COMMAND ${CMAKE_COMMAND} -E remove_directory "${source_dir}"
  49. BUILD_COMMAND ${CMAKE_COMMAND} -E remove_directory "${binary_dir}"
  50. INSTALL_COMMAND ""
  51. )
  52. ExternalProject_Add(download-${PROJECT_NAME}
  53. URL "${url}"
  54. SOURCE_DIR "${source_dir}"
  55. CONFIGURE_COMMAND ""
  56. BUILD_COMMAND ""
  57. INSTALL_COMMAND ""
  58. DEPENDS clean-${PROJECT_NAME}
  59. )
  60. ExternalProject_Add(build-${PROJECT_NAME}
  61. DOWNLOAD_COMMAND ""
  62. SOURCE_DIR "${source_dir}"
  63. BINARY_DIR "${binary_dir}"
  64. INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory
  65. "${binary_dir}/${CMAKE_CFG_INTDIR}"
  66. "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}"
  67. DEPENDS download-${PROJECT_NAME}
  68. )