Skip to content

Commit

Permalink
cmake: rework to be able to build outside LLVM
Browse files Browse the repository at this point in the history
v2: convert to lower case
  • Loading branch information
karolherbst committed Apr 12, 2018
1 parent 622f3ae commit 141c2c1
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 48 deletions.
47 changes: 38 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,44 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.3)
cmake_minimum_required(VERSION 3.1)

# Name & Version
PROJECT(LLVM_SPIRV
VERSION 0.1.0.0
LANGUAGES CXX)
include(GNUInstallDirs)

message(STATUS "LLVM-SPIRV found at ${CMAKE_CURRENT_SOURCE_DIR}")
set(LLVM_SPIRV_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include)
set(LLVM_SPIRV_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
project(LLVM_SPIRV
VERSION
0.1.0.0
LANGUAGES
CXX)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

SUBDIRS(lib/SPIRV tools/llvm-spirv test)
find_package(LLVM 7.0.0 REQUIRED)
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
${LLVM_CMAKE_DIR}
)
include(AddLLVM)

message(STATUS "Found LLVM: ${LLVM_VERSION}")

set(LLVM_SPIRV_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include)

subdirs(
lib/SPIRV
tools/llvm-spirv
test
)

install(
FILES
${LLVM_SPIRV_INCLUDE_DIRS}/SPIRV.h
DESTINATION
${CMAKE_INSTALL_INCLUDEDIR}/llvm-spirv/
)

configure_file(LLVMSPIRVLib.pc.in ${CMAKE_BINARY_DIR}/LLVMSPIRVLib.pc @ONLY)
install(
FILES
${CMAKE_BINARY_DIR}/LLVMSPIRVLib.pc
DESTINATION
${CMAKE_INSTALL_LIBDIR}/pkgconfig
)
12 changes: 12 additions & 0 deletions LLVMSPIRVLib.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@

Name: LLVMSPIRVLib
Description: LLVM/SPIR-V bi-direction translator
Version: @LLVM_SPIRV_VERSION@
URL: https://github.com/KhronosGroup/SPIRV-LLVM-Translator

