diff --git a/CMakeLists.txt b/CMakeLists.txt index ec958452a1..30b8d81359 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,15 +1,44 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 3.3) +CMAKE_MINIMUM_REQUIRED(VERSION 3.1) + +INCLUDE(GNUInstallDirs) -# Name & Version PROJECT(LLVM_SPIRV - VERSION 0.1.0.0 - LANGUAGES CXX) + VERSION + 0.1.0.0 + LANGUAGES + CXX) + +SET(CMAKE_CXX_STANDARD 11) +SET(CMAKE_CXX_STANDARD_REQUIRED ON) + +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) -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}) +SUBDIRS( + lib/SPIRV + tools/llvm-spirv + test +) -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED ON) +INSTALL( + FILES + ${LLVM_SPIRV_INCLUDE_DIRS}/SPIRV.h + DESTINATION + ${CMAKE_INSTALL_INCLUDEDIR}/llvm-spirv/ +) -SUBDIRS(lib/SPIRV tools/llvm-spirv test) +CONFIGURE_FILE(LLVMSPIRVLib.pc.in ${CMAKE_BINARY_DIR}/LLVMSPIRVLib.pc @ONLY) +INSTALL( + FILES + ${CMAKE_BINARY_DIR}/LLVMSPIRVLib.pc + DESTINATION + ${CMAKE_INSTALL_LIBDIR}/pkgconfig +) diff --git a/LLVMSPIRVLib.pc.in b/LLVMSPIRVLib.pc.in new file mode 100644 index 0000000000..549683d032 --- /dev/null +++ b/LLVMSPIRVLib.pc.in @@ -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} diff --git a/lib/SPIRV/CMakeLists.txt b/lib/SPIRV/CMakeLists.txt index fc593b4ca4..01a5ae1d79 100644 --- a/lib/SPIRV/CMakeLists.txt +++ b/lib/SPIRV/CMakeLists.txt @@ -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) +ENDIF() -option(SPIRV_USE_LLVM_API "Enable usage of LLVM API for libSPIRV." ON) -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 @@ -31,8 +25,8 @@ add_llvm_library(LLVMSPIRVLib OCLUtil.cpp SPIRVLowerBool.cpp SPIRVLowerConstExpr.cpp - SPIRVLowerOCLBlocks.cpp SPIRVLowerMemmove.cpp + SPIRVLowerOCLBlocks.cpp SPIRVReader.cpp SPIRVRegularizeLLVM.cpp SPIRVToOCL20.cpp @@ -40,6 +34,22 @@ add_llvm_library(LLVMSPIRVLib 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} +) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 54d490169b..9035fe5576 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,18 +1,28 @@ -configure_lit_site_cfg( +# 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" +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) diff --git a/test/lit.cfg.py b/test/lit.cfg.py index ac60d2d583..924f3f2d95 100644 --- a/test/lit.cfg.py +++ b/test/lit.cfg.py @@ -25,7 +25,7 @@ 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() @@ -33,7 +33,7 @@ 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'] diff --git a/test/lit.site.cfg.py.in b/test/lit.site.cfg.py.in index 32af69fec0..265f819e7b 100644 --- a/test/lit.site.cfg.py.in +++ b/test/lit.site.cfg.py.in @@ -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@" @@ -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. diff --git a/tools/llvm-spirv/CMakeLists.txt b/tools/llvm-spirv/CMakeLists.txt index f4d41a9505..4ad6cdf88b 100644 --- a/tools/llvm-spirv/CMakeLists.txt +++ b/tools/llvm-spirv/CMakeLists.txt @@ -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 +)