TZIVI-254: IVI needs a newer version of cmake
[profile/ivi/cmake.git] / Tests / Contracts / cse-snapshot / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.8)
2 project(cse-snapshot)
3
4 include(ExternalProject)
5
6 include("${CMAKE_CURRENT_SOURCE_DIR}/LocalOverrides.cmake" OPTIONAL)
7 include("${CMAKE_CURRENT_BINARY_DIR}/LocalOverrides.cmake" OPTIONAL)
8
9 if(NOT DEFINED HOME)
10   if(DEFINED ENV{CTEST_REAL_HOME})
11     set(HOME "$ENV{CTEST_REAL_HOME}")
12   else()
13     set(HOME "$ENV{HOME}")
14   endif()
15 endif()
16 message(STATUS "HOME='${HOME}'")
17
18 if(NOT DEFINED repo)
19   set(repo "git://public.kitware.com/cse.git")
20 endif()
21 message(STATUS "repo='${repo}'")
22
23 if(NOT DEFINED tag)
24   set(tag "cc1dcb95439a21ab1d58f444d93481598414196e")
25 endif()
26 message(STATUS "tag='${tag}'")
27
28 string(SUBSTRING "${tag}" 0 8 shorttag)
29
30 set(base_dir "${HOME}/.cmake/Contracts/${PROJECT_NAME}/${shorttag}")
31 set(binary_dir "${base_dir}/build")
32 set(script_dir "${base_dir}")
33 set(source_dir "${base_dir}/src")
34
35 if(NOT DEFINED BUILDNAME)
36   set(BUILDNAME "CMakeContract-${shorttag}")
37 endif()
38 message(STATUS "BUILDNAME='${BUILDNAME}'")
39
40 if(NOT DEFINED SITE)
41   site_name(SITE)
42 endif()
43 message(STATUS "SITE='${SITE}'")
44
45 if(NOT DEFINED PROCESSOR_COUNT)
46   # Unknown:
47   set(PROCESSOR_COUNT 0)
48
49   # Linux:
50   set(cpuinfo_file "/proc/cpuinfo")
51   if(EXISTS "${cpuinfo_file}")
52     file(STRINGS "${cpuinfo_file}" procs REGEX "^processor.: [0-9]+$")
53     list(LENGTH procs PROCESSOR_COUNT)
54   endif()
55
56   # Mac:
57   if(APPLE)
58     find_program(cmd_sysctl "sysctl")
59     if(cmd_sysctl)
60       execute_process(COMMAND ${cmd_sysctl} -n hw.ncpu
61         OUTPUT_VARIABLE PROCESSOR_COUNT
62         OUTPUT_STRIP_TRAILING_WHITESPACE)
63     endif()
64   endif()
65
66   # Windows:
67   if(WIN32)
68     set(PROCESSOR_COUNT "$ENV{NUMBER_OF_PROCESSORS}")
69   endif()
70 endif()
71 message(STATUS "PROCESSOR_COUNT='${PROCESSOR_COUNT}'")
72
73 find_package(Git)
74 if(NOT GIT_EXECUTABLE)
75   message(FATAL_ERROR "error: could not find git")
76   # adjust PATH to find git, or set GIT_EXECUTABLE in LocalOverrides.cmake
77 endif()
78 message(STATUS "GIT_EXECUTABLE='${GIT_EXECUTABLE}'")
79
80 configure_file(
81   "${CMAKE_CURRENT_SOURCE_DIR}/Dashboard.cmake.in"
82   "${script_dir}/Dashboard.cmake"
83   @ONLY)
84
85 # Source dir for this project exists outside the CMake build tree because it
86 # is absolutely huge.
87 #
88 if(EXISTS "${source_dir}/.git")
89   # If it exists already, download is a complete no-op:
90   ExternalProject_Add(download-${PROJECT_NAME}
91     DOWNLOAD_COMMAND ""
92     CONFIGURE_COMMAND ""
93     BUILD_COMMAND ""
94     INSTALL_COMMAND ""
95   )
96 else()
97   # If it does not yet exist, download clones the git repository:
98   ExternalProject_Add(download-${PROJECT_NAME}
99     SOURCE_DIR "${source_dir}"
100     GIT_REPOSITORY "${repo}"
101     GIT_TAG "${tag}"
102     CONFIGURE_COMMAND ""
103     BUILD_COMMAND ""
104     INSTALL_COMMAND ""
105   )
106 endif()
107
108 ExternalProject_Add(build-${PROJECT_NAME}
109   DOWNLOAD_COMMAND ""
110   CONFIGURE_COMMAND ""
111   BUILD_COMMAND ${CMAKE_CTEST_COMMAND} -S "${script_dir}/Dashboard.cmake"
112   INSTALL_COMMAND ""
113   DEPENDS download-${PROJECT_NAME}
114   )