Skip to content

Commit

Permalink
Merge pull request #267 from AnyDSL/refactor/global_dirs
Browse files Browse the repository at this point in the history
Refactor/global dirs
  • Loading branch information
leissa authored Jan 18, 2024
2 parents 9c09ba9 + 1876fe7 commit dc42c9d
Show file tree
Hide file tree
Showing 169 changed files with 365 additions and 542 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
jobs:
build-and-test:
name: Build and test ${{matrix.build-type}} mode
runs-on: macos-11
runs-on: macos-13
strategy:
matrix:
build-type: [Debug, Release]
Expand All @@ -23,7 +23,7 @@ jobs:
uses: Chocobo1/setup-ccache-action@v1
with:
ccache_options: max_size=500M
override_cache_key: mac-11-ccache-${{matrix.build-type}}
override_cache_key: mac-13-ccache-${{matrix.build-type}}

- name: Install LLVM and Clang
run: brew install llvm@16
Expand Down
192 changes: 22 additions & 170 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(THORIN_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/thorin)

option(BUILD_SHARED_LIBS "Build shared libraries." ON)
option(THORIN_BUILD_DOCS "If ON, Thorin will build the documentation (requires Doxygen)." OFF)
option(THORIN_BUILD_EXAMPLES "If ON, Thorin will build examples." OFF)
option(THORIN_INSTALL_DEPENDENCIES "If ON, Thorin's dependencies will be installed alongside Thorin (use when not installing globally)." OFF)

message(STATUS "Build type: ${CMAKE_BUILD_TYPE}; shared libs: ${BUILD_SHARED_LIBS}")

Expand All @@ -43,6 +41,8 @@ else()
add_compile_options(-Wall -Wextra)
endif()

add_custom_target(thorin_all)

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
find_program(MEMORYCHECK_COMMAND valgrind)
set(VALGRIND_COMMAND_OPTIONS "--leak-check=full --error-exitcode=1")
Expand All @@ -62,172 +62,12 @@ set(ABSL_PROPAGATE_CXX_STD ON)
set(ABSL_USE_EXTERNAL_GOOGLETEST ON)
set(ABSL_ENABLE_INSTALL ON)
set(FE_ABSL ON)
set(FE_INSTALL_DEPENDENCIES ${THORIN_INSTALL_DEPENDENCIES})
if(NOT THORIN_INSTALL_DEPENDENCIES)
add_subdirectory(external/abseil-cpp EXCLUDE_FROM_ALL)
add_subdirectory(external/fe EXCLUDE_FROM_ALL)
add_subdirectory(external/lyra EXCLUDE_FROM_ALL)
add_subdirectory(external/rang EXCLUDE_FROM_ALL)
else()
add_subdirectory(external/abseil-cpp)
add_subdirectory(external/fe)
add_subdirectory(external/lyra)
add_subdirectory(external/rang)
endif()

