-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdo_configure
executable file
·158 lines (136 loc) · 5.25 KB
/
do_configure
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/bin/bash
set -e
# Initialize variables with default values
BUILD_TYPE="Release"
CHECK_CODE_COVERAGE=OFF
USE_GPU=OFF
USE_PROTEGO_MECH=OFF
# Get the current directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
# Parse command-line options
while [[ $# -gt 0 ]]; do
key="$1"
case ${key} in
-t | --build-type)
BUILD_TYPE="$2"
shift
shift
;;
-c | --code-coverage)
CHECK_CODE_COVERAGE=ON
BUILD_TYPE="Debug"
echo "Requested code coverage. Build type set to Debug"
shift
;;
-g | --gpu)
USE_GPU=ON
echo "Requested GPU support."
shift
;;
-p | --protego-mech)
USE_PROTEGO_MECH=ON
echo "Including protego-mech."
shift
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
# If some of the spack commmands below fail, make sure the correct environment is activated. e.g.:
# spack env activate aperi-mech
# Check for cmake in the spack environment, if not found, use the system cmake
if spack find -p cmake; then
cmake=$(spack location -i --first cmake)/bin/cmake
else
cmake=cmake
fi
# Configure CMake with specified build type and other options
cmake_command="${cmake}"
cmake_command+=" -D USE_GPU:BOOL=${USE_GPU}"
cmake_command+=" -D USE_PROTEGO_MECH:BOOL=${USE_PROTEGO_MECH}"
cmake_command+=" -D CMAKE_BUILD_TYPE:STRING=\"${BUILD_TYPE}\""
cmake_command+=" -D TRILINOS_PATH:FILEPATH=$(spack location -i trilinos)"
cmake_command+=" -D Kokkos_ROOT:FILEPATH=$(spack location -i kokkos)"
# If eigen is at /home/aperi-mech_docker/eigen_install, use that path. Otherwise, use the spack location
eigen_path=""
if [[ -d /home/aperi-mech_docker/eigen_install ]]; then
eigen_path="/home/aperi-mech_docker/eigen_install"
# Uninstall eigen from spack so that the local eigen is used
spack uninstall -y eigen || true
else
eigen_path=$(spack location -i eigen)
fi
cmake_command+=" -D EIGEN_PATH:FILEPATH=${eigen_path}"
cmake_command+=" -D GTEST_PATH:FILEPATH=$(spack location -i googletest)"
cmake_command+=" -D YAML-CPP_PATH:FILEPATH=$(spack location -i yaml-cpp)"
cmake_command+=" -D OPENMPI_PATH:FILEPATH=$(spack location -i openmpi)"
cmake_command+=" -D COMPADRE_PATH:FILEPATH=$(spack location -i compadre)"
# Add the lcov path to the cmake command
if [[ ${CHECK_CODE_COVERAGE} == "ON" ]]; then
# Verify that lcov is in /usr/bin
if [[ -f /usr/bin/lcov ]]; then
cmake_command+=" -D LCOV_BIN_DIR:FILEPATH=/usr/bin"
echo "lcov found in /usr/bin."
else
echo "lcov not found in /usr/bin. Checking Spack environment."
if spack find -p lcov; then
cmake_command+=" -D LCOV_BIN_DIR:FILEPATH=$(spack location -i --first lcov)/bin"
else
echo "lcov not found in Spack environment."
echo "lcov is required for code coverage. Please install lcov. Exiting."
exit 1
fi
fi
fi
cmake_command+=" -D CHECK_CODE_COVERAGE:BOOL=${CHECK_CODE_COVERAGE}"
if [[ ${USE_GPU} == "ON" ]]; then
# Add the cuda path to the cmake command
CUDA_PATH=$(spack location -i cuda)
# Add the cuda compiler to the cmake command
cmake_command+=" -D CMAKE_CUDA_COMPILER:FILEPATH=${CUDA_PATH}/bin/nvcc"
# Add the cuda flags to the cmake command. There has got to be a better way to do this. Needed?
cmake_command+=' -D CMAKE_CUDA_FLAGS="-arch=sm_'
arch_string=$(spack find kokkos | grep 'cuda_arch=' | awk -F'cuda_arch=' 'NR==1 {print $2}' | awk '{print $1}') || true
cmake_command+="${arch_string}\""
fi
# Add the C++ compiler to the cmake command. There has got to be a better way to do this.
kokkos_compiler=$(spack find --show-full-compiler kokkos | grep kokkos | tail -n 1 | cut -d'%' -f2) || true
kokkos_cxx_path=$(spack compiler info "${kokkos_compiler}" | grep 'cxx' | awk '{print $3}' | grep -v '^$') || true
cmake_command+=" -D CMAKE_CXX_COMPILER:FILEPATH=${kokkos_cxx_path}"
# Add the C compiler to the cmake command. Also, there has got to be a better way to do this.
kokkos_c_path=$(spack compiler info "${kokkos_compiler}" | grep 'cc' | awk '{print $3}' | grep -v '^$') || true
cmake_command+=" -D CMAKE_C_COMPILER:FILEPATH=${kokkos_c_path}"
# Add the C++ flags to the cmake command
cmake_command+=" -D CMAKE_CXX_FLAGS:STRING='-Wall -pedantic -Wno-long-long -ftrapv -Wno-deprecated -Wno-unknown-pragmas'"
# cmake_command+=" -D CMAKE_CXX_FLAGS:STRING='-Wall -Wextra -Werror -pedantic -Wno-long-long -ftrapv -Wno-deprecated -Wno-unknown-pragmas'"
# Add the flag to export compile commands to the cmake command
cmake_command+=" -D CMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON"
# Add the flag to turn off C++ extensions to the cmake command
cmake_command+=" -D CMAKE_CXX_EXTENSIONS=Off"
# Add the script path to the stk_ngp_basic source code
cmake_command+=" ${SCRIPT_DIR}"
# Create build directory
# Build directory base
BUILD_DIR="build/${BUILD_TYPE}"
# Prepend to build directory based on protego-mech usage
if [[ ${USE_PROTEGO_MECH} == "ON" ]]; then
BUILD_DIR="protego-mech/build/${BUILD_TYPE}"
fi
# Append to build directory based on GPU usage
if [[ ${USE_GPU} == "ON" ]]; then
BUILD_DIR+="_gpu"
fi
# Append to build directory based on code coverage
if [[ ${CHECK_CODE_COVERAGE} == "ON" ]]; then
BUILD_DIR+="_cov"
fi
# Create the build directory and change to it
mkdir -p "${BUILD_DIR}"
cd "${BUILD_DIR}" || exit
# Remove CMakeCache if it exists
[[ -f CMakeCache.txt ]] && rm CMakeCache.txt
# Print and execute the cmake command
echo "CMake Command: ${cmake_command}"
eval "${cmake_command}"