diff --git a/clang/tools/nec-aurora-build/CMakeLists.txt b/clang/tools/nec-aurora-build/CMakeLists.txt index d98b30be81a4..b1ec9e4b12f2 100644 --- a/clang/tools/nec-aurora-build/CMakeLists.txt +++ b/clang/tools/nec-aurora-build/CMakeLists.txt @@ -3,6 +3,29 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) project("NEC Aurora Offloading Build Wrapper Tools" CXX) endif() +# Set Clang and RVClang target compiler variables +if (CMAKE_BUILD_TYPE MATCHES RELEASE) + set(NECAURORA_TARGET_COMPILER_CLANG + "${CMAKE_INSTALL_PREFIX}/bin/clang" + CACHE + FILEPATH + "Path to clang used as VE target compiler") + set(NECAURORA_TARGET_COMPILER_RVCLANG + "${CMAKE_INSTALL_PREFIX}/bin/rvclang" + CACHE FILEPATH + "Path to rvclang used as VE target compiler") +else() # most likely there won't be an install step + set(NECAURORA_TARGET_COMPILER_CLANG + "${CMAKE_BINARY_DIR}/bin/clang" + CACHE + FILEPATH + "Path to clang used as VE target compiler") + set(NECAURORA_TARGET_COMPILER_RVCLANG + "${CMAKE_BINARY_DIR}/bin/rvclang" + CACHE FILEPATH + "Path to rvclang used as VE target compiler") +endif() + # Find NEC target compiler. find_program(NECAURORA_TARGET_COMPILER_NCC NAMES @@ -13,29 +36,25 @@ find_program(NECAURORA_TARGET_COMPILER_NCC PATHS "/opt/nec/ve/bin/" ENV PATH) + # It is okay if we do not find ncc, we can fallback to Clang or RVCLang and # will handlle the missing ncc in code. if (NECAURORA_TARGET_COMPILER_NCC) - set(TARGET_COMPILER_NCC "${NECAURORA_TARGET_COMPILER_NCC}") + set(TARGET_COMPILER_NCC "${NECAURORA_TARGET_COMPILER_NCC}") + set(NECAURORA_DEFAULT_TARGET_COMPILER + "ncc" + CACHE STRING + "Default target compiler for NEC OpenMP target (-fopenmp-nec-compiler=)") else() - message(WARNING "Could not find ncc compiler. ncc will not be available as VE target compiler") + set(TARGET_COMPILER_NCC "ncc") # We check whether it exists at runtime + set(NECAURORA_DEFAULT_TARGET_COMPILER + "${NECAURORA_TARGET_COMPILER_CLANG}" + CACHE STRING + "Default target compiler for NEC OpenMP target (-fopenmp-nec-compiler=)") + message(WARNING "Could not find ncc compiler. ncc might not be available as VE target compiler") endif() -# Set Clang and RVClang target compiler variables -set(NECAURORA_TARGET_COMPILER_CLANG - "${CMAKE_INSTALL_PREFIX}/bin/clang" - CACHE - FILEPATH - "Path to clang used as VE target compiler") -set(NECAURORA_TARGET_COMPILER_RVCLANG - "${CMAKE_INSTALL_PREFIX}/bin/rvclang" - CACHE FILEPATH - "Path to rvclang used as VE target compiler") -set(NECAURORA_DEFAULT_TARGET_COMPILER - "ncc" - CACHE STRING - "Default target compiler for NEC OpenMP target (-fopenmp-nec-compiler=)") message("OMPT for SX-Aurora: Using the default target compiler option \"${NECAURORA_DEFAULT_TARGET_COMPILER}\"" ) find_library( diff --git a/clang/tools/nec-aurora-build/utils.cpp b/clang/tools/nec-aurora-build/utils.cpp index 2252fbbe8af1..91e8e5eb97e5 100644 --- a/clang/tools/nec-aurora-build/utils.cpp +++ b/clang/tools/nec-aurora-build/utils.cpp @@ -25,13 +25,20 @@ int configureTargetCompiler(const std::string& CompilerName) { << std::endl; } + // We can assume the first two to exist if (CompilerName == "clang") { CompilerCmd = ClangCompilerCmd; return 0; } if (CompilerName == "rvclang") { CompilerCmd = RVClangCompilerCmd; return 0; } - if (CompilerName == "ncc") { CompilerCmd = NCCCompilerCmd; return 0; } + if (CompilerName == "ncc") { + CompilerCmd = NCCCompilerCmd; + auto ret = std::system((CompilerCmd + " --version").c_str()); + if (ret == 0) { + return 0; + } + } std::cerr << "nec-aurora-build: -fopenmp-nec-compiler=" << CompilerCmd - << " not recognized" + << " not recognized. Aborting." << std::endl; - return 1; + exit(EXIT_FAILURE); // it does not make any sense to continue here } @@ -39,7 +46,7 @@ const char *getTargetCompiler() { // If no option was specified on the command line chose the builtin default if (CompilerCmd.empty()) { #ifndef DEFAULT_TARGET_COMPILER_OPTION -#error "DEFAULT_TARGET_COMPILER_OPTION not specified during build!" +#error "DEFAULT_TARGET_COMPILER_OPTION not specified during build!" #endif configureTargetCompiler(DEFAULT_TARGET_COMPILER_OPTION); }