add_library(libthorin)
target_sources(libthorin
PRIVATE
src/thorin/axiom.cpp
src/thorin/check.cpp
src/thorin/def.cpp
src/thorin/plugin.cpp
src/thorin/dump.cpp
src/thorin/driver.cpp
src/thorin/lam.cpp
src/thorin/lattice.cpp
src/thorin/rewrite.cpp
src/thorin/tuple.cpp
src/thorin/world.cpp
src/thorin/analyses/cfg.cpp
src/thorin/analyses/deptree.cpp
src/thorin/analyses/domfrontier.cpp
src/thorin/analyses/domtree.cpp
src/thorin/analyses/looptree.cpp
src/thorin/analyses/schedule.cpp
src/thorin/analyses/scope.cpp
src/thorin/be/dot/dot.cpp
src/thorin/be/h/bootstrap.cpp
src/thorin/fe/ast.cpp
src/thorin/fe/lexer.cpp
src/thorin/fe/parser.cpp
src/thorin/fe/scopes.cpp
src/thorin/fe/tok.cpp
src/thorin/pass/beta_red.cpp
src/thorin/pass/eta_exp.cpp
src/thorin/pass/eta_red.cpp
src/thorin/pass/lam_spec.cpp
src/thorin/pass/optimize.cpp
src/thorin/pass/pass.cpp
src/thorin/pass/pipelinebuilder.cpp
src/thorin/pass/ret_wrap.cpp
src/thorin/pass/scalarize.cpp
src/thorin/pass/tail_rec_elim.cpp
src/thorin/phase/phase.cpp
src/thorin/util/bitset.cpp
src/thorin/util/dbg.cpp
src/thorin/util/dl.cpp
src/thorin/util/hash.cpp
src/thorin/util/log.cpp
src/thorin/util/print.cpp
src/thorin/util/sys.cpp
PUBLIC
FILE_SET libthorin_headers
BASE_DIRS include
TYPE HEADERS
FILES
include/thorin/axiom.h
include/thorin/check.h
include/thorin/def.h
include/thorin/plugin.h
include/thorin/driver.h
include/thorin/lam.h
include/thorin/lattice.h
include/thorin/rewrite.h
include/thorin/tuple.h
include/thorin/world.h
include/thorin/analyses/cfg.h
include/thorin/analyses/deptree.h
include/thorin/analyses/domfrontier.h
include/thorin/analyses/domtree.h
include/thorin/analyses/looptree.h
include/thorin/analyses/schedule.h
include/thorin/analyses/scope.h
include/thorin/be/dot/dot.h
include/thorin/be/emitter.h
include/thorin/be/h/bootstrap.h
include/thorin/fe/ast.h
include/thorin/fe/lexer.h
include/thorin/fe/parser.h
include/thorin/fe/scopes.h
include/thorin/fe/tok.h
include/thorin/pass/beta_red.h
include/thorin/pass/eta_exp.h
include/thorin/pass/eta_red.h
include/thorin/pass/lam_spec.h
include/thorin/pass/pipelinebuilder.h
include/thorin/pass/ret_wrap.h
include/thorin/pass/scalarize.h
include/thorin/pass/tail_rec_elim.h
include/thorin/phase/phase.h
include/thorin/util/bitset.h
include/thorin/util/dbg.h
include/thorin/util/dl.h
include/thorin/util/hash.h
include/thorin/util/indexmap.h
include/thorin/util/indexset.h
include/thorin/util/log.h
include/thorin/util/print.h
include/thorin/util/span.h
include/thorin/util/sys.h
include/thorin/util/types.h
include/thorin/util/util.h
include/thorin/util/vector.h
)

set_target_properties(libthorin PROPERTIES PREFIX "")

if(MSVC)
target_compile_features(libthorin PUBLIC cxx_std_23) # /std:c++latest - unlocks non-stable c++20 features
target_compile_options(libthorin PUBLIC /utf-8 /wd4146 /wd4245)
if(BUILD_SHARED_LIBS)
target_compile_definitions(libthorin PUBLIC ABSL_CONSUME_DLL)
endif()
else()
target_compile_features(libthorin PUBLIC cxx_std_20)
endif()

configure_file(
include/thorin/config.h.in
"${CMAKE_BINARY_DIR}/include/thorin/config.h"
)
target_include_directories(libthorin
PUBLIC
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include> # for config.h
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/external/half/include>
)
target_link_libraries(libthorin
PUBLIC
absl::btree
absl::fixed_array
absl::inlined_vector
absl::flat_hash_map absl::flat_hash_set
absl::node_hash_map absl::node_hash_set
fe
rang
${CMAKE_DL_LIBS}
)
install(
TARGETS libthorin
EXPORT thorin-targets
FILE_SET libthorin_headers
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(
FILES "${CMAKE_BINARY_DIR}/include/thorin/config.h"
DESTINATION include/thorin
)
install(
FILES "${CMAKE_CURRENT_SOURCE_DIR}/../external/half/include/half.hpp"
DESTINATION include
)

add_subdirectory(cli)
add_subdirectory(libs)
add_subdirectory(plugins)
add_subdirectory(external/abseil-cpp)
add_subdirectory(external/fe)
add_subdirectory(external/lyra)
add_subdirectory(external/rang)
add_subdirectory(src)

if(THORIN_BUILD_EXAMPLES)
add_subdirectory(examples)
Expand All @@ -251,15 +91,27 @@ configure_package_config_file(
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/thorin"
)
install(
TARGETS libthorin
EXPORT thorin-targets
NAMESPACE thorin::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/thorin"
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(
FILES "${PROJECT_SOURCE_DIR}/external/half/include/half.hpp"
DESTINATION include
)
install(
FILES
cmake/Thorin.cmake
"${CMAKE_CURRENT_BINARY_DIR}/thorin-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/thorin-config-version.cmake"
DESTINATION
"${CMAKE_INSTALL_LIBDIR}/cmake/thorin"
${CMAKE_INSTALL_LIBDIR}/cmake/thorin
)
install(
EXPORT thorin-targets
NAMESPACE thorin::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/thorin
)
80 changes: 28 additions & 52 deletions cmake/Thorin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ endif()
function(add_thorin_plugin)
set(PLUGIN ${ARGV0})
cmake_parse_arguments(
PARSE_ARGV 1 # skip first arg
PARSED # prefix of output variables
"INSTALL" # options
"" # one-value keywords (none)
"HEADERS;SOURCES;PUBLIC;PRIVATE;INTERFACE" # multi-value keywords
PARSE_ARGV 1 # skip first arg
PARSED # prefix of output variables
"INSTALL" # options
"" # one-value keywords (none)
"SOURCES;PRIVATE" # multi-value keywords
)

list(TRANSFORM PARSED_INTERFACES PREPEND thorin_interface_ OUTPUT_VARIABLE INTERFACES)

set(PLUGIN_THORIN ${CMAKE_CURRENT_LIST_DIR}/${PLUGIN}.thorin)
set(OUT_PLUGIN_THORIN ${THORIN_LIBRARY_OUTPUT_DIRECTORY}/${PLUGIN}.thorin)
set(INCLUDE_DIR_PLUG ${CMAKE_BINARY_DIR}/include/thorin/plug/${PLUGIN})
set(OUT_PLUGIN_THORIN ${CMAKE_BINARY_DIR}/lib/thorin/${PLUGIN}.thorin)
set(PLUGIN_MD ${CMAKE_BINARY_DIR}/docs/plug/${PLUGIN}.md)
set(PLUGIN_D ${CMAKE_BINARY_DIR}/deps/${PLUGIN}.d)
set(AUTOGEN_H ${INCLUDE_DIR_PLUG}/autogen.h)
set(AUTOGEN_H ${CMAKE_BINARY_DIR}/include/thorin/plug/${PLUGIN}/autogen.h)

file(MAKE_DIRECTORY ${INCLUDE_DIR_PLUG})
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/deps)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/docs/plug/)
file(
MAKE_DIRECTORY
${CMAKE_BINARY_DIR}/docs/plug/
${CMAKE_BINARY_DIR}/deps
${CMAKE_BINARY_DIR}/include/thorin/plug/${PLUGIN}
)

