Skip to content

Commit

Permalink
Make it possible to provide SPIRV-Tools and SPIRV-Headers externally
Browse files Browse the repository at this point in the history
The default behaviour doesn't change but a project embedding clspv
can now:
- pass SPIRV_HEADERS_SOURCE_DIR to provide SPIRV-Headers
- pass SPIRV_TOOLS_SOURCE_DIR to provide SPIRV-Tools
- pass a list of dependencies to be managed by utils/fetch_sources.py

Signed-off-by: Kévin Petit <[email protected]>
  • Loading branch information
kpet committed Sep 26, 2018
1 parent abc935e commit 0d5ffb9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
33 changes: 20 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,26 @@ endif()

use_component(${CMAKE_CURRENT_SOURCE_DIR}/third_party/clang)
use_component(${CMAKE_CURRENT_SOURCE_DIR}/third_party/llvm)
use_component(${CMAKE_CURRENT_SOURCE_DIR}/third_party/SPIRV-Headers)
use_component(${CMAKE_CURRENT_SOURCE_DIR}/third_party/SPIRV-Tools)

if (NOT DEFINED SPIRV_HEADERS_SOURCE_DIR)
set(SPIRV_HEADERS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/SPIRV-Headers)
use_component(${SPIRV_HEADERS_SOURCE_DIR})
endif()

if (NOT DEFINED SPIRV_TOOLS_SOURCE_DIR)

set(SPIRV_TOOLS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/SPIRV-Tools)

use_component(${SPIRV_TOOLS_SOURCE_DIR})

# First tell SPIR-V Tools where to find SPIR-V Headers
set(SPIRV-Headers_SOURCE_DIR ${SPIRV_HEADERS_SOURCE_DIR})

# Bring in the SPIR-V Tools repository which we'll use for testing
add_subdirectory(${SPIRV_TOOLS_SOURCE_DIR} EXCLUDE_FROM_ALL)
endif()

set(SPIRV_TOOLS_BINARY_DIR "$<TARGET_FILE_DIR:spirv-dis>")

set(CLSPV_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})

Expand All @@ -58,7 +76,6 @@ set(LLVM_EXTERNAL_CLANG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/clang
# Then pull in LLVM for building.
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party/llvm EXCLUDE_FROM_ALL)

set(SPIRV_HEADERS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/SPIRV-Headers)
set(SPIRV_HEADERS_INCLUDE_DIRS
${SPIRV_HEADERS_SOURCE_DIR}/include/
)
Expand All @@ -76,16 +93,6 @@ set(CLANG_INCLUDE_DIRS
${CMAKE_CURRENT_BINARY_DIR}/third_party/llvm/tools/clang/include
)

# First tell SPIR-V Tools where to find SPIR-V Headers
set(SPIRV-Headers_SOURCE_DIR ${SPIRV_HEADERS_SOURCE_DIR})

# Bring in the SPIR-V Tools repository which we'll use for testing
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party/SPIRV-Tools EXCLUDE_FROM_ALL)

set(SPIRV_TOOLS_BINARY_DIR
${CMAKE_CURRENT_BINARY_DIR}/third_party/SPIRV-Tools/tools
)

if(NOT WIN32)
# Disable RTTI and exceptions (to match LLVM)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions")
Expand Down
13 changes: 11 additions & 2 deletions utils/fetch_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,22 @@ def GetGoodCommits():


def main():

commits = GetGoodCommits()

all_deps = [c.name for c in commits]

parser = argparse.ArgumentParser(description='Get sources for '
' dependencies at a specified commit')
parser.add_argument('--dir', dest='dir', default='.',
help='Set target directory for dependencies source '
'root. Default is the current directory.')

args = parser.parse_args()
parser.add_argument('--deps', choices=all_deps, nargs='+', default=all_deps,
help='A list of dependencies to fetch sources for. '
'All is the default.')

commits = GetGoodCommits()
args = parser.parse_args()

distutils.dir_util.mkpath(args.dir)
print('Change directory to {d}'.format(d=args.dir))
Expand All @@ -138,6 +145,8 @@ def main():
# Create the subdirectories in sorted order so that parent git repositories
# are created first.
for c in sorted(commits, key=lambda x: x.subdir):
if c.name not in args.deps:
continue
print('Get {n}\n'.format(n=c.name))
c.Checkout()
sys.exit(0)
Expand Down

0 comments on commit 0d5ffb9

Please sign in to comment.