Skip to content

Commit

Permalink
updating cmake magic
Browse files Browse the repository at this point in the history
  • Loading branch information
leissa committed Nov 30, 2023
1 parent 0e2d002 commit fec271d
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 71 deletions.
95 changes: 60 additions & 35 deletions cmake/Thorin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,48 @@ add_thorin_plugin
Registers a new Thorin plugin.
```
add_thorin_plugin(<name>
add_thorin_plugin(<plugin_name>
[SOURCES <source>...]
[DEPENDS <other_plugin_name>...]
[HEADER_DEPENDS <other_plugin_name>...]
[HEADERS <header>...]
[PRIVATE <private_item>...]
[INTERFACE <interface_item>...]
[PUBLIC <public_item>...]
[INSTALL])
```
The `<name>` is expected to be the name of the plugin. This means, there
should be (relative to your CMakeLists.txt) a file `<name>/<name>.thorin`
containing the axiom declarations.
This will generate a header `plug/<name>/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_<name>` 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_<name> <path>..)`.
- `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 `<plugin_name>` is expected to be the name of the plugin. This means, there
should be (relative to your CMakeLists.txt) a file `<plugin_name>.thorin`
containing the axiom declarations. This will generate a header
`plug/<plugin_name>/autogen.h` that can be used in normalizers and passes to
identify the axioms. The command will create three targets:
1. `thorin_internal_<plugin_name>`: This is an internal target to bootstrap the
plugin, i.e. generate the header etc.
2. `thorin_interface_<plugin_name>`: This is a header-only `INTERFACE` library
that consists of all `<header>` files. It "links" via `INTERFACE` with all
`<interface_item>` targets. This means everybody who links to
`thorin_interface_<plugin_name>` will also have access to the include
directories of these targets. In addition, `thorin_interface_<plugin_name>`
depends on `thorin_internal_<plugin_name>`.
3. `thorin_<plugin_name>`: This is the actual `MODULE` library and conists of
all `<source>` files and links `PUBLIC` to `thorin_interface_<plugin_name>`.
Thus, all sources will have access to the headers of
`thorin_interface_<plugin_name>` 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
`<private_item>` build dependencies.
The `<source>` 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_<plugin_name> <path>...)`.
- `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!
Expand All @@ -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)
Expand Down Expand Up @@ -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}
Expand All @@ -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
Expand All @@ -140,6 +162,9 @@ function(add_thorin_plugin)
LIBRARY_OUTPUT_DIRECTORY ${LIB_DIR_PLUG}
)

#
# install
#
if(${PARSED_INSTALL})
install(
TARGETS
Expand Down
7 changes: 1 addition & 6 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 2 additions & 3 deletions plugins/affine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
10 changes: 4 additions & 6 deletions plugins/autodiff/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
5 changes: 2 additions & 3 deletions plugins/clos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
8 changes: 4 additions & 4 deletions plugins/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
10 changes: 4 additions & 6 deletions plugins/matrix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
4 changes: 2 additions & 2 deletions plugins/mem/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
4 changes: 2 additions & 2 deletions plugins/opt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
7 changes: 3 additions & 4 deletions plugins/regex/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

0 comments on commit fec271d

Please sign in to comment.