-
Notifications
You must be signed in to change notification settings - Fork 8
/
install
88 lines (74 loc) · 4.26 KB
/
install
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# Copyright © 2020-2024 Allan Leal
#------------------------------------------------------------------------------
# Note
#------------------------------------------------------------------------------
# This script can be executed from anywhere because of the use of
# CMAKE_CURRENT_LIST_DIR to detect the path to this install cmake script.
#------------------------------------------------------------------------------
# Set the cmake module path of the script
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
# Include this CMake module to output colored text messages
include(ColoredText)
# Set the build type to Release by default, if not defined
if(NOT DEFINED BUILD_TYPE)
set(BUILD_TYPE Release)
endif()
# Set the build path variable BUILD_PATH
if(NOT DEFINED BUILD_PATH)
set(BUILD_PATH ${CMAKE_CURRENT_LIST_DIR}/build) # Set BUILD_PATH to rootdir/build if not defined.
endif()
# Set the install path variable INSTALL_PATH
if(NOT DEFINED INSTALL_PATH)
set(INSTALL_PATH ${BUILD_PATH}/install) # Set INSTALL_PATH to rootdir/build/install if not defined
endif()
# Compute the native install path for target OS (Linux, macOS, Windows).
file(TO_NATIVE_PATH ${INSTALL_PATH} NATIVE_INSTALL_PATH)
# Set the number of parallel jobs to empty for maximum number of jobs, if not defined
if(NOT DEFINED JOBS)
set(JOBS "")
endif()
# Set the PYTHON variable to ON by default to ensure Python bindings are built
if(NOT DEFINED PYTHON)
set(PYTHON ON)
endif()
# Define PARALLEL variable containing the cmake option for parallel builds.
if(NOT DEFINED PARALLEL AND NOT WIN32)
set(PARALLEL --parallel ${JOBS}) # in Windows, using MSVC compilers, --parallel cancels the /MP compilation option and ends up with not parallel build at all!
endif()
# Configure the building and installation of the project
execute_process(COMMAND
${CMAKE_COMMAND} -S ${CMAKE_CURRENT_LIST_DIR} -B ${BUILD_PATH}
-DOPTIMA_BUILD_PYTHON=${PYTHON}
-DCMAKE_BUILD_TYPE=${BUILD_TYPE}
-DCMAKE_INSTALL_PREFIX=${NATIVE_INSTALL_PATH})
# Build and install the library
execute_process(COMMAND
${CMAKE_COMMAND} --build ${BUILD_PATH} --config ${BUILD_TYPE} ${PARALLEL} --target install)
# Run the tests if TESTS option is TRUE
if(TESTS)
execute_process(COMMAND ${CMAKE_COMMAND} --build ${BUILD_PATH} --config ${BUILD_TYPE} --target tests)
endif()
# Print a summary of the installation
message("${BoldCyan}")
message("====================================================================================================")
message("Summary")
message("====================================================================================================${ColourReset}")
message("The library was built in ${BoldBlue}${BUILD_TYPE}${ColourReset} mode in:")
message(" ${BoldYellow}${BUILD_PATH}${ColourReset}")
message("The library was installed in:")
message(" ${BoldYellow}${NATIVE_INSTALL_PATH}${ColourReset}")
message("${BoldCyan}----------------------------------------------------------------------------------------------------")
message("How do I change the default build and install paths and build type?")
message("----------------------------------------------------------------------------------------------------${ColourReset}")
message("Change the default build path to an ${BoldBlue}absolute path${ColourReset} <build-dir> by executing:")
message(" ${BoldYellow}cmake -DBUILD_PATH=<build-dir> -P install${ColourReset}")
message("Change the default build type from Release to Debug by executing:")
message(" ${BoldYellow}cmake -DBUILD_TYPE=Debug -P install${ColourReset}")
message("Change the default install path to an ${BoldBlue}absolute path${ColourReset} <install-dir> by executing:")
message(" ${BoldYellow}cmake -DPREFIX=<install-dir> -P install${ColourReset}")
message("Linux and macOS users might want to install in a system directory, for example:")
message(" ${BoldYellow}cmake -DPREFIX=/usr/local -P install${ColourReset}")
message("${BoldCyan}----------------------------------------------------------------------------------------------------")
message("*** The above summary assumes a successfull build/installation process for all components ***")
message("====================================================================================================")
message("${ColourReset}")