Libs: -L${libdir} -lLLVMSPIRVLib
Cflags: -I${includedir}
34 changes: 22 additions & 12 deletions lib/SPIRV/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
include_directories(
${LLVM_SPIRV_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/Mangler
${CMAKE_CURRENT_SOURCE_DIR}/libSPIRV
${CMAKE_CURRENT_SOURCE_DIR})

option(SPIRV_USE_LLVM_API "Enable usage of LLVM API for libSPIRV." ON)
if ( SPIRV_USE_LLVM_API )
add_definitions(-D_SPIRV_LLVM_API)
if(SPIRV_USE_LLVM_API)
ADD_DEFINITIONS(-D_SPIRV_LLVM_API)
endif()

add_llvm_library(LLVMSPIRVLib
add_library(LLVMSPIRVLib SHARED
libSPIRV/SPIRVBasicBlock.cpp
libSPIRV/SPIRVDebug.cpp
libSPIRV/SPIRVDecorate.cpp
Expand All @@ -31,15 +25,31 @@ add_llvm_library(LLVMSPIRVLib
OCLUtil.cpp
SPIRVLowerBool.cpp
SPIRVLowerConstExpr.cpp
SPIRVLowerOCLBlocks.cpp
SPIRVLowerMemmove.cpp
SPIRVLowerOCLBlocks.cpp
SPIRVReader.cpp
SPIRVRegularizeLLVM.cpp
SPIRVToOCL20.cpp
SPIRVUtil.cpp
SPIRVWriter.cpp
SPIRVWriterPass.cpp
TransOCLMD.cpp
)
)

target_include_directories(LLVMSPIRVLib
PRIVATE
${LLVM_INCLUDE_DIR}
${LLVM_SPIRV_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/libSPIRV
${CMAKE_CURRENT_SOURCE_DIR}/Mangler
)

target_link_libraries(LLVMSPIRVLib
LLVM
)

add_dependencies(LLVMSPIRVLib intrinsics_gen)
install(
TARGETS LLVMSPIRVLib
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
30 changes: 20 additions & 10 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
# required by lit.site.cfg.py.in
get_target_property(LLVM_SPIRV_DIR llvm-spirv BINARY_DIR)
configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
MAIN_CONFIG
${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py
)

list(APPEND LLVM_SPIRV_TEST_DEPS
FileCheck count not
llvm-as
llvm-dis
llvm-spirv
${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py
)

add_lit_testsuite(check-llvm-spirv "Running the LLVM-SPIRV regression tests"
${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${LLVM_SPIRV_TEST_DEPS}
)
ARGS
--verbose
DEPENDS
llvm-spirv
)

# to enable a custom test target on cmake below 3.11
# starting with 3.11 "test" is only reserved if ENABLE_TESTING(ON)
cmake_policy(PUSH)
if(POLICY CMP0037 AND ${CMAKE_VERSION} VERSION_LESS "3.11.0")
CMAKE_POLICY(SET CMP0037 OLD)
endif()
add_custom_target(test
DEPENDS
check-llvm-spirv
)
cmake_policy(POP)
4 changes: 2 additions & 2 deletions test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
config.test_source_root = os.path.dirname(__file__)

# test_exec_root: The root path where tests should be run.
config.test_exec_root = os.path.join(config.llvm_obj_root, 'test')
config.test_exec_root = os.path.join(config.test_run_dir, 'test_output')

llvm_config.use_default_substitutions()

#llvm_config.use_clang()

config.substitutions.append(('%PATH%', config.environment['PATH']))

tool_dirs = [config.llvm_tools_dir]
tool_dirs = [config.llvm_tools_dir, config.llvm_spirv_dir]

tools = ['llvm-as', 'llvm-dis', 'llvm-spirv']

Expand Down
2 changes: 2 additions & 0 deletions test/lit.site.cfg.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import sys
config.llvm_src_root = "@LLVM_SOURCE_DIR@"
config.llvm_obj_root = "@LLVM_BINARY_DIR@"
config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
config.llvm_spirv_dir = "@LLVM_SPIRV_DIR@"
config.llvm_libs_dir = "@LLVM_LIBS_DIR@"
config.llvm_shlib_dir = "@SHLIBDIR@"
config.llvm_plugin_ext = "@LLVM_PLUGIN_EXT@"
Expand All @@ -13,6 +14,7 @@ config.host_triple = "@LLVM_HOST_TRIPLE@"
config.target_triple = "@TARGET_TRIPLE@"
config.host_arch = "@HOST_ARCH@"
config.python_executable = "@PYTHON_EXECUTABLE@"
config.test_run_dir = "@CMAKE_CURRENT_BINARY_DIR@"

# Support substitution of the tools and libs dirs with user parameters. This is
# used when we can't determine the tool dir at configuration time.
Expand Down
35 changes: 20 additions & 15 deletions tools/llvm-spirv/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
set(LLVM_LINK_COMPONENTS
Analysis
BitReader
BitWriter
Core
SPIRVLib
Support
TransformUtils
)

include_directories(${LLVM_SPIRV_INCLUDE_DIRS})

add_llvm_tool(llvm-spirv
llvm-spirv.cpp
)
add_executable(llvm-spirv
llvm-spirv.cpp
)

target_include_directories(llvm-spirv
PRIVATE
${LLVM_INCLUDE_DIR}
${LLVM_SPIRV_INCLUDE_DIRS}
)

target_link_libraries(llvm-spirv
LLVMSPIRVLib
)

install(
TARGETS
llvm-spirv
DESTINATION
${CMAKE_INSTALL_PREFIX}/bin
)

0 comments on commit 141c2c1

Please sign in to comment.