88 lines
3.1 KiB
Bash
Executable File
88 lines
3.1 KiB
Bash
Executable File
#!/bin/bash -e
|
|
#
|
|
# This script allows CMAKE_CXX_COMPILER to be a standard
|
|
# C++ compiler and Kokkos sets RULE_LAUNCH_COMPILE and
|
|
# RULE_LAUNCH_LINK in CMake so that all compiler and link
|
|
# commands are prefixed with this script followed by the
|
|
# C++ compiler. Thus if $1 == $2 then we know the command
|
|
# was intended for the C++ compiler and we discard both
|
|
# $1 and $2 and redirect the command to NVCC_WRAPPER.
|
|
# If $1 != $2 then we know that the command was not intended
|
|
# for the C++ compiler and we just discard $1 and launch
|
|
# the original command. Examples of when $2 will not equal
|
|
# $1 are 'ar', 'cmake', etc. during the linking phase
|
|
#
|
|
|
|
# check the arguments for the KOKKOS_DEPENDENCE compiler definition
|
|
KOKKOS_DEPENDENCE=0
|
|
for i in ${@}
|
|
do
|
|
if [ -n "$(echo ${i} | grep 'KOKKOS_DEPENDENCE$')" ]; then
|
|
KOKKOS_DEPENDENCE=1
|
|
break
|
|
fi
|
|
done
|
|
|
|
# if C++ is not passed, someone is probably trying to invoke it directly
|
|
if [ -z "${1}" ]; then
|
|
echo -e "\n${BASH_SOURCE[0]} was invoked without the C++ compiler as the first argument."
|
|
echo "This script is not indended to be directly invoked by any mechanism other"
|
|
echo -e "than through a RULE_LAUNCH_COMPILE or RULE_LAUNCH_LINK property set in CMake\n"
|
|
exit 1
|
|
fi
|
|
|
|
# if there aren't two args, this isn't necessarily invalid, just a bit strange
|
|
if [ -z "${2}" ]; then exit 0; fi
|
|
|
|
# store the expected C++ compiler
|
|
CXX_COMPILER=${1}
|
|
|
|
# remove the expected C++ compiler from the arguments
|
|
shift
|
|
|
|
# after the above shift, $1 is now the exe for the compile or link command, e.g.
|
|
# kokkos_launch_compiler g++ gcc -c file.c -o file.o
|
|
# becomes:
|
|
# kokkos_launch_compiler gcc -c file.c -o file.o
|
|
# Check to see if the executable is the C++ compiler and if it is not, then
|
|
# just execute the command.
|
|
#
|
|
# Summary:
|
|
# kokkos_launch_compiler g++ gcc -c file.c -o file.o
|
|
# results in this command being executed:
|
|
# gcc -c file.c -o file.o
|
|
# and
|
|
# kokkos_launch_compiler g++ g++ -c file.cpp -o file.o
|
|
# results in this command being executed:
|
|
# nvcc_wrapper -c file.cpp -o file.o
|
|
if [[ "${KOKKOS_DEPENDENCE}" -eq "0" || "${CXX_COMPILER}" != "${1}" ]]; then
|
|
# the command does not depend on Kokkos so just execute the command w/o re-directing to nvcc_wrapper
|
|
eval $@
|
|
else
|
|
# the executable is the C++ compiler, so we need to re-direct to nvcc_wrapper
|
|
|
|
# find the nvcc_wrapper from the same build/install
|
|
NVCC_WRAPPER="$(dirname ${BASH_SOURCE[0]})/nvcc_wrapper"
|
|
|
|
if [ -z "${NVCC_WRAPPER}" ]; then
|
|
echo -e "\nError: nvcc_wrapper not found in $(dirname ${BASH_SOURCE[0]}).\n"
|
|
exit 1
|
|
fi
|
|
|
|
# set default nvcc wrapper compiler if not specified
|
|
: ${NVCC_WRAPPER_DEFAULT_COMPILER:=${CXX_COMPILER}}
|
|
export NVCC_WRAPPER_DEFAULT_COMPILER
|
|
|
|
# calling itself will cause an infinitely long build
|
|
if [ "${NVCC_WRAPPER}" = "${NVCC_WRAPPER_DEFAULT_COMPILER}" ]; then
|
|
echo -e "\nError: NVCC_WRAPPER == NVCC_WRAPPER_DEFAULT_COMPILER. Terminating to avoid infinite loop!\n"
|
|
exit 1
|
|
fi
|
|
|
|
# discard the compiler from the command
|
|
shift
|
|
|
|
# execute nvcc_wrapper
|
|
${NVCC_WRAPPER} $@
|
|
fi
|