-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
72 lines (56 loc) · 2.59 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
### Maintainer: mpohling[@techfak.uni-bielefeld.de] ###
cmake_minimum_required(VERSION 2.8)
PROJECT(csra-db)
SET(CMAKE_BUILD_TYPE distribution)
IF(NOT DEFINED BCO_DB_HOME)
SET(BCO_DB_HOME "share/bco/registry/db")
ENDIF ()
IF(NOT DEFINED BCO_DB_GIT_URL)
EXECUTE_PROCESS(COMMAND git config --get remote.origin.url OUTPUT_VARIABLE BCO_DB_GIT_URL OUTPUT_STRIP_TRAILING_WHITESPACE)
MESSAGE("Found remote url: ${BCO_DB_GIT_URL}")
ENDIF ()
IF (NOT CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
SET(INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
MESSAGE("-- Use given install PREFIX: ${INSTALL_PREFIX}")
ELSEIF (DEFINED ENV{prefix})
SET(INSTALL_PREFIX $ENV{prefix})
MESSAGE("-- Found global install PREFIX: ${INSTALL_PREFIX}")
MESSAGE("---- Set -DCMAKE_INSTALL_PREFIX for using a custom prefix.")
ELSE ()
SET(INSTALL_PREFIX "$ENV{HOME}/.local/share")
MESSAGE("-- Use default prefix: ${INSTALL_PREFIX}")
MESSAGE("---- Set -DCMAKE_INSTALL_PREFIX for using a custom prefix.")
ENDIF()
SET(DB_DOWNLOAD_FOLDER ${CMAKE_BINARY_DIR}/db-clone)
IF (EXISTS ${DB_DOWNLOAD_FOLDER})
FILE(REMOVE_RECURSE ${DB_DOWNLOAD_FOLDER})
ENDIF()
file(MAKE_DIRECTORY ${DB_DOWNLOAD_FOLDER})
MESSAGE("Download repository ${BCO_DB_GIT_URL} into ${DB_DOWNLOAD_FOLDER}")
EXECUTE_PROCESS(COMMAND git clone ${BCO_DB_GIT_URL} ${DB_DOWNLOAD_FOLDER})
IF(DEFINED BCO_DB_GIT_PATH)
MESSAGE("Manual db version overwrite detected!")
SET(BCO_BRANCH ${BCO_DB_GIT_PATH})
ELSE()
EXECUTE_PROCESS(COMMAND git rev-parse --abbrev-ref HEAD OUTPUT_VARIABLE BCO_BRANCH OUTPUT_STRIP_TRAILING_WHITESPACE)
ENDIF()
MESSAGE("Checkout: ${BCO_BRANCH}")
EXECUTE_PROCESS(COMMAND git -C ${DB_DOWNLOAD_FOLDER} checkout ${BCO_BRANCH})
IF (EXISTS ${INSTALL_PREFIX}/${BCO_DB_HOME})
IF(${FORCE})
FILE(REMOVE_RECURSE ${INSTALL_PREFIX}/${BCO_DB_HOME})
ELSE()
MESSAGE(SEND_ERROR "Abort installation! Database cannot be overwritten. Set -DFORCE=true to overwrite the database.")
ENDIF()
ENDIF()
### Create db folder ###
FILE(MAKE_DIRECTORY ${INSTALL_PREFIX}/${BCO_DB_HOME})
IF(${READ_ONLY})
SET(DB_PERMISSIONS PATTERN "*.json" PERMISSIONS OWNER_READ GROUP_READ WORLD_READ)
ELSE()
SET(DB_PERMISSIONS PATTERN "*.json" PERMISSIONS OWNER_READ GROUP_READ WORLD_READ OWNER_WRITE GROUP_WRITE)
ENDIF()
### Install data into volume ###
INSTALL(DIRECTORY "${DB_DOWNLOAD_FOLDER}/" DESTINATION ${INSTALL_PREFIX}/${BCO_DB_HOME} ${DB_PERMISSIONS})
INSTALL(PROGRAMS "${DB_DOWNLOAD_FOLDER}/install.sh" DESTINATION ${INSTALL_PREFIX}/${BCO_DB_HOME})
INSTALL(PROGRAMS "${DB_DOWNLOAD_FOLDER}/reset.sh" DESTINATION ${INSTALL_PREFIX}/${BCO_DB_HOME})