diff --git a/cmake/Thorin.cmake b/cmake/Thorin.cmake index 264a44bf8a..3520069b2c 100644 --- a/cmake/Thorin.cmake +++ b/cmake/Thorin.cmake @@ -13,40 +13,48 @@ add_thorin_plugin Registers a new Thorin plugin. ``` -add_thorin_plugin( +add_thorin_plugin( [SOURCES ...] - [DEPENDS ...] - [HEADER_DEPENDS ...] + [HEADERS
...] + [PRIVATE ...] + [INTERFACE ...] + [PUBLIC ...] [INSTALL]) ``` -The `` is expected to be the name of the plugin. This means, there -should be (relative to your CMakeLists.txt) a file `/.thorin` -containing the axiom declarations. -This will generate a header `plug//autogen.h` that can be used in normalizers -and passes to identify the axioms. - -- `SOURCES`: The values to the `SOURCES` argument are the source files used - to build the loadable plugin containing normalizers, passes and backends. - One of the source files must export the `thorin_get_plugin` function. - `add_thorin_plugin` creates a new target called `thorin_` that builds - the plugin. - Custom properties can be specified in the using `CMakeLists.txt` file, - e.g. adding include paths is done with `target_include_directories(thorin_ ..)`. -- `DEPENDS`: The `DEPENDS` arguments specify the relation between multiple - plugins. This makes sure that the bootstrapping of the plugin is done - whenever a depended-upon plugin description is changed. - E.g. `core` depends on `mem`, therefore whenever `mem.thorin` changes, - `core.thorin` has to be bootstrapped again as well. -- `HEADER_DEPENDS`: The `HEADER_DEPENDS` arguments specify dependencies - of a plugin on the generated header of another plugin. - E.g. `mem.thorin` does not import `core.thorin` but the plugin relies - on the `%core.conv` axiom. Therefore `mem` requires `core`'s autogenerated - header to be up-to-date. +The `` is expected to be the name of the plugin. This means, there +should be (relative to your CMakeLists.txt) a file `.thorin` +containing the axiom declarations. This will generate a header +`plug//autogen.h` that can be used in normalizers and passes to +identify the axioms. The command will create three targets: + +1. `thorin_internal_`: This is an internal target to bootstrap the + plugin, i.e. generate the header etc. +2. `thorin_interface_`: This is a header-only `INTERFACE` library + that consists of all `
` files. It "links" via `INTERFACE` with all + `` targets. This means everybody who links to + `thorin_interface_` will also have access to the include + directories of these targets. In addition, `thorin_interface_` + depends on `thorin_internal_`. +3. `thorin_`: This is the actual `MODULE` library and conists of + all `` files and links `PUBLIC` to `thorin_interface_`. + Thus, all sources will have access to the headers of + `thorin_interface_` and to all other targets specified via + `INTERFACE`. Furthermore, you can specify additional `public_item` targets that + the module should link against as `PUBLIC`. Finally, you can specify additional + `` build dependencies. + +The `` files are used to build the loadable plugin containing +normalizers, passes and backends. One of the source files must export the +`thorin_get_plugin` function. Custom properties can be specified in the +`CMakeLists.txt` file, e.g. adding include paths is done with +`target_include_directories(thorin_ ...)`. + - `INSTALL`: Specify, if the plugin description, plugin and headers shall be installed with `make install`. To export the targets, the export name `thorin-targets` has to be - exported accordingly (see [install(EXPORT ..)](https://cmake.org/cmake/help/latest/command/install.html#export)) + exported accordingly (see + [install(EXPORT ..)](https://cmake.org/cmake/help/latest/command/install.html#export)) ## Note: a copy of this text is in `docs/coding.md`. Please update! @@ -55,11 +63,11 @@ function(add_thorin_plugin) set(PLUGIN ${ARGV0}) list(SUBLIST ARGV 1 -1 UNPARSED) cmake_parse_arguments( - PARSED # prefix of output variables - "INSTALL" # list of names of the boolean arguments (only defined ones will be true) - "THORIN" # list of names of mono-valued arguments - "HEADERS;SOURCES;INTERFACES" # list of names of multi-valued arguments (output variables are lists) - ${UNPARSED} # arguments of the function to parse, here we take the all original ones + PARSED # prefix of output variables + "INSTALL" # list of names of the boolean arguments (only defined ones will be true) + "THORIN" # list of names of mono-valued arguments + "HEADERS;SOURCES;PUBLIC;PRIVATE;INTERFACE" # list of names of multi-valued arguments (output variables are lists) + ${UNPARSED} # arguments of the function to parse, here we take the all original ones ) list(TRANSFORM PARSED_INTERFACES PREPEND thorin_interface_ OUTPUT_VARIABLE INTERFACES) @@ -109,6 +117,9 @@ function(add_thorin_plugin) SET(THORIN_PLUGIN_LIST "${THORIN_PLUGIN_LIST}" CACHE INTERNAL "THORIN_PLUGIN_LIST") SET(THORIN_PLUGIN_LAYOUT "${THORIN_PLUGIN_LAYOUT}" CACHE INTERNAL "THORIN_PLUGIN_LAYOUT") + # + # thorin_interface_plugin + # add_library(thorin_interface_${PLUGIN} INTERFACE) add_dependencies(thorin_interface_${PLUGIN} thorin_internal_${PLUGIN}) target_sources(thorin_interface_${PLUGIN} @@ -122,14 +133,25 @@ function(add_thorin_plugin) ${AUTOGEN_H} # the generated header of this plugin ${PARSED_HEADERS} # original headers passed to add_thorin_plugin ) - target_link_libraries(thorin_interface_${PLUGIN} INTERFACE libthorin) + target_link_libraries(thorin_interface_${PLUGIN} + INTERFACE + ${PARSED_INTERFACE} + libthorin + ) + # + # thorin_plugin + # add_library(thorin_${PLUGIN} MODULE) - target_sources(thorin_${PLUGIN} PRIVATE ${PARSED_SOURCES}) + target_sources(thorin_${PLUGIN} + PRIVATE + ${PARSED_SOURCES} + ${PARSED_PRIVATE} + ) target_link_libraries(thorin_${PLUGIN} PUBLIC thorin_interface_${PLUGIN} - ${INTERFACES} + ${PARSED_PUBLIC} ) set_target_properties(thorin_${PLUGIN} PROPERTIES @@ -140,6 +162,9 @@ function(add_thorin_plugin) LIBRARY_OUTPUT_DIRECTORY ${LIB_DIR_PLUG} ) + # + # install + # if(${PARSED_INSTALL}) install( TARGETS diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 0e89054ac2..820fb8d8fe 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,9 +1,4 @@ add_executable(hello hello.cpp) -target_link_libraries(hello - PRIVATE - libthorin - thorin_interface_mem -) +target_link_libraries(hello PRIVATE thorin_interface_mem) set_target_properties(hello PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/examples") -add_dependencies(hello thorin_compile thorin_core) install(TARGETS hello EXPORT thorin-targets) diff --git a/plugins/affine/CMakeLists.txt b/plugins/affine/CMakeLists.txt index a75432a287..455dab342b 100644 --- a/plugins/affine/CMakeLists.txt +++ b/plugins/affine/CMakeLists.txt @@ -5,8 +5,7 @@ add_thorin_plugin(affine HEADERS include/thorin/plug/affine/affine.h include/thorin/plug/affine/pass/lower_for.h - INTERFACES - core - mem + INTERFACE + thorin_interface_core INSTALL ) diff --git a/plugins/autodiff/CMakeLists.txt b/plugins/autodiff/CMakeLists.txt index 606499e3d8..3c5028b3c1 100644 --- a/plugins/autodiff/CMakeLists.txt +++ b/plugins/autodiff/CMakeLists.txt @@ -13,11 +13,9 @@ add_thorin_plugin(autodiff include/thorin/plug/autodiff/pass/autodiff_eval.h include/thorin/plug/autodiff/pass/autodiff_zero.h include/thorin/plug/autodiff/pass/autodiff_zero_cleanup.h - INTERFACES - affine - compile - core - direct - mem + INTERFACE + thorin_interface_affine + thorin_interface_compile + thorin_interface_direct INSTALL ) diff --git a/plugins/clos/CMakeLists.txt b/plugins/clos/CMakeLists.txt index 8e8b1f82fa..eafe57d5a0 100644 --- a/plugins/clos/CMakeLists.txt +++ b/plugins/clos/CMakeLists.txt @@ -16,8 +16,7 @@ add_thorin_plugin(clos include/thorin/plug/clos/pass/lower_typed_clos_prep.h include/thorin/plug/clos/phase/clos_conv.h include/thorin/plug/clos/phase/lower_typed_clos.h - INTERFACES - core - mem + INTERFACE + thorin_interface_core INSTALL ) diff --git a/plugins/core/CMakeLists.txt b/plugins/core/CMakeLists.txt index f6f3f8846e..9e98c44610 100644 --- a/plugins/core/CMakeLists.txt +++ b/plugins/core/CMakeLists.txt @@ -6,9 +6,9 @@ add_thorin_plugin(core HEADERS include/thorin/plug/core/core.h include/thorin/plug/core/be/ll.h - INTERFACES - clos - math - mem + INTERFACE + thorin_interface_clos + thorin_interface_mem + thorin_interface_math INSTALL ) diff --git a/plugins/matrix/CMakeLists.txt b/plugins/matrix/CMakeLists.txt index 0462365e2d..4dd34f3980 100644 --- a/plugins/matrix/CMakeLists.txt +++ b/plugins/matrix/CMakeLists.txt @@ -11,11 +11,9 @@ add_thorin_plugin(matrix include/thorin/plug/matrix/pass/lower_matrix_highlevel.h include/thorin/plug/matrix/pass/lower_matrix_mediumlevel.h include/thorin/plug/matrix/pass/lower_matrix_lowlevel.h - INTERFACES - affine - compile - core - direct - mem + INTERFACE + thorin_interface_affine + thorin_interface_compile + thorin_interface_direct INSTALL ) diff --git a/plugins/mem/CMakeLists.txt b/plugins/mem/CMakeLists.txt index 234b79e377..3a137d1ce4 100644 --- a/plugins/mem/CMakeLists.txt +++ b/plugins/mem/CMakeLists.txt @@ -16,7 +16,7 @@ add_thorin_plugin(mem include/thorin/plug/mem/pass/reshape.h include/thorin/plug/mem/pass/ssa_constr.h include/thorin/plug/mem/phase/add_mem.h - INTERFACES - core + INTERFACE + thorin_interface_core INSTALL ) diff --git a/plugins/opt/CMakeLists.txt b/plugins/opt/CMakeLists.txt index d54fb26dcd..000d33c296 100644 --- a/plugins/opt/CMakeLists.txt +++ b/plugins/opt/CMakeLists.txt @@ -3,7 +3,7 @@ add_thorin_plugin(opt src/thorin/plug/opt/opt.cpp HEADERS include/thorin/plug/opt/opt.h - INTERFACES - compile + INTERFACE + thorin_interface_compile INSTALL ) diff --git a/plugins/regex/CMakeLists.txt b/plugins/regex/CMakeLists.txt index e69376b5c0..3fb2729d98 100644 --- a/plugins/regex/CMakeLists.txt +++ b/plugins/regex/CMakeLists.txt @@ -20,9 +20,8 @@ add_thorin_plugin(regex include/thorin/plug/regex/pass/dfa2matcher.h include/thorin/plug/regex/pass/lower_regex.h include/thorin/plug/regex/pass/regex2nfa.h - INTERFACES - core - direct - mem + INTERFACE + thorin_interface_core + thorin_interface_direct INSTALL )