diff --git a/CMakeLists.txt b/CMakeLists.txt index ec958452a1..09bb64f688 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 +) 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..3ee70dbaf6 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) +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..95c9a16950 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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) 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..66815f7182 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 +)