add_custom_command(
OUTPUT
Expand Down Expand Up @@ -62,50 +62,31 @@ 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}
INTERFACE
FILE_SET thorin_headers_${PLUGIN}
TYPE HEADERS
BASE_DIRS
${CMAKE_CURRENT_LIST_DIR}/include
${CMAKE_BINARY_DIR}/include
FILES
${AUTOGEN_H} # the generated header of this plugin
${PARSED_HEADERS} # original headers passed to add_thorin_plugin
)
target_link_libraries(thorin_interface_${PLUGIN}
INTERFACE
${PARSED_INTERFACE}
libthorin
)

#
# thorin_plugin
#
add_library(thorin_${PLUGIN} MODULE)
add_dependencies(thorin_${PLUGIN} thorin_internal_${PLUGIN})
target_sources(thorin_${PLUGIN}
PRIVATE
${PARSED_SOURCES}
)
target_link_libraries(thorin_${PLUGIN}
target_include_directories(thorin_${PLUGIN}
PUBLIC
thorin_interface_${PLUGIN}
${PARSED_PUBLIC}
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include> # for autogen.h
)
target_link_libraries(thorin_${PLUGIN}
PRIVATE
${PARSED_PRIVATE}
${THORIN_TARGET_NAMESPACE}libthorin
)
set_target_properties(thorin_${PLUGIN}
PROPERTIES
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN 1
WINDOWS_EXPORT_ALL_SYMBOLS OFF
PREFIX "lib" # always use "lib" as prefix regardless of OS/compiler
LIBRARY_OUTPUT_DIRECTORY ${THORIN_LIBRARY_OUTPUT_DIRECTORY}
PREFIX "lib" # always use "lib" as prefix regardless of OS/compiler
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/thorin
)

#
Expand All @@ -114,25 +95,20 @@ function(add_thorin_plugin)
if(${PARSED_INSTALL})
install(
TARGETS
thorin_interface_${PLUGIN}
thorin_${PLUGIN}
EXPORT thorin-targets
FILE_SET thorin_headers_${PLUGIN}
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/thorin"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}/thorin"
RUNTIME DESTINATION "${CMAKE_INSTALL_LIBDIR}/thorin"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/thorin
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/thorin
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/thorin
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(
FILES ${LIB_DIR_PLUGIN_THORIN}
DESTINATION lib/thorin
FILES ${CMAKE_BINARY_DIR}/lib/thorin/${PLUGIN}.thorin
DESTINATION ${CMAKE_INSTALL_LIBDIR}/thorin
)
install(
FILES ${AUTOGEN_H}
DESTINATION "include/plug/${PLUGIN}"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/plug/${PLUGIN}
)
endif()
if(TARGET thorin_all_plugins)
add_dependencies(thorin_all_plugins thorin_${PLUGIN})
endif()
endfunction()
Loading

0 comments on commit dc42c9d

Please sign in to comment.