1# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2# file Copyright.txt or https://cmake.org/licensing for details.
3
4
5# determine the compiler to use for ISPC programs
6
7include(${CMAKE_ROOT}/Modules/CMakeDetermineCompiler.cmake)
8
9if( NOT (("${CMAKE_GENERATOR}" MATCHES "Make") OR ("${CMAKE_GENERATOR}" MATCHES "Ninja")) )
10  message(FATAL_ERROR "ISPC language not currently supported by \"${CMAKE_GENERATOR}\" generator")
11endif()
12
13# Load system-specific compiler preferences for this language.
14include(Platform/${CMAKE_SYSTEM_NAME}-Determine-ISPC OPTIONAL)
15include(Platform/${CMAKE_SYSTEM_NAME}-ISPC OPTIONAL)
16if(NOT CMAKE_ISPC_COMPILER_NAMES)
17  set(CMAKE_ISPC_COMPILER_NAMES ispc)
18endif()
19
20
21if(NOT CMAKE_ISPC_COMPILER)
22
23  set(CMAKE_ISPC_COMPILER_INIT NOTFOUND)
24
25  # prefer the environment variable CC
26  if(NOT $ENV{ISPC} STREQUAL "")
27    get_filename_component(CMAKE_ISPC_COMPILER_INIT $ENV{ISPC} PROGRAM PROGRAM_ARGS CMAKE_ISPC_FLAGS_ENV_INIT)
28    if(CMAKE_ISPC_FLAGS_ENV_INIT)
29      set(CMAKE_ISPC_COMPILER_ARG1 "${CMAKE_ISPC_FLAGS_ENV_INIT}" CACHE STRING "First argument to ISPC compiler")
30    endif()
31    if(NOT EXISTS ${CMAKE_ISPC_COMPILER_INIT})
32      message(FATAL_ERROR "Could not find compiler set in environment variable ISPC:\n$ENV{ISPC}.")
33    endif()
34  endif()
35
36  # next try prefer the compiler specified by the generator
37  if(CMAKE_GENERATOR_ISPC)
38    if(NOT CMAKE_ISPC_COMPILER_INIT)
39      set(CMAKE_ISPC_COMPILER_INIT ${CMAKE_GENERATOR_ISPC})
40    endif()
41  endif()
42
43  # finally list compilers to try
44  if(NOT CMAKE_ISPC_COMPILER_INIT)
45    set(CMAKE_ISPC_COMPILER_LIST ${_CMAKE_TOOLCHAIN_PREFIX}ispc ispc)
46  endif()
47
48  # Find the compiler.
49  _cmake_find_compiler(ISPC)
50
51else()
52  _cmake_find_compiler_path(ISPC)
53endif()
54mark_as_advanced(CMAKE_ISPC_COMPILER)
55
56if(NOT CMAKE_ISPC_COMPILER_ID_RUN)
57set(CMAKE_ISPC_COMPILER_ID_RUN 1)
58
59  # Try to identify the compiler.
60  set(CMAKE_ISPC_COMPILER_ID)
61  set(CMAKE_ISPC_PLATFORM_ID)
62
63
64  set(CMAKE_ISPC_COMPILER_ID_TEST_FLAGS_FIRST
65  # setup logic to make sure ISPC outputs a file
66  "-o cmake_ispc_output"
67  )
68
69  include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake)
70  CMAKE_DETERMINE_COMPILER_ID(ISPC ISPCFLAGS CMakeISPCCompilerId.ispc)
71
72  _cmake_find_compiler_sysroot(ISPC)
73endif()
74
75if (NOT _CMAKE_TOOLCHAIN_LOCATION)
76  get_filename_component(_CMAKE_TOOLCHAIN_LOCATION "${CMAKE_ISPC_COMPILER}" PATH)
77endif ()
78
79set(_CMAKE_PROCESSING_LANGUAGE "ISPC")
80include(CMakeFindBinUtils)
81include(Compiler/${CMAKE_ISPC_COMPILER_ID}-FindBinUtils OPTIONAL)
82unset(_CMAKE_PROCESSING_LANGUAGE)
83
84if(CMAKE_ISPC_COMPILER_ID_VENDOR_MATCH)
85  set(_SET_CMAKE_ISPC_COMPILER_ID_VENDOR_MATCH
86    "set(CMAKE_ISPC_COMPILER_ID_VENDOR_MATCH [==[${CMAKE_ISPC_COMPILER_ID_VENDOR_MATCH}]==])")
87else()
88  set(_SET_CMAKE_ISPC_COMPILER_ID_VENDOR_MATCH "")
89endif()
90
91
92# configure variables set in this file for fast reload later on
93configure_file(${CMAKE_ROOT}/Modules/CMakeISPCCompiler.cmake.in
94  ${CMAKE_PLATFORM_INFO_DIR}/CMakeISPCCompiler.cmake @ONLY)
95
96set(CMAKE_ISPC_COMPILER_ENV_VAR "ISPC")
97