├── example02 ├── include │ └── bar.hpp ├── src │ ├── bar.cpp │ └── CMakeLists.txt └── CMakeLists.txt ├── example03 ├── include │ └── bar.hpp ├── src │ ├── bar.cpp │ └── CMakeLists.txt └── CMakeLists.txt ├── example01 ├── include │ ├── detail │ │ └── bar_impl.hpp │ ├── bar.hpp │ └── general │ │ └── general.h ├── src │ ├── bar.cpp │ ├── foo.cpp │ └── CMakeLists.txt └── CMakeLists.txt ├── README.md ├── cmake ├── LLVMIRUtilInternal.cmake └── LLVMIRUtil.cmake └── LICENSE /example02/include/bar.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void foo(); 4 | 5 | -------------------------------------------------------------------------------- /example03/include/bar.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void foo(); 4 | 5 | -------------------------------------------------------------------------------- /example01/include/detail/bar_impl.hpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | namespace detail { 4 | const int g_bar_count = 0; 5 | } 6 | 7 | -------------------------------------------------------------------------------- /example01/include/bar.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef DIR_FOO 4 | #error "DIR_FOO is not defined" 5 | #endif 6 | 7 | void foo(); 8 | 9 | -------------------------------------------------------------------------------- /example02/src/bar.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include "bar.hpp" 5 | 6 | void foo() { 7 | std::cout << "foo\n"; 8 | 9 | return; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /example03/src/bar.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include "bar.hpp" 5 | 6 | void foo() { 7 | std::cout << "foo\n"; 8 | 9 | return; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /example01/include/general/general.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include 5 | 6 | 7 | void general(void) { 8 | std::cout << "this is general\n"; 9 | 10 | return; 11 | } 12 | -------------------------------------------------------------------------------- /example01/src/bar.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include "bar.hpp" 5 | #include "bar_impl.hpp" 6 | 7 | void foo() { 8 | using ::detail::g_bar_count; 9 | 10 | std::cout << "foo\n"; 11 | 12 | return; 13 | } 14 | 15 | 16 | -------------------------------------------------------------------------------- /example01/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # cmake file 2 | 3 | cmake_minimum_required(VERSION 3.2) 4 | 5 | project(qux C CXX) 6 | 7 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake") 8 | 9 | message(STATUS ${CMAKE_MODULE_PATH}) 10 | include(LLVMIRUtil) 11 | 12 | add_subdirectory(src) 13 | 14 | -------------------------------------------------------------------------------- /example02/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # cmake file 2 | 3 | cmake_minimum_required(VERSION 3.2) 4 | 5 | project(qux C CXX) 6 | 7 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake") 8 | 9 | message(STATUS ${CMAKE_MODULE_PATH}) 10 | include(LLVMIRUtil) 11 | 12 | add_subdirectory(src) 13 | 14 | -------------------------------------------------------------------------------- /example03/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # cmake file 2 | 3 | cmake_minimum_required(VERSION 3.2) 4 | 5 | project(qux C CXX) 6 | 7 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake") 8 | 9 | message(STATUS ${CMAKE_MODULE_PATH}) 10 | include(LLVMIRUtil) 11 | 12 | add_subdirectory(src) 13 | 14 | -------------------------------------------------------------------------------- /example01/src/foo.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include "general.h" 5 | 6 | #include "bar.hpp" 7 | 8 | #ifndef TARGET_IF_FOO 9 | #error "TARGET_IF_FOO is not defined." 10 | #endif 11 | 12 | #ifndef TARGET_PUB_FOO 13 | #error "TARGET_PUB_FOO is not defined." 14 | #endif 15 | 16 | #ifndef TARGET_PRIV_FOO 17 | #error "TARGET_PRIV_FOO is not defined." 18 | #endif 19 | 20 | int main(int argc, const char *argv[]) { 21 | std::cout << "Hello!\n"; 22 | foo(); 23 | 24 | return 0; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /example02/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # cmake file 2 | 3 | # options 4 | 5 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath /lib") 6 | 7 | # general defs 8 | 9 | set(SOURCES 10 | bar.cpp) 11 | 12 | 13 | # directory level 14 | 15 | 16 | # target level 17 | 18 | add_library(bar ${SOURCES}) 19 | 20 | # this property is required by our parasitic targets 21 | set_target_properties(bar PROPERTIES LINKER_LANGUAGE CXX) 22 | 23 | target_include_directories(bar PUBLIC "../include") 24 | 25 | target_compile_options(bar PUBLIC "-O0") 26 | 27 | if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "5.0.0" OR 28 | CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "5.0.0") 29 | target_compile_options(bar PUBLIC -Xclang -disable-O0-optnone) 30 | endif() 31 | 32 | set_target_properties(bar PROPERTIES 33 | CXX_STANDARD 11 34 | CXX_EXTENSIONS OFF) 35 | 36 | # attachments on first target 37 | 38 | llvmir_attach_bc_target(bar_bc bar) 39 | 40 | llvmir_attach_opt_pass_target(bar_pass1 bar_bc -mem2reg) 41 | llvmir_attach_opt_pass_target(bar_pass2 bar_pass1 -simplifycfg -licm) 42 | llvmir_attach_opt_pass_target(bar_pass3 bar_pass2 -licm) 43 | 44 | llvmir_attach_disassemble_target(bar_dis bar_pass2) 45 | llvmir_attach_assemble_target(bar_as bar_dis) 46 | 47 | llvmir_attach_link_target(bar_llvmlink bar_pass2) 48 | 49 | llvmir_attach_opt_pass_target(bar_pass4 bar_llvmlink -simplifycfg) 50 | 51 | llvmir_attach_library(bar_bc_lib bar_pass2 SHARED) 52 | 53 | 54 | -------------------------------------------------------------------------------- /example03/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # cmake file 2 | 3 | # options 4 | 5 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath /lib") 6 | 7 | # general defs 8 | 9 | set(SOURCES 10 | bar.cpp) 11 | 12 | 13 | # directory level 14 | 15 | 16 | # target level 17 | 18 | add_library(bar ${SOURCES}) 19 | 20 | # this property is required by our parasitic targets 21 | set_target_properties(bar PROPERTIES LINKER_LANGUAGE CXX) 22 | 23 | target_include_directories(bar PUBLIC "../include") 24 | 25 | target_compile_options(bar PUBLIC "-O0") 26 | 27 | if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "5.0.0" OR 28 | CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "5.0.0") 29 | target_compile_options(bar PUBLIC -Xclang -disable-O0-optnone) 30 | endif() 31 | 32 | set_target_properties(bar PROPERTIES 33 | CXX_STANDARD 11 34 | CXX_EXTENSIONS OFF) 35 | 36 | # attachments on first target 37 | 38 | llvmir_attach_bc_target( 39 | TARGET bar_bc 40 | DEPENDS bar) 41 | 42 | llvmir_attach_opt_pass_target( 43 | TARGET bar_pass1 44 | DEPENDS bar_bc -mem2reg) 45 | 46 | llvmir_attach_opt_pass_target( 47 | TARGET bar_pass2 48 | DEPENDS bar_pass1 -simplifycfg -licm) 49 | 50 | llvmir_attach_opt_pass_target( 51 | TARGET bar_pass3 52 | DEPENDS bar_pass2 -licm) 53 | 54 | llvmir_attach_disassemble_target( 55 | TARGET bar_dis 56 | DEPENDS bar_pass2) 57 | 58 | llvmir_attach_assemble_target( 59 | TARGET bar_as 60 | DEPENDS bar_dis) 61 | 62 | llvmir_attach_link_target( 63 | TARGET bar_llvmlink 64 | DEPENDS bar_pass2) 65 | 66 | llvmir_attach_opt_pass_target( 67 | TARGET bar_pass4 68 | DEPENDS bar_llvmlink -simplifycfg) 69 | 70 | llvmir_attach_library( 71 | TARGET bar_bc_lib 72 | DEPENDS bar_pass2 SHARED) 73 | 74 | 75 | -------------------------------------------------------------------------------- /example01/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # cmake file 2 | 3 | # general defs 4 | 5 | set(SOURCES 6 | foo.cpp 7 | bar.cpp) 8 | 9 | 10 | # directory level 11 | 12 | add_definitions(-DDIR_FOO=1) 13 | 14 | include_directories("../include/general") 15 | 16 | 17 | # target level 18 | 19 | add_executable(qux ${SOURCES}) 20 | #add_library(qux ${SOURCES}) 21 | 22 | # this property is required by our parasitic targets 23 | set_target_properties(qux PROPERTIES LINKER_LANGUAGE CXX) 24 | 25 | target_compile_definitions(qux PUBLIC TARGET_PUB_FOO=2) 26 | target_compile_definitions(qux PRIVATE TARGET_PRIV_FOO=3) 27 | 28 | # this seems not to be used in add_executable/add_library 29 | #target_compile_definitions(qux INTERFACE TARGET_IF_FOO=4) 30 | target_compile_definitions(qux PUBLIC TARGET_IF_FOO=4) 31 | 32 | target_compile_options(qux PUBLIC -O0) 33 | 34 | if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "5.0.0" OR 35 | CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "5.0.0") 36 | target_compile_options(qux PUBLIC -Xclang -disable-O0-optnone) 37 | endif() 38 | 39 | target_compile_options(qux PUBLIC -Wnonnull) 40 | target_compile_options(qux PRIVATE -Wfloat-conversion) 41 | target_compile_options(qux INTERFACE -Wpedantic) 42 | 43 | target_include_directories(qux PRIVATE "../include/detail") 44 | target_include_directories(qux PUBLIC "../include") 45 | 46 | 47 | # attachments on first target 48 | 49 | llvmir_attach_bc_target(qux_bc qux) 50 | add_dependencies(qux_bc qux) 51 | 52 | llvmir_attach_opt_pass_target(qux_pass1 qux_bc -mem2reg) 53 | add_dependencies(qux_pass1 qux_bc) 54 | 55 | llvmir_attach_opt_pass_target(qux_pass2 qux_pass1 -simplifycfg -licm) 56 | add_dependencies(qux_pass2 qux_pass1) 57 | 58 | llvmir_attach_opt_pass_target(qux_pass3 qux_pass2 -licm) 59 | add_dependencies(qux_pass3 qux_pass2) 60 | 61 | llvmir_attach_disassemble_target(qux_dis qux_pass2) 62 | add_dependencies(qux_dis qux_pass2) 63 | 64 | llvmir_attach_assemble_target(qux_as qux_dis) 65 | add_dependencies(qux_as qux_dis) 66 | 67 | llvmir_attach_link_target(qux_llvmlink qux_pass2) 68 | add_dependencies(qux_llvmlink qux_pass2) 69 | 70 | llvmir_attach_opt_pass_target(qux_pass4 qux_llvmlink -simplifycfg) 71 | add_dependencies(qux_pass4 qux_llvmlink) 72 | 73 | llvmir_attach_executable(qux_bc_exe qux_pass4) 74 | add_dependencies(qux_bc_exe qux_pass4) 75 | 76 | llvmir_attach_executable(qux_bc_exe2 qux_pass2) 77 | add_dependencies(qux_bc_exe2 qux_pass2) 78 | 79 | llvmir_attach_library(qux_bc_lib qux_pass2 SHARED) 80 | add_dependencies(qux_bc_lib qux_pass2) 81 | 82 | 83 | add_custom_target(qux_pipeline1 DEPENDS 84 | qux_pass1) 85 | 86 | add_custom_target(qux_pipeline2 DEPENDS 87 | qux_pass2) 88 | 89 | set_property(TARGET qux_pipeline2 PROPERTY EXCLUDE_FROM_ALL OFF) 90 | 91 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LLVM IR cmake utilities 2 | 3 | ## Introduction 4 | 5 | A collection of helper `cmake` functions/macros that eases the generation of `LLVM` IR and the application of various 6 | `LLVM` `opt` passes while obtaining and preserving the separate IR files that are generated by each user-defined step. 7 | 8 | ## Requirements 9 | 10 | - [`cmake`][1] 3.0.0 or later 11 | - [`LLVM`][2] tools: 12 | - Currently used: 13 | - `clang/clang++` 14 | - `opt` 15 | - `llvm-dis` / `llvm-as` 16 | - `llvm-link` 17 | - Tested with: 18 | - 3.7 and later 19 | 20 | ## Installation 21 | 22 | - Clone this repo (or even add it as a submodule to your project). 23 | - In your `CMakeLists.txt` file `include(LLVMIRUtil)`. 24 | - You are good to go! 25 | 26 | ## Quick overview 27 | 28 | The provided `cmake` commands are expected to work in a parasitic way to targets created via `add_executable()` and 29 | `add_library`. The "gateway" command is `llvmir_attach_bc_target()` which generates the required bitcode files. 30 | Currently, `C/C++` are supported via `clang/clang++`, but in theory any compiler which produces `LLVM` bitcode should be 31 | easily supported (depending how nice it plays with `cmake` too). 32 | 33 | The `cmake` calls currently provided are: 34 | 35 | - `llvmir_attach_bc_target()` 36 | Attaches to an existing target that can be compiled down to `LLVM IR` and does just that, using all the related flags 37 | and options from the main target. The existing supported targets make use of `clang/clang++`, so currently this means 38 | that the `C/C++` language is supported. It uses `add_custom_library()` `cmake` command under the hood. This creates a 39 | target of type `LLVMIR`. 40 | 41 | - `llvmir_attach_opt_pass_target()` 42 | Attaches to a target of type `LLVMIR` and applies various `opt` passes to its bitcode files, specified as arguments. 43 | It uses `add_custom_library()` `cmake` command under the hood. This creates a target of type `LLVMIR`. 44 | 45 | - `llvmir_attach_disassemble_target()` 46 | Attaches to a target of type `LLVMIR` and uses `llvm-dis` to disassemble its bitcode files. It uses 47 | `add_custom_library()` `cmake` command under the hood. This creates a target of type `LLVMIR`. 48 | 49 | - `llvmir_attach_assemble_target()` 50 | Attaches to a target of type `LLVMIR` and uses `llvm-as` to assemble its bitcode files. It uses `add_custom_library()` 51 | `cmake` command under the hood. This creates a target of type `LLVMIR`. 52 | 53 | - `llvmir_attach_link_target()` 54 | Attaches to a target of type `LLVMIR` and uses `llvm-link` to link its bitcode files to a single bitcode file. The 55 | output bitcode file is names after the target name. It uses `add_custom_library()` `cmake` command under the hood. 56 | This creates a target of type `LLVMIR`. 57 | 58 | - `llvmir_attach_library()` 59 | Attaches to a target of type `LLVMIR` and uses the appropriate compiler to compile its bitcode files to a native 60 | library. The output library name uses the target name according to platform rules. It uses `add_library()` `cmake` 61 | command under the hood. This creates a target of type `LLVMIR`. 62 | 63 | - `llvmir_attach_executable()` 64 | Attaches to a target of type `LLVMIR` and uses the appropriate compiler to compile its bitcode files to a native 65 | executable. The output library name uses the target name according to platform rules. It uses `add_executable()` 66 | `cmake` command under the hood. This creates a target of type `LLVMIR`. 67 | 68 | ### Influential properties 69 | 70 | - `LLVMIR_SHORT_NAME` 71 | This property, if present, controls the output name for the calls that produce a single object (e.g. archive, library, 72 | etc.): 73 | - `llvmir_attach_link_target()` 74 | - `llvmir_attach_library()` 75 | - `llvmir_attach_executable()` 76 | 77 | 78 | _CAUTION_ 79 | 80 | If you require to get raw _unoptimized_ `LLVM` IR, but with the ability to further optimize it later on and you are 81 | compiling with `LLVM` 5 or later, you need to add the following compile options, either: 82 | 83 | ```bash 84 | -O1 -Xclang -disable-llvm-passes 85 | ``` 86 | 87 | or 88 | 89 | ```bash 90 | -O0 -Xclang -disable-O0-optnone 91 | ``` 92 | 93 | This is because, since `LLVM` 5, using `-O0` add the `optnone` attribute to all functions. 94 | 95 | ## Basic Usage 96 | 97 | Have a look and toy around with the included examples in this repo. The easiest way to start is: 98 | 99 | 1. `git clone` this repo. 100 | 2. Create a directory for an out-of-source build and `cd` into it. 101 | 3. `CC=clang CXX=clang++ cmake [path to example source dir]` 102 | 4. `cmake --build .` 103 | 5. `cmake --build . --target help` to see available target and use them for bitcode generation. 104 | 105 | [1]: https://cmake.org 106 | 107 | [2]: www.llvm.org 108 | -------------------------------------------------------------------------------- /cmake/LLVMIRUtilInternal.cmake: -------------------------------------------------------------------------------- 1 | 2 | # internal utility macros/functions 3 | 4 | include(CMakeParseArguments) 5 | 6 | function(debug message_txt) 7 | if($ENV{LLVMIR_CMAKE_DEBUG}) 8 | message(STATUS "[DEBUG] ${message_txt}") 9 | endif() 10 | endfunction() 11 | 12 | 13 | macro(catuniq lst) 14 | list(APPEND ${lst} ${ARGN}) 15 | if(${lst}) 16 | list(REMOVE_DUPLICATES ${lst}) 17 | endif() 18 | endmacro() 19 | 20 | 21 | # internal implementation detail macros/functions 22 | 23 | macro(llvmir_setup) 24 | set(LLVMIR_DIR "llvm-ir") 25 | 26 | set(LLVMIR_COMPILER "") 27 | set(LLVMIR_OPT "opt") 28 | set(LLVMIR_LINK "llvm-link") 29 | set(LLVMIR_ASSEMBLER "llvm-as") 30 | set(LLVMIR_DISASSEMBLER "llvm-dis") 31 | 32 | set(LLVMIR_BINARY_FMT_SUFFIX "bc") 33 | set(LLVMIR_TEXT_FMT_SUFFIX "ll") 34 | 35 | set(LLVMIR_BINARY_TYPE "LLVMIR_BINARY") 36 | set(LLVMIR_TEXT_TYPE "LLVMIR_TEXT") 37 | set(LLVMIR_OBJECT_TYPE "LLVMIR_OBJECT") 38 | 39 | set(LLVMIR_TYPES ${LLVMIR_BINARY_TYPE} ${LLVMIR_TEXT_TYPE}) 40 | set(LLVMIR_FMT_SUFFICES ${LLVMIR_BINARY_FMT_SUFFIX} ${LLVMIR_TEXT_FMT_SUFFIX}) 41 | 42 | set(LLVMIR_COMPILER_IDS "Clang" "AppleClang") 43 | 44 | message(STATUS "LLVM IR Utils") 45 | 46 | define_property(TARGET PROPERTY LLVMIR_TYPE 47 | BRIEF_DOCS "type of LLVM IR file" 48 | FULL_DOCS "type of LLVM IR file") 49 | define_property(TARGET PROPERTY LLVMIR_DIR 50 | BRIEF_DOCS "Input /output directory for LLVM IR files" 51 | FULL_DOCS "Input /output directory for LLVM IR files") 52 | define_property(TARGET PROPERTY LLVMIR_FILES 53 | BRIEF_DOCS "list of LLVM IR files" 54 | FULL_DOCS "list of LLVM IR files") 55 | endmacro() 56 | 57 | 58 | macro(llvmir_set_compiler linker_language) 59 | if("${LLVMIR_COMPILER}" STREQUAL "") 60 | set(LLVMIR_COMPILER ${CMAKE_${linker_language}_COMPILER}) 61 | set(LLVMIR_COMPILER_ID ${CMAKE_${linker_language}_COMPILER_ID}) 62 | 63 | list(FIND LLVMIR_COMPILER_IDS ${LLVMIR_COMPILER_ID} found) 64 | 65 | if(found EQUAL -1) 66 | message(FATAL_ERROR "LLVM IR compiler ID ${LLVMIR_COMPILER_ID} is not in \ 67 | ${LLVMIR_COMPILER_IDS}") 68 | endif() 69 | endif() 70 | endmacro() 71 | 72 | 73 | function(llvmir_check_target_properties_impl) 74 | set(options) 75 | set(oneValueArgs TARGET RESULT_VARIABLE) 76 | set(multiValueArgs PROPERTIES) 77 | cmake_parse_arguments(CTP 78 | "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) 79 | 80 | # argument checks 81 | 82 | if(NOT CTP_TARGET) 83 | message(FATAL_ERROR "Missing TARGET option.") 84 | endif() 85 | 86 | if(NOT CTP_RESULT_VARIABLE) 87 | message(FATAL_ERROR "Missing RESULT_VARIABLE option.") 88 | endif() 89 | 90 | if(NOT CTP_PROPERTIES) 91 | message(FATAL_ERROR "Missing PROPERTIES option.") 92 | endif() 93 | 94 | if(CTP_UNPARSED_ARGUMENTS) 95 | message(FATAL_ERROR "Extraneous arguments ${CTP_UNPARSED_ARGUMENTS}.") 96 | endif() 97 | 98 | if(NOT TARGET ${CTP_TARGET}) 99 | message(FATAL_ERROR "Cannot attach to non-existing target: ${CTP_TARGET}.") 100 | endif() 101 | 102 | set(_RESULT_VARIABLE 0) 103 | 104 | foreach(prop ${CTP_PROPERTIES}) 105 | # equivalent to 106 | # if(DEFINED prop AND prop STREQUAL "") 107 | set(is_def TRUE) 108 | set(is_set TRUE) 109 | 110 | # this seems to not be working for targets defined with builtins 111 | #get_property(is_def TARGET ${CTP_TARGET} PROPERTY ${prop} DEFINED) 112 | 113 | get_property(is_set TARGET ${CTP_TARGET} PROPERTY ${prop} SET) 114 | 115 | if(NOT is_def) 116 | message(WARNING "property ${prop} for target ${CTP_TARGET} \ 117 | must be defined.") 118 | set(_RESULT_VARIABLE 1) 119 | endif() 120 | 121 | if(NOT is_set) 122 | message(WARNING "property ${prop} for target ${CTP_TARGET} must be set.") 123 | set(_RESULT_VARIABLE 2) 124 | endif() 125 | endforeach() 126 | 127 | set(${CTP_RESULT_VARIABLE} ${_RESULT_VARIABLE} PARENT_SCOPE) 128 | endfunction() 129 | 130 | 131 | function(llvmir_check_non_llvmir_target_properties trgt) 132 | set(props SOURCES LINKER_LANGUAGE) 133 | 134 | llvmir_check_target_properties_impl( 135 | TARGET ${trgt} 136 | PROPERTIES ${props} 137 | RESULT_VARIABLE RC) 138 | 139 | if(RC) 140 | message(FATAL_ERROR "Target ${trgt} is missing required properties.") 141 | endif() 142 | endfunction() 143 | 144 | 145 | function(llvmir_check_target_properties trgt) 146 | set(props LINKER_LANGUAGE LLVMIR_DIR LLVMIR_FILES LLVMIR_TYPE) 147 | 148 | llvmir_check_target_properties_impl( 149 | TARGET ${trgt} 150 | PROPERTIES ${props} 151 | RESULT_VARIABLE RC) 152 | 153 | if(RC) 154 | message(FATAL_ERROR "Target ${trgt} is missing required properties.\ 155 | It might not be a LLVMIR target.") 156 | endif() 157 | endfunction() 158 | 159 | 160 | function(llvmir_extract_compile_defs_properties out_compile_defs from) 161 | set(defs "") 162 | set(compile_defs "") 163 | set(prop_name "COMPILE_DEFINITIONS") 164 | 165 | # per directory 166 | get_property(defs DIRECTORY PROPERTY ${prop_name}) 167 | foreach(def ${defs}) 168 | list(APPEND compile_defs -D${def}) 169 | endforeach() 170 | 171 | get_property(defs DIRECTORY PROPERTY ${prop_name}_${CMAKE_BUILD_TYPE}) 172 | foreach(def ${defs}) 173 | list(APPEND compile_defs -D${def}) 174 | endforeach() 175 | 176 | # per target 177 | if(TARGET ${from}) 178 | get_property(defs TARGET ${from} PROPERTY ${prop_name}) 179 | foreach(def ${defs}) 180 | list(APPEND compile_defs -D${def}) 181 | endforeach() 182 | 183 | get_property(defs TARGET ${from} PROPERTY ${prop_name}_${CMAKE_BUILD_TYPE}) 184 | foreach(def ${defs}) 185 | list(APPEND compile_defs -D${def}) 186 | endforeach() 187 | 188 | get_property(defs TARGET ${from} PROPERTY INTERFACE_${prop_name}) 189 | foreach(def ${defs}) 190 | list(APPEND compile_defs -D${def}) 191 | endforeach() 192 | else() 193 | # per file 194 | get_property(defs SOURCE ${from} PROPERTY ${prop_name}) 195 | foreach(def ${defs}) 196 | list(APPEND compile_defs -D${def}) 197 | endforeach() 198 | 199 | get_property(defs SOURCE ${from} PROPERTY ${prop_name}_${CMAKE_BUILD_TYPE}) 200 | foreach(def ${defs}) 201 | list(APPEND compile_defs -D${def}) 202 | endforeach() 203 | endif() 204 | 205 | list(REMOVE_DUPLICATES compile_defs) 206 | 207 | debug("@llvmir_extract_compile_defs_properties ${from}: ${compile_defs}") 208 | 209 | set(${out_compile_defs} ${compile_defs} PARENT_SCOPE) 210 | endfunction() 211 | 212 | 213 | function(llvmir_extract_compile_option_properties out_compile_options trgt) 214 | set(options "") 215 | set(compile_options "") 216 | set(prop_name "COMPILE_OPTIONS") 217 | 218 | # per directory 219 | get_property(options DIRECTORY PROPERTY ${prop_name}) 220 | foreach(opt ${options}) 221 | list(APPEND compile_options ${opt}) 222 | endforeach() 223 | 224 | # per target 225 | get_property(options TARGET ${trgt} PROPERTY ${prop_name}) 226 | foreach(opt ${options}) 227 | list(APPEND compile_options ${opt}) 228 | endforeach() 229 | 230 | get_property(options TARGET ${trgt} PROPERTY INTERFACE_${prop_name}) 231 | foreach(opt ${options}) 232 | list(APPEND compile_options ${opt}) 233 | endforeach() 234 | 235 | list(REMOVE_DUPLICATES compile_options) 236 | 237 | debug("@llvmir_extract_compile_option_properties ${trgt}: ${compile_options}") 238 | 239 | set(${out_compile_options} ${compile_options} PARENT_SCOPE) 240 | endfunction() 241 | 242 | 243 | function(llvmir_extract_include_dirs_properties out_include_dirs trgt) 244 | set(dirs "") 245 | set(prop_name "INCLUDE_DIRECTORIES") 246 | 247 | # per directory 248 | get_property(dirs DIRECTORY PROPERTY ${prop_name}) 249 | foreach(dir ${dirs}) 250 | list(APPEND include_dirs -I${dir}) 251 | endforeach() 252 | 253 | # per target 254 | get_property(dirs TARGET ${trgt} PROPERTY ${prop_name}) 255 | foreach(dir ${dirs}) 256 | list(APPEND include_dirs -I${dir}) 257 | endforeach() 258 | 259 | get_property(dirs TARGET ${trgt} PROPERTY INTERFACE_${prop_name}) 260 | foreach(dir ${dirs}) 261 | list(APPEND include_dirs -I${dir}) 262 | endforeach() 263 | 264 | get_property(dirs TARGET ${trgt} PROPERTY INTERFACE_SYSTEM_${prop_name}) 265 | foreach(dir ${dirs}) 266 | list(APPEND include_dirs -I${dir}) 267 | endforeach() 268 | 269 | if(include_dirs) 270 | list(REMOVE_DUPLICATES include_dirs) 271 | endif() 272 | 273 | debug("@llvmir_extract_include_dirs_properties ${trgt}: ${include_dirs}") 274 | 275 | set(${out_include_dirs} ${include_dirs} PARENT_SCOPE) 276 | endfunction() 277 | 278 | 279 | function(llvmir_extract_lang_flags out_lang_flags lang) 280 | set(lang_flags "") 281 | 282 | set(lang_flags ${CMAKE_${lang}_FLAGS_${CMAKE_BUILD_TYPE}}) 283 | set(lang_flags "${lang_flags} ${CMAKE_${lang}_FLAGS}") 284 | 285 | string(REPLACE "\ " ";" lang_flags ${lang_flags}) 286 | 287 | debug("@llvmir_extract_lang_flags ${lang}: ${lang_flags}") 288 | 289 | set(${out_lang_flags} ${lang_flags} PARENT_SCOPE) 290 | endfunction() 291 | 292 | 293 | function(llvmir_extract_standard_flags out_standard_flags trgt lang) 294 | set(standard_flags "") 295 | set(std_prop "${lang}_STANDARD") 296 | set(ext_prop "${lang}_EXTENSIONS") 297 | 298 | get_property(std TARGET ${trgt} PROPERTY ${std_prop}) 299 | get_property(ext TARGET ${trgt} PROPERTY ${ext_prop}) 300 | 301 | set(lang_prefix "") 302 | 303 | if(std) 304 | if(ext) 305 | set(lang_prefix "gnu") 306 | else() 307 | string(TOLOWER ${lang} lang_prefix) 308 | endif() 309 | endif() 310 | 311 | if(lang_prefix STREQUAL "cxx") 312 | set(lang_prefix "c++") 313 | endif() 314 | 315 | set(flag "${lang_prefix}${std}") 316 | 317 | if(flag) 318 | set(standard_flags "-std=${flag}") 319 | endif() 320 | 321 | debug("@llvmir_extract_standard_flags ${lang}: ${standard_flags}") 322 | 323 | set(${out_standard_flags} ${standard_flags} PARENT_SCOPE) 324 | endfunction() 325 | 326 | 327 | function(llvmir_extract_compile_flags out_compile_flags from) 328 | set(compile_flags "") 329 | set(prop_name "COMPILE_FLAGS") 330 | 331 | if(TARGET ${from}) 332 | get_property(compile_flags TARGET ${from} PROPERTY ${prop_name}) 333 | else() 334 | get_property(compile_flags SOURCE ${from} PROPERTY ${prop_name}) 335 | endif() 336 | 337 | # deprecated according to cmake docs 338 | if(NOT "${compile_flags}" STREQUAL "") 339 | message(WARNING "COMPILE_FLAGS property is deprecated.") 340 | endif() 341 | 342 | debug("@llvmir_extract_compile_flags ${from}: ${compile_flags}") 343 | 344 | set(${out_compile_flags} ${compile_flags} PARENT_SCOPE) 345 | endfunction() 346 | 347 | 348 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | (This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.) 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | {description} 474 | Copyright (C) {year} {fullname} 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 489 | USA 490 | 491 | Also add information on how to contact you by electronic and paper mail. 492 | 493 | You should also get your employer (if you work as a programmer) or your 494 | school, if any, to sign a "copyright disclaimer" for the library, if 495 | necessary. Here is a sample; alter the names: 496 | 497 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 498 | library `Frob' (a library for tweaking knobs) written by James Random 499 | Hacker. 500 | 501 | {signature of Ty Coon}, 1 April 1990 502 | Ty Coon, President of Vice 503 | 504 | That's all there is to it! 505 | -------------------------------------------------------------------------------- /cmake/LLVMIRUtil.cmake: -------------------------------------------------------------------------------- 1 | #.rst: 2 | #LLVM-IR-Util 3 | # ------------- 4 | # 5 | # LLVM IR utils for cmake 6 | 7 | cmake_minimum_required(VERSION 3.0.0) 8 | 9 | include(CMakeParseArguments) 10 | 11 | include(LLVMIRUtilInternal) 12 | 13 | ### 14 | 15 | llvmir_setup() 16 | 17 | ### 18 | 19 | 20 | # public (client) interface macros/functions 21 | 22 | function(llvmir_attach_bc_target) 23 | set(options ATTACH_TO_DEPENDENT_STATIC_LIBS) 24 | set(oneValueArgs TARGET DEPENDS) 25 | set(multiValueArgs) 26 | cmake_parse_arguments(LLVMIR_ATTACH 27 | "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) 28 | 29 | set(TRGT ${LLVMIR_ATTACH_TARGET}) 30 | set(DEPENDS_TRGT ${LLVMIR_ATTACH_DEPENDS}) 31 | 32 | # fallback to backwards compatible mode for argument parsing 33 | if(NOT TRGT AND NOT DEPENDS_TRGT) 34 | set(TRGT ${ARGV0}) 35 | set(DEPENDS_TRGT ${ARGV1}) 36 | 37 | if(${ARGC} GREATER 3) 38 | message(FATAL_ERROR "llvmir_attach_bc_target: \ 39 | extraneous arguments provided") 40 | endif() 41 | else() 42 | if(LLVMIR_ATTACH_UNPARSED_ARGUMENTS) 43 | message(FATAL_ERROR "llvmir_attach_bc_target: \ 44 | extraneous arguments provided") 45 | endif() 46 | endif() 47 | 48 | if(NOT TRGT) 49 | message(FATAL_ERROR "llvmir_attach_bc_target: missing TARGET option") 50 | endif() 51 | 52 | if(NOT DEPENDS_TRGT) 53 | message(FATAL_ERROR "llvmir_attach_bc_target: missing DEPENDS option") 54 | endif() 55 | 56 | ## preamble 57 | set(OUT_LLVMIR_FILES "") 58 | set(FULL_OUT_LLVMIR_FILES "") 59 | 60 | llvmir_check_non_llvmir_target_properties(${DEPENDS_TRGT}) 61 | 62 | # the 3.x and above INTERFACE_SOURCES does not participate in the compilation 63 | # of a target 64 | 65 | # if the property does not exist the related variable is not defined 66 | get_property(IN_FILES TARGET ${DEPENDS_TRGT} PROPERTY SOURCES) 67 | get_property(LINKER_LANGUAGE TARGET ${DEPENDS_TRGT} PROPERTY LINKER_LANGUAGE) 68 | get_property(EXTERNAL_TYPE TARGET ${DEPENDS_TRGT} PROPERTY TYPE) 69 | get_property(LINK_DEPENDS TARGET ${DEPENDS_TRGT} PROPERTY LINK_DEPENDS) 70 | get_property(LINK_FLAGS TARGET ${DEPENDS_TRGT} PROPERTY LINK_FLAGS) 71 | get_property(LINK_FLAGS_${CMAKE_BUILD_TYPE} 72 | TARGET ${DEPENDS_TRGT} 73 | PROPERTY LINK_FLAGS_${CMAKE_BUILD_TYPE}) 74 | get_property(INTERFACE_LINK_LIBRARIES 75 | TARGET ${DEPENDS_TRGT} 76 | PROPERTY INTERFACE_LINK_LIBRARIES) 77 | get_property(LINK_LIBRARIES TARGET ${DEPENDS_TRGT} PROPERTY LINK_LIBRARIES) 78 | get_property(LINK_INTERFACE_LIBRARIES 79 | TARGET ${DEPENDS_TRGT} 80 | PROPERTY LINK_INTERFACE_LIBRARIES) 81 | get_property(LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE} 82 | TARGET ${DEPENDS_TRGT} 83 | PROPERTY LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE}) 84 | get_property(SHORT_NAME TARGET ${DEPENDS_TRGT} PROPERTY LLVMIR_SHORT_NAME) 85 | 86 | debug( 87 | "@llvmir_attach_bc_target ${DEPENDS_TRGT} linker lang: ${LINKER_LANGUAGE}") 88 | 89 | llvmir_set_compiler(${LINKER_LANGUAGE}) 90 | 91 | ## command options 92 | set(WORK_DIR "${CMAKE_CURRENT_BINARY_DIR}/${LLVMIR_DIR}/${TRGT}") 93 | file(MAKE_DIRECTORY ${WORK_DIR}) 94 | 95 | # compile definitions 96 | llvmir_extract_compile_defs_properties(IN_DEFS ${DEPENDS_TRGT}) 97 | 98 | # includes 99 | llvmir_extract_include_dirs_properties(IN_INCLUDES ${DEPENDS_TRGT}) 100 | 101 | # language standards flags 102 | llvmir_extract_standard_flags(IN_STANDARD_FLAGS 103 | ${DEPENDS_TRGT} ${LINKER_LANGUAGE}) 104 | 105 | # compile options 106 | llvmir_extract_compile_option_properties(IN_COMPILE_OPTIONS ${DEPENDS_TRGT}) 107 | 108 | # compile flags 109 | llvmir_extract_compile_flags(IN_COMPILE_FLAGS ${DEPENDS_TRGT}) 110 | 111 | # compile lang flags 112 | llvmir_extract_lang_flags(IN_LANG_FLAGS ${LINKER_LANGUAGE}) 113 | 114 | # Link static libraries 115 | if(LLVMIR_ATTACH_ATTACH_TO_DEPENDENT_STATIC_LIBS) 116 | message(STATUS "ATTACH_TO_DEPENDENT_STATIC_LIBS option is turned on. Attaching to dependent static libraries of target ${TRGT}.") 117 | 118 | # Find statically linked libraries, and add the source files for IR generation 119 | foreach(LINK_LIB ${LINK_LIBRARIES}) 120 | if(TARGET ${LINK_LIB}) 121 | get_target_property(type ${LINK_LIB} TYPE) 122 | 123 | # Check the library is a static one. For shared libraries, we cannot get the source files for compiling. 124 | if(${type} STREQUAL "STATIC_LIBRARY") 125 | get_property(LINK_LIB_FILES TARGET ${LINK_LIB} PROPERTY SOURCES) 126 | message(STATUS "Attaching to dependent static library ${LINK_LIB} of target ${TRGT}.") 127 | 128 | foreach(LINK_LIB_FILE ${LINK_LIB_FILES}) 129 | if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${LINK_LIB_FILE}") 130 | list(APPEND IN_FILES ${LINK_LIB_FILE}) 131 | message(STATUS "Add file from static library: ${LINK_LIB_FILE}") 132 | endif() 133 | endforeach() 134 | endif() 135 | endif() 136 | endforeach() 137 | 138 | list(REMOVE_DUPLICATES IN_FILES) 139 | endif() 140 | 141 | set(header_exts ".h;.hh;.hpp;.h++;.hxx") 142 | set(temp_include_dirs "") 143 | 144 | # Find all header files in the source 145 | foreach(IN_FILE ${IN_FILES}) 146 | get_filename_component(FILE_EXT ${IN_FILE} LAST_EXT) 147 | get_filename_component(FILE_DIR ${IN_FILE} DIRECTORY) 148 | string(TOLOWER ${FILE_EXT} FILE_EXT) 149 | list(FIND header_exts ${FILE_EXT} _index) 150 | 151 | if(${_index} GREATER -1) 152 | message(WARNING "A header file ${IN_FILE} is found in source files! Please add header directories using target_include_directories() instead.") 153 | 154 | # Add to include list 155 | list(APPEND temp_include_dirs "-I${FILE_DIR}") 156 | endif() 157 | endforeach() 158 | 159 | if(temp_include_dirs) 160 | list(REMOVE_DUPLICATES temp_include_dirs) 161 | message(WARNING "\"${temp_include_dirs}\" added to include directories.") 162 | 163 | list(APPEND IN_INCLUDES ${temp_include_dirs}) 164 | list(REMOVE_DUPLICATES IN_INCLUDES) 165 | endif() 166 | 167 | # main operations 168 | foreach(IN_FILE ${IN_FILES}) 169 | get_target_property(SOURCE_DIR ${DEPENDS_TRGT} SOURCE_DIR) 170 | get_filename_component(ABS_IN_FILE ${IN_FILE} ABSOLUTE BASE_DIR ${SOURCE_DIR}) 171 | 172 | # Skip header files 173 | get_filename_component(FILE_EXT ${ABS_IN_FILE} LAST_EXT) 174 | string(TOLOWER ${FILE_EXT} FILE_EXT) 175 | 176 | list (FIND header_exts ${FILE_EXT} _index) 177 | if(${_index} GREATER -1) 178 | continue() 179 | endif() 180 | 181 | get_filename_component(OUTFILE ${ABS_IN_FILE} NAME) 182 | set(OUT_LLVMIR_FILE "${OUTFILE}.${LLVMIR_BINARY_FMT_SUFFIX}") 183 | set(FULL_OUT_LLVMIR_FILE "${WORK_DIR}/${OUT_LLVMIR_FILE}") 184 | 185 | # compile definitions per source file 186 | llvmir_extract_compile_defs_properties(IN_FILE_DEFS ${ABS_IN_FILE}) 187 | 188 | # compile flags per source file 189 | llvmir_extract_lang_flags(IN_FILE_COMPILE_FLAGS ${ABS_IN_FILE}) 190 | 191 | # stitch all args together 192 | catuniq(CURRENT_DEFS ${IN_DEFS} ${IN_FILE_DEFS}) 193 | debug("@llvmir_attach_bc_target ${DEPENDS_TRGT} defs: ${CURRENT_DEFS}") 194 | 195 | catuniq(CURRENT_COMPILE_FLAGS ${IN_COMPILE_FLAGS} ${IN_FILE_COMPILE_FLAGS}) 196 | debug("@llvmir_attach_bc_target ${DEPENDS_TRGT} compile flags: \ 197 | ${CURRENT_COMPILE_FLAGS}") 198 | 199 | set(CMD_ARGS "-emit-llvm" ${IN_STANDARD_FLAGS} ${IN_LANG_FLAGS} 200 | ${IN_COMPILE_OPTIONS} ${CURRENT_COMPILE_FLAGS} ${CURRENT_DEFS} 201 | ${IN_INCLUDES}) 202 | 203 | add_custom_command(OUTPUT ${FULL_OUT_LLVMIR_FILE} 204 | COMMAND ${LLVMIR_COMPILER} 205 | ARGS ${CMD_ARGS} -c ${ABS_IN_FILE} -o ${FULL_OUT_LLVMIR_FILE} 206 | DEPENDS ${ABS_IN_FILE} 207 | IMPLICIT_DEPENDS ${LINKER_LANGUAGE} ${ABS_IN_FILE} 208 | COMMENT "Generating LLVM bitcode ${OUT_LLVMIR_FILE}" 209 | VERBATIM) 210 | 211 | list(APPEND OUT_LLVMIR_FILES ${OUT_LLVMIR_FILE}) 212 | list(APPEND FULL_OUT_LLVMIR_FILES ${FULL_OUT_LLVMIR_FILE}) 213 | endforeach() 214 | 215 | ## postamble 216 | 217 | # setup custom target 218 | add_custom_target(${TRGT} DEPENDS ${FULL_OUT_LLVMIR_FILES}) 219 | 220 | set_property(TARGET ${TRGT} PROPERTY LLVMIR_TYPE ${LLVMIR_BINARY_TYPE}) 221 | set_property(TARGET ${TRGT} PROPERTY LLVMIR_EXTERNAL_TYPE ${EXTERNAL_TYPE}) 222 | set_property(TARGET ${TRGT} PROPERTY LLVMIR_DIR ${WORK_DIR}) 223 | set_property(TARGET ${TRGT} PROPERTY LLVMIR_FILES ${OUT_LLVMIR_FILES}) 224 | set_property(TARGET ${TRGT} PROPERTY LINKER_LANGUAGE ${LINKER_LANGUAGE}) 225 | set_property(TARGET ${TRGT} PROPERTY LINK_DEPENDS ${LINK_DEPENDS}) 226 | set_property(TARGET ${TRGT} PROPERTY LINK_FLAGS ${LINK_FLAGS}) 227 | set_property(TARGET ${TRGT} 228 | PROPERTY LINK_FLAGS_${CMAKE_BUILD_TYPE} ${LINK_FLAGS_${CMAKE_BUILD_TYPE}}) 229 | set_property(TARGET ${TRGT} 230 | PROPERTY INTERFACE_LINK_LIBRARIES ${INTERFACE_LINK_LIBRARIES}) 231 | set_property(TARGET ${TRGT} 232 | PROPERTY LINK_INTERFACE_LIBRARIES ${LINK_INTERFACE_LIBRARIES}) 233 | set_property(TARGET ${TRGT} 234 | PROPERTY 235 | LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE} 236 | ${LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE}}) 237 | set_property(TARGET ${TRGT} PROPERTY EXCLUDE_FROM_ALL On) 238 | set_property(TARGET ${TRGT} PROPERTY LLVMIR_SHORT_NAME ${SHORT_NAME}) 239 | endfunction() 240 | 241 | # 242 | 243 | function(llvmir_attach_opt_pass_target) 244 | set(options) 245 | set(oneValueArgs TARGET DEPENDS) 246 | set(multiValueArgs) 247 | cmake_parse_arguments(LLVMIR_ATTACH 248 | "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) 249 | 250 | set(TRGT ${LLVMIR_ATTACH_TARGET}) 251 | set(DEPENDS_TRGT ${LLVMIR_ATTACH_DEPENDS}) 252 | 253 | # fallback to backwards compatible mode for argument parsing 254 | if(NOT TRGT AND NOT DEPENDS_TRGT) 255 | list(GET LLVMIR_ATTACH_UNPARSED_ARGUMENTS 0 TRGT) 256 | list(GET LLVMIR_ATTACH_UNPARSED_ARGUMENTS 1 DEPENDS_TRGT) 257 | list(REMOVE_AT LLVMIR_ATTACH_UNPARSED_ARGUMENTS 0 1) 258 | endif() 259 | 260 | if(NOT TRGT) 261 | message(FATAL_ERROR "llvmir_attach_opt_pass_target: missing TARGET option") 262 | endif() 263 | 264 | if(NOT DEPENDS_TRGT) 265 | message(FATAL_ERROR "llvmir_attach_opt_pass_target: missing DEPENDS option") 266 | endif() 267 | 268 | ## preamble 269 | llvmir_check_target_properties(${DEPENDS_TRGT}) 270 | 271 | set(OUT_LLVMIR_FILES "") 272 | set(FULL_OUT_LLVMIR_FILES "") 273 | 274 | get_property(IN_LLVMIR_TYPE TARGET ${DEPENDS_TRGT} PROPERTY LLVMIR_TYPE) 275 | get_property(LLVMIR_EXTERNAL_TYPE TARGET ${DEPENDS_TRGT} 276 | PROPERTY LLVMIR_EXTERNAL_TYPE) 277 | get_property(IN_LLVMIR_DIR TARGET ${DEPENDS_TRGT} PROPERTY LLVMIR_DIR) 278 | get_property(IN_LLVMIR_FILES TARGET ${DEPENDS_TRGT} PROPERTY LLVMIR_FILES) 279 | get_property(LINKER_LANGUAGE TARGET ${DEPENDS_TRGT} PROPERTY LINKER_LANGUAGE) 280 | get_property(LINK_DEPENDS TARGET ${DEPENDS_TRGT} PROPERTY LINK_DEPENDS) 281 | get_property(LINK_FLAGS TARGET ${DEPENDS_TRGT} PROPERTY LINK_FLAGS) 282 | get_property(LINK_FLAGS_${CMAKE_BUILD_TYPE} 283 | TARGET ${DEPENDS_TRGT} 284 | PROPERTY LINK_FLAGS_${CMAKE_BUILD_TYPE}) 285 | get_property(INTERFACE_LINK_LIBRARIES 286 | TARGET ${DEPENDS_TRGT} 287 | PROPERTY INTERFACE_LINK_LIBRARIES) 288 | get_property(LINK_LIBRARIES TARGET ${DEPENDS_TRGT} PROPERTY LINK_LIBRARIES) 289 | get_property(LINK_INTERFACE_LIBRARIES 290 | TARGET ${DEPENDS_TRGT} 291 | PROPERTY LINK_INTERFACE_LIBRARIES) 292 | get_property(LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE} 293 | TARGET ${DEPENDS_TRGT} 294 | PROPERTY LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE}) 295 | get_property(SHORT_NAME TARGET ${DEPENDS_TRGT} PROPERTY LLVMIR_SHORT_NAME) 296 | 297 | if(NOT "${IN_LLVMIR_TYPE}" STREQUAL "${LLVMIR_BINARY_TYPE}") 298 | message(FATAL_ERROR "Cannot attach ${TRGT} to target of type: \ 299 | ${IN_LLVMIR_TYPE}.") 300 | endif() 301 | 302 | if("${LINKER_LANGUAGE}" STREQUAL "") 303 | message(FATAL_ERROR "Linker language for target ${DEPENDS_TRGT} \ 304 | must be set.") 305 | endif() 306 | 307 | ## main operations 308 | set(WORK_DIR "${CMAKE_CURRENT_BINARY_DIR}/${LLVMIR_DIR}/${TRGT}") 309 | file(MAKE_DIRECTORY ${WORK_DIR}) 310 | 311 | foreach(IN_LLVMIR_FILE ${IN_LLVMIR_FILES}) 312 | get_filename_component(OUTFILE ${IN_LLVMIR_FILE} NAME_WE) 313 | set(INFILE "${IN_LLVMIR_DIR}/${IN_LLVMIR_FILE}") 314 | set(OUT_LLVMIR_FILE "${OUTFILE}.${LLVMIR_BINARY_FMT_SUFFIX}") 315 | set(FULL_OUT_LLVMIR_FILE "${WORK_DIR}/${OUT_LLVMIR_FILE}") 316 | 317 | add_custom_command(OUTPUT ${FULL_OUT_LLVMIR_FILE} 318 | COMMAND ${LLVMIR_OPT} 319 | ARGS 320 | ${LLVMIR_ATTACH_UNPARSED_ARGUMENTS} ${INFILE} -o ${FULL_OUT_LLVMIR_FILE} 321 | DEPENDS ${INFILE} 322 | COMMENT "Generating LLVM bitcode ${OUT_LLVMIR_FILE}" 323 | VERBATIM) 324 | 325 | list(APPEND OUT_LLVMIR_FILES ${OUT_LLVMIR_FILE}) 326 | list(APPEND FULL_OUT_LLVMIR_FILES ${FULL_OUT_LLVMIR_FILE}) 327 | endforeach() 328 | 329 | ## postamble 330 | 331 | # setup custom target 332 | add_custom_target(${TRGT} DEPENDS ${FULL_OUT_LLVMIR_FILES}) 333 | 334 | set_property(TARGET ${TRGT} PROPERTY LLVMIR_TYPE ${LLVMIR_BINARY_TYPE}) 335 | set_property(TARGET ${TRGT} 336 | PROPERTY LLVMIR_EXTERNAL_TYPE ${LLVMIR_EXTERNAL_TYPE}) 337 | set_property(TARGET ${TRGT} PROPERTY LLVMIR_DIR ${WORK_DIR}) 338 | set_property(TARGET ${TRGT} PROPERTY LLVMIR_FILES ${OUT_LLVMIR_FILES}) 339 | set_property(TARGET ${TRGT} PROPERTY LINKER_LANGUAGE ${LINKER_LANGUAGE}) 340 | set_property(TARGET ${TRGT} PROPERTY LINK_DEPENDS ${LINK_DEPENDS}) 341 | set_property(TARGET ${TRGT} PROPERTY LINK_FLAGS ${LINK_FLAGS}) 342 | set_property(TARGET ${TRGT} 343 | PROPERTY LINK_FLAGS_${CMAKE_BUILD_TYPE} ${LINK_FLAGS_${CMAKE_BUILD_TYPE}}) 344 | set_property(TARGET ${TRGT} 345 | PROPERTY INTERFACE_LINK_LIBRARIES ${INTERFACE_LINK_LIBRARIES}) 346 | set_property(TARGET ${TRGT} 347 | PROPERTY LINK_INTERFACE_LIBRARIES ${LINK_INTERFACE_LIBRARIES}) 348 | set_property(TARGET ${TRGT} 349 | PROPERTY 350 | LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE} 351 | ${LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE}}) 352 | set_property(TARGET ${TRGT} PROPERTY EXCLUDE_FROM_ALL On) 353 | set_property(TARGET ${TRGT} PROPERTY LLVMIR_SHORT_NAME ${SHORT_NAME}) 354 | endfunction() 355 | 356 | # 357 | 358 | function(llvmir_attach_disassemble_target) 359 | set(options) 360 | set(oneValueArgs TARGET DEPENDS) 361 | set(multiValueArgs) 362 | cmake_parse_arguments(LLVMIR_ATTACH 363 | "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) 364 | 365 | set(TRGT ${LLVMIR_ATTACH_TARGET}) 366 | set(DEPENDS_TRGT ${LLVMIR_ATTACH_DEPENDS}) 367 | 368 | # fallback to backwards compatible mode for argument parsing 369 | if(NOT TRGT AND NOT DEPENDS_TRGT) 370 | list(GET LLVMIR_ATTACH_UNPARSED_ARGUMENTS 0 TRGT) 371 | list(GET LLVMIR_ATTACH_UNPARSED_ARGUMENTS 1 DEPENDS_TRGT) 372 | list(REMOVE_AT LLVMIR_ATTACH_UNPARSED_ARGUMENTS 0 1) 373 | endif() 374 | 375 | if(NOT TRGT) 376 | message(FATAL_ERROR "llvmir_attach_disassemble_target: missing TARGET option") 377 | endif() 378 | 379 | if(NOT DEPENDS_TRGT) 380 | message(FATAL_ERROR "llvmir_attach_disassemble_target: missing DEPENDS option") 381 | endif() 382 | 383 | ## preamble 384 | llvmir_check_target_properties(${DEPENDS_TRGT}) 385 | 386 | set(OUT_LLVMIR_FILES "") 387 | set(FULL_OUT_LLVMIR_FILES "") 388 | 389 | get_property(IN_LLVMIR_TYPE TARGET ${DEPENDS_TRGT} PROPERTY LLVMIR_TYPE) 390 | get_property(LLVMIR_EXTERNAL_TYPE TARGET ${DEPENDS_TRGT} 391 | PROPERTY LLVMIR_EXTERNAL_TYPE) 392 | get_property(IN_LLVMIR_DIR TARGET ${DEPENDS_TRGT} PROPERTY LLVMIR_DIR) 393 | get_property(IN_LLVMIR_FILES TARGET ${DEPENDS_TRGT} PROPERTY LLVMIR_FILES) 394 | get_property(LINKER_LANGUAGE TARGET ${DEPENDS_TRGT} PROPERTY LINKER_LANGUAGE) 395 | get_property(LINK_DEPENDS TARGET ${DEPENDS_TRGT} PROPERTY LINK_DEPENDS) 396 | get_property(LINK_FLAGS TARGET ${DEPENDS_TRGT} PROPERTY LINK_FLAGS) 397 | get_property(LINK_FLAGS_${CMAKE_BUILD_TYPE} 398 | TARGET ${DEPENDS_TRGT} 399 | PROPERTY LINK_FLAGS_${CMAKE_BUILD_TYPE}) 400 | get_property(INTERFACE_LINK_LIBRARIES 401 | TARGET ${DEPENDS_TRGT} 402 | PROPERTY INTERFACE_LINK_LIBRARIES) 403 | get_property(LINK_LIBRARIES TARGET ${DEPENDS_TRGT} PROPERTY LINK_LIBRARIES) 404 | get_property(LINK_INTERFACE_LIBRARIES 405 | TARGET ${DEPENDS_TRGT} 406 | PROPERTY LINK_INTERFACE_LIBRARIES) 407 | get_property(LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE} 408 | TARGET ${DEPENDS_TRGT} 409 | PROPERTY LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE}) 410 | get_property(SHORT_NAME TARGET ${DEPENDS_TRGT} PROPERTY LLVMIR_SHORT_NAME) 411 | 412 | if(NOT "${IN_LLVMIR_TYPE}" STREQUAL "${LLVMIR_BINARY_TYPE}") 413 | message(FATAL_ERROR "Cannot attach ${TRGT} to a ${IN_LLVMIR_TYPE} target.") 414 | endif() 415 | 416 | ## main operations 417 | set(WORK_DIR "${CMAKE_CURRENT_BINARY_DIR}/${LLVMIR_DIR}/${TRGT}") 418 | file(MAKE_DIRECTORY ${WORK_DIR}) 419 | 420 | foreach(IN_LLVMIR_FILE ${IN_LLVMIR_FILES}) 421 | get_filename_component(OUTFILE ${IN_LLVMIR_FILE} NAME_WE) 422 | set(INFILE "${IN_LLVMIR_DIR}/${IN_LLVMIR_FILE}") 423 | set(OUT_LLVMIR_FILE "${OUTFILE}.${LLVMIR_TEXT_FMT_SUFFIX}") 424 | set(FULL_OUT_LLVMIR_FILE "${WORK_DIR}/${OUT_LLVMIR_FILE}") 425 | 426 | add_custom_command(OUTPUT ${FULL_OUT_LLVMIR_FILE} 427 | COMMAND ${LLVMIR_DISASSEMBLER} 428 | ARGS 429 | ${LLVMIR_ATTACH_UNPARSED_ARGUMENTS} ${INFILE} -o ${FULL_OUT_LLVMIR_FILE} 430 | DEPENDS ${INFILE} 431 | COMMENT "Disassembling LLVM bitcode ${OUT_LLVMIR_FILE}" 432 | VERBATIM) 433 | 434 | list(APPEND OUT_LLVMIR_FILES ${OUT_LLVMIR_FILE}) 435 | list(APPEND FULL_OUT_LLVMIR_FILES ${FULL_OUT_LLVMIR_FILE}) 436 | endforeach() 437 | 438 | ## postamble 439 | 440 | # setup custom target 441 | add_custom_target(${TRGT} DEPENDS ${FULL_OUT_LLVMIR_FILES}) 442 | 443 | set_property(TARGET ${TRGT} PROPERTY LLVMIR_TYPE ${LLVMIR_TEXT_TYPE}) 444 | set_property(TARGET ${TRGT} 445 | PROPERTY LLVMIR_EXTERNAL_TYPE ${LLVMIR_EXTERNAL_TYPE}) 446 | set_property(TARGET ${TRGT} PROPERTY LLVMIR_DIR ${WORK_DIR}) 447 | set_property(TARGET ${TRGT} PROPERTY LLVMIR_FILES ${OUT_LLVMIR_FILES}) 448 | set_property(TARGET ${TRGT} PROPERTY LINKER_LANGUAGE ${LINKER_LANGUAGE}) 449 | set_property(TARGET ${TRGT} PROPERTY LINK_DEPENDS ${LINK_DEPENDS}) 450 | set_property(TARGET ${TRGT} PROPERTY LINK_FLAGS ${LINK_FLAGS}) 451 | set_property(TARGET ${TRGT} 452 | PROPERTY LINK_FLAGS_${CMAKE_BUILD_TYPE} ${LINK_FLAGS_${CMAKE_BUILD_TYPE}}) 453 | set_property(TARGET ${TRGT} 454 | PROPERTY INTERFACE_LINK_LIBRARIES ${INTERFACE_LINK_LIBRARIES}) 455 | set_property(TARGET ${TRGT} 456 | PROPERTY LINK_INTERFACE_LIBRARIES ${LINK_INTERFACE_LIBRARIES}) 457 | set_property(TARGET ${TRGT} 458 | PROPERTY 459 | LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE} 460 | ${LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE}}) 461 | set_property(TARGET ${TRGT} PROPERTY EXCLUDE_FROM_ALL On) 462 | set_property(TARGET ${TRGT} PROPERTY LLVMIR_SHORT_NAME ${SHORT_NAME}) 463 | endfunction() 464 | 465 | # 466 | 467 | function(llvmir_attach_assemble_target) 468 | set(options) 469 | set(oneValueArgs TARGET DEPENDS) 470 | set(multiValueArgs) 471 | cmake_parse_arguments(LLVMIR_ATTACH 472 | "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) 473 | 474 | set(TRGT ${LLVMIR_ATTACH_TARGET}) 475 | set(DEPENDS_TRGT ${LLVMIR_ATTACH_DEPENDS}) 476 | 477 | # fallback to backwards compatible mode for argument parsing 478 | if(NOT TRGT AND NOT DEPENDS_TRGT) 479 | list(GET LLVMIR_ATTACH_UNPARSED_ARGUMENTS 0 TRGT) 480 | list(GET LLVMIR_ATTACH_UNPARSED_ARGUMENTS 1 DEPENDS_TRGT) 481 | list(REMOVE_AT LLVMIR_ATTACH_UNPARSED_ARGUMENTS 0 1) 482 | endif() 483 | 484 | if(NOT TRGT) 485 | message(FATAL_ERROR "llvmir_attach_assemble_target: missing TARGET option") 486 | endif() 487 | 488 | if(NOT DEPENDS_TRGT) 489 | message(FATAL_ERROR "llvmir_attach_assemble_target: missing DEPENDS option") 490 | endif() 491 | 492 | ## preamble 493 | llvmir_check_target_properties(${DEPENDS_TRGT}) 494 | 495 | set(OUT_LLVMIR_FILES "") 496 | set(FULL_OUT_LLVMIR_FILES "") 497 | 498 | get_property(IN_LLVMIR_TYPE TARGET ${DEPENDS_TRGT} PROPERTY LLVMIR_TYPE) 499 | get_property(LLVMIR_EXTERNAL_TYPE TARGET ${DEPENDS_TRGT} 500 | PROPERTY LLVMIR_EXTERNAL_TYPE) 501 | get_property(IN_LLVMIR_DIR TARGET ${DEPENDS_TRGT} PROPERTY LLVMIR_DIR) 502 | get_property(IN_LLVMIR_FILES TARGET ${DEPENDS_TRGT} PROPERTY LLVMIR_FILES) 503 | get_property(LINKER_LANGUAGE TARGET ${DEPENDS_TRGT} PROPERTY LINKER_LANGUAGE) 504 | get_property(LINK_DEPENDS TARGET ${DEPENDS_TRGT} PROPERTY LINK_DEPENDS) 505 | get_property(LINK_FLAGS TARGET ${DEPENDS_TRGT} PROPERTY LINK_FLAGS) 506 | get_property(LINK_FLAGS_${CMAKE_BUILD_TYPE} 507 | TARGET ${DEPENDS_TRGT} 508 | PROPERTY LINK_FLAGS_${CMAKE_BUILD_TYPE}) 509 | get_property(INTERFACE_LINK_LIBRARIES 510 | TARGET ${DEPENDS_TRGT} 511 | PROPERTY INTERFACE_LINK_LIBRARIES) 512 | get_property(LINK_LIBRARIES TARGET ${DEPENDS_TRGT} PROPERTY LINK_LIBRARIES) 513 | get_property(LINK_INTERFACE_LIBRARIES 514 | TARGET ${DEPENDS_TRGT} 515 | PROPERTY LINK_INTERFACE_LIBRARIES) 516 | get_property(LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE} 517 | TARGET ${DEPENDS_TRGT} 518 | PROPERTY LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE}) 519 | get_property(SHORT_NAME TARGET ${DEPENDS_TRGT} PROPERTY LLVMIR_SHORT_NAME) 520 | 521 | if(NOT "${IN_LLVMIR_TYPE}" STREQUAL "${LLVMIR_TEXT_TYPE}") 522 | message(FATAL_ERROR "Cannot attach ${TRGT} to a ${IN_LLVMIR_TYPE} target.") 523 | endif() 524 | 525 | ## main operations 526 | set(WORK_DIR "${CMAKE_CURRENT_BINARY_DIR}/${LLVMIR_DIR}/${TRGT}") 527 | file(MAKE_DIRECTORY ${WORK_DIR}) 528 | 529 | foreach(IN_LLVMIR_FILE ${IN_LLVMIR_FILES}) 530 | get_filename_component(OUTFILE ${IN_LLVMIR_FILE} NAME_WE) 531 | set(INFILE "${IN_LLVMIR_DIR}/${IN_LLVMIR_FILE}") 532 | set(OUT_LLVMIR_FILE "${OUTFILE}.${LLVMIR_BINARY_FMT_SUFFIX}") 533 | set(FULL_OUT_LLVMIR_FILE "${WORK_DIR}/${OUT_LLVMIR_FILE}") 534 | 535 | add_custom_command(OUTPUT ${FULL_OUT_LLVMIR_FILE} 536 | COMMAND ${LLVMIR_ASSEMBLER} 537 | ARGS 538 | ${LLVMIR_ATTACH_UNPARSED_ARGUMENTS} ${INFILE} -o ${FULL_OUT_LLVMIR_FILE} 539 | DEPENDS ${INFILE} 540 | COMMENT "Assembling LLVM bitcode ${OUT_LLVMIR_FILE}" 541 | VERBATIM) 542 | 543 | list(APPEND OUT_LLVMIR_FILES ${OUT_LLVMIR_FILE}) 544 | list(APPEND FULL_OUT_LLVMIR_FILES ${FULL_OUT_LLVMIR_FILE}) 545 | endforeach() 546 | 547 | ## postamble 548 | 549 | # setup custom target 550 | add_custom_target(${TRGT} DEPENDS ${FULL_OUT_LLVMIR_FILES}) 551 | 552 | set_property(TARGET ${TRGT} PROPERTY LLVMIR_TYPE ${LLVMIR_BINARY_TYPE}) 553 | set_property(TARGET ${TRGT} 554 | PROPERTY LLVMIR_EXTERNAL_TYPE ${LLVMIR_EXTERNAL_TYPE}) 555 | set_property(TARGET ${TRGT} PROPERTY LLVMIR_DIR ${WORK_DIR}) 556 | set_property(TARGET ${TRGT} PROPERTY LLVMIR_FILES ${OUT_LLVMIR_FILES}) 557 | set_property(TARGET ${TRGT} PROPERTY LINKER_LANGUAGE ${LINKER_LANGUAGE}) 558 | set_property(TARGET ${TRGT} PROPERTY LINK_DEPENDS ${LINK_DEPENDS}) 559 | set_property(TARGET ${TRGT} PROPERTY LINK_FLAGS ${LINK_FLAGS}) 560 | set_property(TARGET ${TRGT} 561 | PROPERTY LINK_FLAGS_${CMAKE_BUILD_TYPE} ${LINK_FLAGS_${CMAKE_BUILD_TYPE}}) 562 | set_property(TARGET ${TRGT} 563 | PROPERTY INTERFACE_LINK_LIBRARIES ${INTERFACE_LINK_LIBRARIES}) 564 | set_property(TARGET ${TRGT} 565 | PROPERTY LINK_INTERFACE_LIBRARIES ${LINK_INTERFACE_LIBRARIES}) 566 | set_property(TARGET ${TRGT} 567 | PROPERTY 568 | LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE} 569 | ${LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE}}) 570 | set_property(TARGET ${TRGT} PROPERTY EXCLUDE_FROM_ALL On) 571 | set_property(TARGET ${TRGT} PROPERTY LLVMIR_SHORT_NAME ${SHORT_NAME}) 572 | endfunction() 573 | 574 | # 575 | 576 | function(llvmir_attach_link_target) 577 | set(options) 578 | set(oneValueArgs TARGET DEPENDS) 579 | set(multiValueArgs) 580 | cmake_parse_arguments(LLVMIR_ATTACH 581 | "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) 582 | 583 | set(TRGT ${LLVMIR_ATTACH_TARGET}) 584 | set(DEPENDS_TRGT ${LLVMIR_ATTACH_DEPENDS}) 585 | 586 | # fallback to backwards compatible mode for argument parsing 587 | if(NOT TRGT AND NOT DEPENDS_TRGT) 588 | list(GET LLVMIR_ATTACH_UNPARSED_ARGUMENTS 0 TRGT) 589 | list(GET LLVMIR_ATTACH_UNPARSED_ARGUMENTS 1 DEPENDS_TRGT) 590 | list(REMOVE_AT LLVMIR_ATTACH_UNPARSED_ARGUMENTS 0 1) 591 | endif() 592 | 593 | if(NOT TRGT) 594 | message(FATAL_ERROR "llvmir_attach_link_target: missing TARGET option") 595 | endif() 596 | 597 | if(NOT DEPENDS_TRGT) 598 | message(FATAL_ERROR "llvmir_attach_link_target: missing DEPENDS option") 599 | endif() 600 | 601 | ## preamble 602 | llvmir_check_target_properties(${DEPENDS_TRGT}) 603 | 604 | set(OUT_LLVMIR_FILES "") 605 | set(FULL_OUT_LLVMIR_FILES "") 606 | 607 | get_property(IN_LLVMIR_TYPE TARGET ${DEPENDS_TRGT} PROPERTY LLVMIR_TYPE) 608 | get_property(LLVMIR_EXTERNAL_TYPE TARGET ${DEPENDS_TRGT} 609 | PROPERTY LLVMIR_EXTERNAL_TYPE) 610 | get_property(INFILES TARGET ${DEPENDS_TRGT} PROPERTY LLVMIR_FILES) 611 | get_property(IN_LLVMIR_DIR TARGET ${DEPENDS_TRGT} PROPERTY LLVMIR_DIR) 612 | get_property(LINKER_LANGUAGE TARGET ${DEPENDS_TRGT} PROPERTY LINKER_LANGUAGE) 613 | get_property(LINK_DEPENDS TARGET ${DEPENDS_TRGT} PROPERTY LINK_DEPENDS) 614 | get_property(LINK_FLAGS TARGET ${DEPENDS_TRGT} PROPERTY LINK_FLAGS) 615 | get_property(LINK_FLAGS_${CMAKE_BUILD_TYPE} 616 | TARGET ${DEPENDS_TRGT} 617 | PROPERTY LINK_FLAGS_${CMAKE_BUILD_TYPE}) 618 | get_property(INTERFACE_LINK_LIBRARIES 619 | TARGET ${DEPENDS_TRGT} 620 | PROPERTY INTERFACE_LINK_LIBRARIES) 621 | get_property(LINK_LIBRARIES TARGET ${DEPENDS_TRGT} PROPERTY LINK_LIBRARIES) 622 | get_property(LINK_INTERFACE_LIBRARIES 623 | TARGET ${DEPENDS_TRGT} 624 | PROPERTY LINK_INTERFACE_LIBRARIES) 625 | get_property(LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE} 626 | TARGET ${DEPENDS_TRGT} 627 | PROPERTY LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE}) 628 | get_property(SHORT_NAME TARGET ${DEPENDS_TRGT} PROPERTY LLVMIR_SHORT_NAME) 629 | 630 | if(NOT "${IN_LLVMIR_TYPE}" STREQUAL "${LLVMIR_BINARY_TYPE}") 631 | message(FATAL_ERROR "Cannot attach ${TRGT} to a ${IN_LLVMIR_TYPE} target.") 632 | endif() 633 | 634 | ## main operations 635 | set(WORK_DIR "${CMAKE_CURRENT_BINARY_DIR}/${LLVMIR_DIR}/${TRGT}") 636 | file(MAKE_DIRECTORY ${WORK_DIR}) 637 | 638 | set(IN_FULL_LLVMIR_FILES "") 639 | foreach(IN_LLVMIR_FILE ${INFILES}) 640 | list(APPEND IN_FULL_LLVMIR_FILES "${IN_LLVMIR_DIR}/${IN_LLVMIR_FILE}") 641 | endforeach() 642 | 643 | set(FULL_OUT_LLVMIR_FILE "${WORK_DIR}/${TRGT}.${LLVMIR_BINARY_FMT_SUFFIX}") 644 | if(SHORT_NAME) 645 | set(FULL_OUT_LLVMIR_FILE 646 | "${WORK_DIR}/${SHORT_NAME}.${LLVMIR_BINARY_FMT_SUFFIX}") 647 | endif() 648 | get_filename_component(OUT_LLVMIR_FILE ${FULL_OUT_LLVMIR_FILE} NAME) 649 | 650 | list(APPEND OUT_LLVMIR_FILES ${OUT_LLVMIR_FILE}) 651 | list(APPEND FULL_OUT_LLVMIR_FILES ${FULL_OUT_LLVMIR_FILE}) 652 | 653 | # setup custom target 654 | add_custom_target(${TRGT} DEPENDS ${FULL_OUT_LLVMIR_FILES}) 655 | 656 | set_property(TARGET ${TRGT} PROPERTY LLVMIR_TYPE ${LLVMIR_BINARY_TYPE}) 657 | set_property(TARGET ${TRGT} 658 | PROPERTY LLVMIR_EXTERNAL_TYPE ${LLVMIR_EXTERNAL_TYPE}) 659 | set_property(TARGET ${TRGT} PROPERTY LLVMIR_DIR ${WORK_DIR}) 660 | set_property(TARGET ${TRGT} PROPERTY LLVMIR_FILES ${OUT_LLVMIR_FILES}) 661 | set_property(TARGET ${TRGT} PROPERTY LINKER_LANGUAGE ${LINKER_LANGUAGE}) 662 | set_property(TARGET ${TRGT} PROPERTY LINK_DEPENDS ${LINK_DEPENDS}) 663 | set_property(TARGET ${TRGT} PROPERTY LINK_FLAGS ${LINK_FLAGS}) 664 | set_property(TARGET ${TRGT} 665 | PROPERTY LINK_FLAGS_${CMAKE_BUILD_TYPE} ${LINK_FLAGS_${CMAKE_BUILD_TYPE}}) 666 | set_property(TARGET ${TRGT} 667 | PROPERTY INTERFACE_LINK_LIBRARIES ${INTERFACE_LINK_LIBRARIES}) 668 | set_property(TARGET ${TRGT} 669 | PROPERTY LINK_INTERFACE_LIBRARIES ${LINK_INTERFACE_LIBRARIES}) 670 | set_property(TARGET ${TRGT} 671 | PROPERTY 672 | LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE} 673 | ${LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE}}) 674 | set_property(TARGET ${TRGT} PROPERTY EXCLUDE_FROM_ALL On) 675 | set_property(TARGET ${TRGT} PROPERTY LLVMIR_SHORT_NAME ${SHORT_NAME}) 676 | 677 | add_custom_command(OUTPUT ${FULL_OUT_LLVMIR_FILE} 678 | COMMAND llvm-link 679 | ARGS 680 | ${LLVMIR_ATTACH_UNPARSED_ARGUMENTS} 681 | -o ${FULL_OUT_LLVMIR_FILE} ${IN_FULL_LLVMIR_FILES} 682 | DEPENDS ${IN_FULL_LLVMIR_FILES} 683 | COMMENT "Linking LLVM bitcode ${OUT_LLVMIR_FILE}" 684 | VERBATIM) 685 | 686 | ## postamble 687 | endfunction() 688 | 689 | function(llvmir_attach_obj_target) 690 | set(options) 691 | set(oneValueArgs TARGET DEPENDS) 692 | set(multiValueArgs) 693 | cmake_parse_arguments(LLVMIR_ATTACH 694 | "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) 695 | 696 | set(TRGT ${LLVMIR_ATTACH_TARGET}) 697 | set(DEPENDS_TRGT ${LLVMIR_ATTACH_DEPENDS}) 698 | 699 | # fallback to backwards compatible mode for argument parsing 700 | if(NOT TRGT AND NOT DEPENDS_TRGT) 701 | list(GET LLVMIR_ATTACH_UNPARSED_ARGUMENTS 0 TRGT) 702 | list(GET LLVMIR_ATTACH_UNPARSED_ARGUMENTS 1 DEPENDS_TRGT) 703 | list(REMOVE_AT LLVMIR_ATTACH_UNPARSED_ARGUMENTS 0 1) 704 | endif() 705 | 706 | if(NOT TRGT) 707 | message(FATAL_ERROR "llvmir_attach_obj_target: missing TARGET option") 708 | endif() 709 | 710 | if(NOT DEPENDS_TRGT) 711 | message(FATAL_ERROR "llvmir_attach_obj_target: missing DEPENDS option") 712 | endif() 713 | 714 | ## preamble 715 | llvmir_check_target_properties(${DEPENDS_TRGT}) 716 | 717 | set(OUT_LLVMIR_FILES "") 718 | set(FULL_OUT_LLVMIR_FILES "") 719 | 720 | get_property(IN_LLVMIR_TYPE TARGET ${DEPENDS_TRGT} PROPERTY LLVMIR_TYPE) 721 | get_property(LLVMIR_EXTERNAL_TYPE TARGET ${DEPENDS_TRGT} 722 | PROPERTY LLVMIR_EXTERNAL_TYPE) 723 | get_property(INFILES TARGET ${DEPENDS_TRGT} PROPERTY LLVMIR_FILES) 724 | get_property(IN_LLVMIR_DIR TARGET ${DEPENDS_TRGT} PROPERTY LLVMIR_DIR) 725 | get_property(LINKER_LANGUAGE TARGET ${DEPENDS_TRGT} PROPERTY LINKER_LANGUAGE) 726 | get_property(LINK_DEPENDS TARGET ${DEPENDS_TRGT} PROPERTY LINK_DEPENDS) 727 | get_property(LINK_FLAGS TARGET ${DEPENDS_TRGT} PROPERTY LINK_FLAGS) 728 | get_property(LINK_FLAGS_${CMAKE_BUILD_TYPE} 729 | TARGET ${DEPENDS_TRGT} 730 | PROPERTY LINK_FLAGS_${CMAKE_BUILD_TYPE}) 731 | get_property(INTERFACE_LINK_LIBRARIES 732 | TARGET ${DEPENDS_TRGT} 733 | PROPERTY INTERFACE_LINK_LIBRARIES) 734 | get_property(LINK_LIBRARIES TARGET ${DEPENDS_TRGT} PROPERTY LINK_LIBRARIES) 735 | get_property(LINK_INTERFACE_LIBRARIES 736 | TARGET ${DEPENDS_TRGT} 737 | PROPERTY LINK_INTERFACE_LIBRARIES) 738 | get_property(LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE} 739 | TARGET ${DEPENDS_TRGT} 740 | PROPERTY LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE}) 741 | get_property(SHORT_NAME TARGET ${DEPENDS_TRGT} PROPERTY LLVMIR_SHORT_NAME) 742 | 743 | if(NOT "${IN_LLVMIR_TYPE}" STREQUAL "${LLVMIR_BINARY_TYPE}") 744 | message(FATAL_ERROR "Cannot attach ${TRGT} to a ${IN_LLVMIR_TYPE} target.") 745 | endif() 746 | 747 | ## main operations 748 | set(WORK_DIR "${CMAKE_CURRENT_BINARY_DIR}/${LLVMIR_DIR}/${TRGT}") 749 | file(MAKE_DIRECTORY ${WORK_DIR}) 750 | 751 | set(IN_FULL_LLVMIR_FILES "") 752 | foreach(IN_LLVMIR_FILE ${INFILES}) 753 | list(APPEND IN_FULL_LLVMIR_FILES "${IN_LLVMIR_DIR}/${IN_LLVMIR_FILE}") 754 | endforeach() 755 | 756 | set(FULL_OUT_LLVMIR_FILE "${WORK_DIR}/${TRGT}.o") 757 | if(SHORT_NAME) 758 | set(FULL_OUT_LLVMIR_FILE "${WORK_DIR}/${SHORT_NAME}.o") 759 | endif() 760 | get_filename_component(OUT_LLVMIR_FILE ${FULL_OUT_LLVMIR_FILE} NAME) 761 | 762 | list(APPEND OUT_LLVMIR_FILES ${OUT_LLVMIR_FILE}) 763 | list(APPEND FULL_OUT_LLVMIR_FILES ${FULL_OUT_LLVMIR_FILE}) 764 | 765 | # setup custom target 766 | add_custom_target(${TRGT} DEPENDS ${FULL_OUT_LLVMIR_FILES}) 767 | 768 | set_property(TARGET ${TRGT} PROPERTY LLVMIR_TYPE ${LLVMIR_OBJECT_TYPE}) 769 | set_property(TARGET ${TRGT} 770 | PROPERTY LLVMIR_EXTERNAL_TYPE ${LLVMIR_EXTERNAL_TYPE}) 771 | set_property(TARGET ${TRGT} PROPERTY LLVMIR_DIR ${WORK_DIR}) 772 | set_property(TARGET ${TRGT} PROPERTY LLVMIR_FILES ${OUT_LLVMIR_FILES}) 773 | set_property(TARGET ${TRGT} PROPERTY LINKER_LANGUAGE ${LINKER_LANGUAGE}) 774 | set_property(TARGET ${TRGT} PROPERTY LINK_DEPENDS ${LINK_DEPENDS}) 775 | set_property(TARGET ${TRGT} PROPERTY LINK_FLAGS ${LINK_FLAGS}) 776 | set_property(TARGET ${TRGT} 777 | PROPERTY LINK_FLAGS_${CMAKE_BUILD_TYPE} ${LINK_FLAGS_${CMAKE_BUILD_TYPE}}) 778 | set_property(TARGET ${TRGT} 779 | PROPERTY INTERFACE_LINK_LIBRARIES ${INTERFACE_LINK_LIBRARIES}) 780 | set_property(TARGET ${TRGT} 781 | PROPERTY LINK_INTERFACE_LIBRARIES ${LINK_INTERFACE_LIBRARIES}) 782 | set_property(TARGET ${TRGT} 783 | PROPERTY 784 | LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE} 785 | ${LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE}}) 786 | set_property(TARGET ${TRGT} PROPERTY EXCLUDE_FROM_ALL On) 787 | set_property(TARGET ${TRGT} PROPERTY LLVMIR_SHORT_NAME ${SHORT_NAME}) 788 | 789 | add_custom_command(OUTPUT ${FULL_OUT_LLVMIR_FILE} 790 | COMMAND llc 791 | ARGS 792 | -filetype=obj 793 | ${LLVMIR_ATTACH_UNPARSED_ARGUMENTS} 794 | -o ${FULL_OUT_LLVMIR_FILE} ${IN_FULL_LLVMIR_FILES} 795 | DEPENDS ${IN_FULL_LLVMIR_FILES} 796 | COMMENT "Generating object ${OUT_LLVMIR_FILE}" 797 | VERBATIM) 798 | 799 | ## postamble 800 | endfunction() 801 | 802 | function(llvmir_attach_executable) 803 | set(options) 804 | set(oneValueArgs TARGET DEPENDS) 805 | set(multiValueArgs) 806 | cmake_parse_arguments(LLVMIR_ATTACH 807 | "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) 808 | 809 | set(TRGT ${LLVMIR_ATTACH_TARGET}) 810 | set(DEPENDS_TRGT ${LLVMIR_ATTACH_DEPENDS}) 811 | 812 | # fallback to backwards compatible mode for argument parsing 813 | if(NOT TRGT AND NOT DEPENDS_TRGT) 814 | set(TRGT ${ARGV0}) 815 | set(DEPENDS_TRGT ${ARGV1}) 816 | 817 | if(${ARGC} GREATER 3) 818 | message(FATAL_ERROR 819 | "llvmir_attach_executable: extraneous arguments provided") 820 | endif() 821 | else() 822 | if(LLVMIR_ATTACH_UNPARSED_ARGUMENTS) 823 | message(FATAL_ERROR 824 | "llvmir_attach_executable: extraneous arguments provided") 825 | endif() 826 | endif() 827 | 828 | if(NOT TRGT) 829 | message(FATAL_ERROR "llvmir_attach_executable: missing TARGET option") 830 | endif() 831 | 832 | if(NOT DEPENDS_TRGT) 833 | message(FATAL_ERROR "llvmir_attach_executable: missing DEPENDS option") 834 | endif() 835 | 836 | ## preamble 837 | llvmir_check_target_properties(${DEPENDS_TRGT}) 838 | 839 | get_property(IN_LLVMIR_TYPE TARGET ${DEPENDS_TRGT} PROPERTY LLVMIR_TYPE) 840 | get_property(LLVMIR_EXTERNAL_TYPE TARGET ${DEPENDS_TRGT} 841 | PROPERTY LLVMIR_EXTERNAL_TYPE) 842 | get_property(INFILES TARGET ${DEPENDS_TRGT} PROPERTY LLVMIR_FILES) 843 | get_property(IN_LLVMIR_DIR TARGET ${DEPENDS_TRGT} PROPERTY LLVMIR_DIR) 844 | get_property(LINKER_LANGUAGE TARGET ${DEPENDS_TRGT} PROPERTY LINKER_LANGUAGE) 845 | get_property(LINK_DEPENDS TARGET ${DEPENDS_TRGT} PROPERTY LINK_DEPENDS) 846 | get_property(LINK_FLAGS TARGET ${DEPENDS_TRGT} PROPERTY LINK_FLAGS) 847 | get_property(LINK_FLAGS_${CMAKE_BUILD_TYPE} 848 | TARGET ${DEPENDS_TRGT} 849 | PROPERTY LINK_FLAGS_${CMAKE_BUILD_TYPE}) 850 | get_property(INTERFACE_LINK_LIBRARIES 851 | TARGET ${DEPENDS_TRGT} 852 | PROPERTY INTERFACE_LINK_LIBRARIES) 853 | get_property(LINK_LIBRARIES TARGET ${DEPENDS_TRGT} PROPERTY LINK_LIBRARIES) 854 | get_property(LINK_INTERFACE_LIBRARIES 855 | TARGET ${DEPENDS_TRGT} 856 | PROPERTY LINK_INTERFACE_LIBRARIES) 857 | get_property(LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE} 858 | TARGET ${DEPENDS_TRGT} 859 | PROPERTY LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE}) 860 | get_property(SHORT_NAME TARGET ${DEPENDS_TRGT} PROPERTY LLVMIR_SHORT_NAME) 861 | 862 | if(NOT "${IN_LLVMIR_TYPE}" STREQUAL "${LLVMIR_BINARY_TYPE}" AND 863 | NOT "${IN_LLVMIR_TYPE}" STREQUAL "${LLVMIR_OBJECT_TYPE}") 864 | message(FATAL_ERROR "Cannot attach ${TRGT} to a ${IN_LLVMIR_TYPE} target.") 865 | endif() 866 | 867 | ## main operations 868 | set(OUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/${LLVMIR_DIR}/${TRGT}") 869 | file(MAKE_DIRECTORY "${OUT_DIR}") 870 | 871 | set(IN_FULL_LLVMIR_FILES "") 872 | foreach(IN_LLVMIR_FILE ${INFILES}) 873 | list(APPEND IN_FULL_LLVMIR_FILES "${IN_LLVMIR_DIR}/${IN_LLVMIR_FILE}") 874 | endforeach() 875 | 876 | 877 | add_executable(${TRGT} ${IN_FULL_LLVMIR_FILES}) 878 | 879 | if(SHORT_NAME) 880 | set_property(TARGET ${TRGT} PROPERTY OUTPUT_NAME ${SHORT_NAME}) 881 | endif() 882 | 883 | # simply setting the property does not seem to work 884 | #set_property(TARGET ${TRGT} 885 | #PROPERTY INTERFACE_LINK_LIBRARIES ${INTERFACE_LINK_LIBRARIES}) 886 | #set_property(TARGET ${TRGT} 887 | #PROPERTY LINK_INTERFACE_LIBRARIES ${LINK_INTERFACE_LIBRARIES}) 888 | #set_property(TARGET ${TRGT} 889 | #PROPERTY 890 | #LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE} 891 | #${LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE}}) 892 | 893 | # FIXME: cmake bags PUBLIC link dependencies under both interface and private 894 | # target properties, so for an exact propagation it is required to search for 895 | # elements that are only in the INTERFACE properties and set them as such 896 | # correctly with the target_link_libraries command 897 | if(INTERFACE_LINK_LIBRARIES) 898 | target_link_libraries(${TRGT} PUBLIC ${INTERFACE_LINK_LIBRARIES}) 899 | endif() 900 | if(LINK_INTERFACE_LIBRARIES) 901 | target_link_libraries(${TRGT} PUBLIC ${LINK_INTERFACE_LIBRARIES}) 902 | endif() 903 | if(LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE}) 904 | target_link_libraries(${TRGT} 905 | PUBLIC ${LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE}}) 906 | endif() 907 | 908 | set_property(TARGET ${TRGT} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${OUT_DIR}) 909 | set_property(TARGET ${TRGT} PROPERTY LINKER_LANGUAGE ${LINKER_LANGUAGE}) 910 | set_property(TARGET ${TRGT} PROPERTY LINK_DEPENDS ${LINK_DEPENDS}) 911 | set_property(TARGET ${TRGT} PROPERTY LINK_FLAGS ${LINK_FLAGS}) 912 | set_property(TARGET ${TRGT} 913 | PROPERTY LINK_FLAGS_${CMAKE_BUILD_TYPE} ${LINK_FLAGS_${CMAKE_BUILD_TYPE}}) 914 | set_property(TARGET ${TRGT} PROPERTY EXCLUDE_FROM_ALL On) 915 | set_property(TARGET ${TRGT} PROPERTY LLVMIR_SHORT_NAME ${SHORT_NAME}) 916 | 917 | # this marks the object as to be linked but not compiled 918 | foreach(IN_FULL_LLVMIR_FILE ${IN_FULL_LLVMIR_FILES}) 919 | set_property(SOURCE ${IN_FULL_LLVMIR_FILE} PROPERTY EXTERNAL_OBJECT TRUE) 920 | endforeach() 921 | 922 | ## postamble 923 | endfunction() 924 | 925 | # 926 | 927 | function(llvmir_attach_library) 928 | set(options) 929 | set(oneValueArgs TARGET DEPENDS) 930 | set(multiValueArgs) 931 | cmake_parse_arguments(LLVMIR_ATTACH 932 | "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) 933 | 934 | set(TRGT ${LLVMIR_ATTACH_TARGET}) 935 | set(DEPENDS_TRGT ${LLVMIR_ATTACH_DEPENDS}) 936 | 937 | # fallback to backwards compatible mode for argument parsing 938 | if(NOT TRGT AND NOT DEPENDS_TRGT) 939 | list(GET LLVMIR_ATTACH_UNPARSED_ARGUMENTS 0 TRGT) 940 | list(GET LLVMIR_ATTACH_UNPARSED_ARGUMENTS 1 DEPENDS_TRGT) 941 | list(REMOVE_AT LLVMIR_ATTACH_UNPARSED_ARGUMENTS 0 1) 942 | endif() 943 | 944 | if(NOT TRGT) 945 | message(FATAL_ERROR "llvmir_attach_library: missing TARGET option") 946 | endif() 947 | 948 | if(NOT DEPENDS_TRGT) 949 | message(FATAL_ERROR "llvmir_attach_library: missing DEPENDS option") 950 | endif() 951 | 952 | ## preamble 953 | llvmir_check_target_properties(${DEPENDS_TRGT}) 954 | 955 | get_property(IN_LLVMIR_TYPE TARGET ${DEPENDS_TRGT} PROPERTY LLVMIR_TYPE) 956 | get_property(LLVMIR_EXTERNAL_TYPE TARGET ${DEPENDS_TRGT} 957 | PROPERTY LLVMIR_EXTERNAL_TYPE) 958 | get_property(INFILES TARGET ${DEPENDS_TRGT} PROPERTY LLVMIR_FILES) 959 | get_property(IN_LLVMIR_DIR TARGET ${DEPENDS_TRGT} PROPERTY LLVMIR_DIR) 960 | get_property(LINKER_LANGUAGE TARGET ${DEPENDS_TRGT} PROPERTY LINKER_LANGUAGE) 961 | get_property(LINK_DEPENDS TARGET ${DEPENDS_TRGT} PROPERTY LINK_DEPENDS) 962 | get_property(LINK_FLAGS TARGET ${DEPENDS_TRGT} PROPERTY LINK_FLAGS) 963 | get_property(LINK_FLAGS_${CMAKE_BUILD_TYPE} 964 | TARGET ${DEPENDS_TRGT} 965 | PROPERTY LINK_FLAGS_${CMAKE_BUILD_TYPE}) 966 | get_property(INTERFACE_LINK_LIBRARIES 967 | TARGET ${DEPENDS_TRGT} 968 | PROPERTY INTERFACE_LINK_LIBRARIES) 969 | get_property(LINK_LIBRARIES TARGET ${DEPENDS_TRGT} PROPERTY LINK_LIBRARIES) 970 | get_property(LINK_INTERFACE_LIBRARIES 971 | TARGET ${DEPENDS_TRGT} 972 | PROPERTY LINK_INTERFACE_LIBRARIES) 973 | get_property(LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE} 974 | TARGET ${DEPENDS_TRGT} 975 | PROPERTY LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE}) 976 | get_property(SHORT_NAME TARGET ${DEPENDS_TRGT} PROPERTY LLVMIR_SHORT_NAME) 977 | 978 | if(NOT "${IN_LLVMIR_TYPE}" STREQUAL "${LLVMIR_BINARY_TYPE}" AND 979 | NOT "${IN_LLVMIR_TYPE}" STREQUAL "${LLVMIR_OBJECT_TYPE}") 980 | message(FATAL_ERROR "Cannot attach ${TRGT} to a ${IN_LLVMIR_TYPE} target.") 981 | endif() 982 | 983 | ## main operations 984 | set(OUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/${LLVMIR_DIR}/${TRGT}") 985 | file(MAKE_DIRECTORY "${OUT_DIR}") 986 | 987 | set(IN_FULL_LLVMIR_FILES "") 988 | foreach(IN_LLVMIR_FILE ${INFILES}) 989 | list(APPEND IN_FULL_LLVMIR_FILES "${IN_LLVMIR_DIR}/${IN_LLVMIR_FILE}") 990 | endforeach() 991 | 992 | # currenly unparsed args holds the library mode, e.g. SHARED, STATIC, etc 993 | add_library(${TRGT} 994 | ${LLVMIR_ATTACH_UNPARSED_ARGUMENTS} ${IN_FULL_LLVMIR_FILES}) 995 | 996 | if(SHORT_NAME) 997 | set_property(TARGET ${TRGT} PROPERTY OUTPUT_NAME ${SHORT_NAME}) 998 | endif() 999 | 1000 | # simply setting the property does not seem to work 1001 | #set_property(TARGET ${TRGT} 1002 | #PROPERTY INTERFACE_LINK_LIBRARIES ${INTERFACE_LINK_LIBRARIES}) 1003 | #set_property(TARGET ${TRGT} 1004 | #PROPERTY LINK_INTERFACE_LIBRARIES ${LINK_INTERFACE_LIBRARIES}) 1005 | #set_property(TARGET ${TRGT} 1006 | #PROPERTY 1007 | #LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE} 1008 | #${LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE}}) 1009 | 1010 | # FIXME: cmake bags PUBLIC link dependencies under both interface and private 1011 | # target properties, so for an exact propagation it is required to search for 1012 | # elements that are only in the INTERFACE properties and set them as such 1013 | # correctly with the target_link_libraries command 1014 | if(INTERFACE_LINK_LIBRARIES) 1015 | target_link_libraries(${TRGT} PUBLIC ${INTERFACE_LINK_LIBRARIES}) 1016 | endif() 1017 | if(LINK_INTERFACE_LIBRARIES) 1018 | target_link_libraries(${TRGT} PUBLIC ${LINK_INTERFACE_LIBRARIES}) 1019 | endif() 1020 | if(LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE}) 1021 | target_link_libraries(${TRGT} 1022 | PUBLIC ${LINK_INTERFACE_LIBRARIES_${CMAKE_BUILD_TYPE}}) 1023 | endif() 1024 | 1025 | set_property(TARGET ${TRGT} PROPERTY LIBRARY_OUTPUT_DIRECTORY ${OUT_DIR}) 1026 | set_property(TARGET ${TRGT} PROPERTY LINKER_LANGUAGE ${LINKER_LANGUAGE}) 1027 | set_property(TARGET ${TRGT} PROPERTY LINK_DEPENDS ${LINK_DEPENDS}) 1028 | set_property(TARGET ${TRGT} PROPERTY LINK_FLAGS ${LINK_FLAGS}) 1029 | set_property(TARGET ${TRGT} 1030 | PROPERTY LINK_FLAGS_${CMAKE_BUILD_TYPE} ${LINK_FLAGS_${CMAKE_BUILD_TYPE}}) 1031 | set_property(TARGET ${TRGT} PROPERTY EXCLUDE_FROM_ALL On) 1032 | set_property(TARGET ${TRGT} PROPERTY LLVMIR_SHORT_NAME ${SHORT_NAME}) 1033 | 1034 | # this marks the object as to be linked but not compiled 1035 | foreach(IN_FULL_LLVMIR_FILE ${IN_FULL_LLVMIR_FILES}) 1036 | set_property(SOURCE ${IN_FULL_LLVMIR_FILE} PROPERTY EXTERNAL_OBJECT TRUE) 1037 | endforeach() 1038 | 1039 | ## postamble 1040 | endfunction() 1041 | 1042 | --------------------------------------------------------------------------------