2021-09-28 02:02:44 +08:00
|
|
|
cmake_minimum_required(VERSION 3.14)
|
2022-07-27 04:06:00 +08:00
|
|
|
project(
|
|
|
|
Codon
|
2022-12-13 10:00:32 +08:00
|
|
|
VERSION "0.15.2"
|
2022-07-27 04:06:00 +08:00
|
|
|
HOMEPAGE_URL "https://github.com/exaloop/codon"
|
|
|
|
DESCRIPTION "high-performance, extensible Python compiler")
|
2022-12-19 02:12:32 +08:00
|
|
|
set(CODON_JIT_PYTHON_VERSION "0.1.1")
|
2021-10-10 13:02:11 +08:00
|
|
|
configure_file("${PROJECT_SOURCE_DIR}/cmake/config.h.in"
|
2021-10-11 07:41:52 +08:00
|
|
|
"${PROJECT_SOURCE_DIR}/codon/config/config.h")
|
2022-08-03 02:53:17 +08:00
|
|
|
configure_file("${PROJECT_SOURCE_DIR}/cmake/config.py.in"
|
2022-12-13 09:54:01 +08:00
|
|
|
"${PROJECT_SOURCE_DIR}/extra/python/codon/version.py")
|
2021-09-28 02:02:44 +08:00
|
|
|
|
2021-12-01 00:50:28 +08:00
|
|
|
option(CODON_JUPYTER "build Codon Jupyter server" OFF)
|
2022-09-16 03:40:00 +08:00
|
|
|
option(CODON_GPU "build Codon GPU backend" OFF)
|
2021-12-01 00:50:28 +08:00
|
|
|
|
2021-09-28 02:02:44 +08:00
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
2022-02-18 11:03:07 +08:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
2022-07-27 04:06:00 +08:00
|
|
|
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
|
|
|
set(CMAKE_CXX_FLAGS
|
|
|
|
"${CMAKE_CXX_FLAGS} -pedantic -fvisibility-inlines-hidden -Wno-return-type-c-linkage -Wno-gnu-zero-variadic-macro-arguments -Wno-deprecated-declarations"
|
|
|
|
)
|
2022-02-18 11:03:07 +08:00
|
|
|
else()
|
2022-07-27 04:06:00 +08:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-return-type")
|
2022-02-18 11:03:07 +08:00
|
|
|
endif()
|
|
|
|
set(CMAKE_CXX_FLAGS_DEBUG "-g")
|
2022-07-27 04:06:00 +08:00
|
|
|
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
|
|
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-limit-debug-info")
|
2022-02-18 11:03:07 +08:00
|
|
|
endif()
|
2021-09-28 02:02:44 +08:00
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
|
|
|
|
include_directories(.)
|
|
|
|
|
2022-10-14 21:31:10 +08:00
|
|
|
set(APPLE_ARM OFF)
|
|
|
|
if (APPLE AND CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64")
|
|
|
|
set(APPLE_ARM ON)
|
|
|
|
endif()
|
|
|
|
|
2021-09-28 02:02:44 +08:00
|
|
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
|
|
|
find_package(Threads REQUIRED)
|
|
|
|
find_package(LLVM REQUIRED)
|
|
|
|
|
2022-12-05 08:45:21 +08:00
|
|
|
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
|
|
|
|
cmake_policy(SET CMP0135 NEW)
|
|
|
|
endif()
|
|
|
|
|
2021-09-28 02:02:44 +08:00
|
|
|
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
|
|
|
|
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
|
2021-10-10 13:02:11 +08:00
|
|
|
include(${CMAKE_SOURCE_DIR}/cmake/deps.cmake)
|
2021-09-28 02:02:44 +08:00
|
|
|
|
|
|
|
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
|
|
|
|
if(APPLE)
|
2022-07-27 04:06:00 +08:00
|
|
|
set(CMAKE_INSTALL_RPATH "@loader_path;@loader_path/../lib/codon")
|
|
|
|
set(STATIC_LIBCPP "")
|
2021-09-28 02:02:44 +08:00
|
|
|
else()
|
2022-07-27 04:06:00 +08:00
|
|
|
set(CMAKE_INSTALL_RPATH "$ORIGIN:$ORIGIN/../lib/codon")
|
|
|
|
set(STATIC_LIBCPP "-static-libstdc++")
|
2021-09-28 02:02:44 +08:00
|
|
|
endif()
|
|
|
|
|
2022-12-05 08:45:21 +08:00
|
|
|
add_executable(peg2cpp codon/util/peg2cpp.cpp)
|
|
|
|
target_include_directories(peg2cpp PRIVATE ${peglib_SOURCE_DIR})
|
|
|
|
target_link_libraries(peg2cpp PRIVATE Threads::Threads fmt)
|
2021-09-28 02:02:44 +08:00
|
|
|
add_custom_command(
|
2022-07-27 04:06:00 +08:00
|
|
|
OUTPUT codon_rules.cpp
|
|
|
|
COMMAND peg2cpp ${CMAKE_SOURCE_DIR}/codon/parser/peg/grammar.peg
|
|
|
|
codon_rules.cpp codon
|
|
|
|
DEPENDS peg2cpp codon/parser/peg/grammar.peg)
|
2021-09-28 02:02:44 +08:00
|
|
|
add_custom_command(
|
2022-07-27 04:06:00 +08:00
|
|
|
OUTPUT omp_rules.cpp
|
|
|
|
COMMAND peg2cpp ${CMAKE_SOURCE_DIR}/codon/parser/peg/openmp.peg omp_rules.cpp
|
|
|
|
omp
|
|
|
|
DEPENDS peg2cpp codon/parser/peg/openmp.peg)
|
2021-09-28 02:02:44 +08:00
|
|
|
|
2021-10-01 03:04:26 +08:00
|
|
|
# Codon runtime library
|
2022-07-27 04:06:00 +08:00
|
|
|
set(CODONRT_FILES codon/runtime/lib.h codon/runtime/lib.cpp
|
2022-09-16 03:40:00 +08:00
|
|
|
codon/runtime/re.cpp codon/runtime/exc.cpp
|
|
|
|
codon/runtime/gpu.cpp)
|
2021-10-01 03:04:26 +08:00
|
|
|
add_library(codonrt SHARED ${CODONRT_FILES})
|
2022-07-09 07:17:50 +08:00
|
|
|
add_dependencies(codonrt zlibstatic gc backtrace bz2 liblzma re2)
|
2022-10-14 21:31:10 +08:00
|
|
|
if(APPLE AND APPLE_ARM)
|
|
|
|
add_dependencies(codonrt unwind_shared)
|
|
|
|
endif()
|
2022-07-09 07:17:50 +08:00
|
|
|
target_include_directories(codonrt PRIVATE ${backtrace_SOURCE_DIR}
|
|
|
|
${re2_SOURCE_DIR}
|
2022-07-27 04:06:00 +08:00
|
|
|
"${gc_SOURCE_DIR}/include" runtime)
|
2022-12-05 08:45:21 +08:00
|
|
|
target_link_libraries(codonrt PRIVATE fmt omp backtrace ${STATIC_LIBCPP}
|
2022-07-27 04:06:00 +08:00
|
|
|
LLVMSupport)
|
2021-09-28 02:02:44 +08:00
|
|
|
if(APPLE)
|
2022-07-27 04:06:00 +08:00
|
|
|
target_link_libraries(
|
|
|
|
codonrt
|
|
|
|
PRIVATE -Wl,-force_load,$<TARGET_FILE:zlibstatic>
|
|
|
|
-Wl,-force_load,$<TARGET_FILE:gc>
|
|
|
|
-Wl,-force_load,$<TARGET_FILE:bz2>
|
|
|
|
-Wl,-force_load,$<TARGET_FILE:liblzma>
|
|
|
|
-Wl,-force_load,$<TARGET_FILE:re2>)
|
2021-09-28 02:02:44 +08:00
|
|
|
else()
|
2022-07-27 04:06:00 +08:00
|
|
|
target_link_libraries(
|
|
|
|
codonrt
|
|
|
|
PRIVATE -Wl,--whole-archive $<TARGET_FILE:zlibstatic> $<TARGET_FILE:gc>
|
|
|
|
$<TARGET_FILE:bz2> $<TARGET_FILE:liblzma> $<TARGET_FILE:re2>
|
|
|
|
-Wl,--no-whole-archive)
|
2021-09-28 02:02:44 +08:00
|
|
|
endif()
|
2021-12-01 00:50:28 +08:00
|
|
|
if(ASAN)
|
2022-07-27 04:06:00 +08:00
|
|
|
target_compile_options(
|
|
|
|
codonrt PRIVATE "-fno-omit-frame-pointer" "-fsanitize=address"
|
|
|
|
"-fsanitize-recover=address")
|
|
|
|
target_link_libraries(
|
|
|
|
codonrt PRIVATE "-fno-omit-frame-pointer" "-fsanitize=address"
|
|
|
|
"-fsanitize-recover=address")
|
2021-12-01 00:50:28 +08:00
|
|
|
endif()
|
2022-09-16 03:40:00 +08:00
|
|
|
if(CODON_GPU)
|
|
|
|
add_compile_definitions(CODON_GPU)
|
|
|
|
find_package(CUDAToolkit REQUIRED)
|
|
|
|
target_link_libraries(codonrt PRIVATE CUDA::cudart_static CUDA::cuda_driver)
|
|
|
|
endif()
|
2022-07-27 04:06:00 +08:00
|
|
|
add_custom_command(
|
|
|
|
TARGET codonrt
|
|
|
|
POST_BUILD
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:omp>
|
|
|
|
${CMAKE_BINARY_DIR})
|
2022-10-14 21:31:10 +08:00
|
|
|
if(APPLE AND APPLE_ARM)
|
|
|
|
add_custom_command(
|
|
|
|
TARGET codonrt
|
|
|
|
POST_BUILD
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:unwind_shared>
|
|
|
|
${CMAKE_BINARY_DIR})
|
|
|
|
endif()
|
2021-09-28 02:02:44 +08:00
|
|
|
|
2021-10-01 03:04:26 +08:00
|
|
|
# Codon compiler library
|
2021-09-28 02:02:44 +08:00
|
|
|
include_directories(${LLVM_INCLUDE_DIRS})
|
|
|
|
add_definitions(${LLVM_DEFINITIONS})
|
2021-10-01 03:04:26 +08:00
|
|
|
set(CODON_HPPFILES
|
2021-12-01 00:50:28 +08:00
|
|
|
codon/compiler/compiler.h
|
|
|
|
codon/compiler/debug_listener.h
|
|
|
|
codon/compiler/engine.h
|
|
|
|
codon/compiler/error.h
|
|
|
|
codon/compiler/jit.h
|
|
|
|
codon/compiler/memory_manager.h
|
2021-10-11 07:41:52 +08:00
|
|
|
codon/dsl/dsl.h
|
|
|
|
codon/dsl/plugins.h
|
|
|
|
codon/parser/ast.h
|
|
|
|
codon/parser/ast/expr.h
|
|
|
|
codon/parser/ast/stmt.h
|
|
|
|
codon/parser/ast/types.h
|
2022-12-05 08:45:21 +08:00
|
|
|
codon/parser/ast/types/type.h
|
|
|
|
codon/parser/ast/types/link.h
|
|
|
|
codon/parser/ast/types/class.h
|
|
|
|
codon/parser/ast/types/function.h
|
|
|
|
codon/parser/ast/types/union.h
|
|
|
|
codon/parser/ast/types/static.h
|
|
|
|
codon/parser/ast/types/traits.h
|
2021-10-11 07:41:52 +08:00
|
|
|
codon/parser/cache.h
|
|
|
|
codon/parser/common.h
|
|
|
|
codon/parser/ctx.h
|
|
|
|
codon/parser/peg/peg.h
|
|
|
|
codon/parser/peg/rules.h
|
|
|
|
codon/parser/visitors/doc/doc.h
|
|
|
|
codon/parser/visitors/format/format.h
|
|
|
|
codon/parser/visitors/simplify/simplify.h
|
2022-07-27 04:06:00 +08:00
|
|
|
codon/parser/visitors/simplify/ctx.h
|
2021-10-11 07:41:52 +08:00
|
|
|
codon/parser/visitors/translate/translate.h
|
|
|
|
codon/parser/visitors/translate/translate_ctx.h
|
|
|
|
codon/parser/visitors/typecheck/typecheck.h
|
2022-07-27 04:06:00 +08:00
|
|
|
codon/parser/visitors/typecheck/ctx.h
|
2021-10-11 07:41:52 +08:00
|
|
|
codon/parser/visitors/visitor.h
|
|
|
|
codon/sir/analyze/analysis.h
|
2022-07-02 23:48:19 +08:00
|
|
|
codon/sir/analyze/dataflow/capture.h
|
2021-10-11 07:41:52 +08:00
|
|
|
codon/sir/analyze/dataflow/cfg.h
|
|
|
|
codon/sir/analyze/dataflow/dominator.h
|
|
|
|
codon/sir/analyze/dataflow/reaching.h
|
|
|
|
codon/sir/analyze/module/global_vars.h
|
|
|
|
codon/sir/analyze/module/side_effect.h
|
|
|
|
codon/sir/attribute.h
|
|
|
|
codon/sir/base.h
|
|
|
|
codon/sir/const.h
|
|
|
|
codon/sir/dsl/codegen.h
|
|
|
|
codon/sir/dsl/nodes.h
|
|
|
|
codon/sir/flow.h
|
|
|
|
codon/sir/func.h
|
|
|
|
codon/sir/instr.h
|
2022-09-16 03:40:00 +08:00
|
|
|
codon/sir/llvm/gpu.h
|
2021-10-11 07:41:52 +08:00
|
|
|
codon/sir/llvm/llvisitor.h
|
|
|
|
codon/sir/llvm/llvm.h
|
2021-10-22 02:08:11 +08:00
|
|
|
codon/sir/llvm/optimize.h
|
2021-10-11 07:41:52 +08:00
|
|
|
codon/sir/module.h
|
|
|
|
codon/sir/sir.h
|
|
|
|
codon/sir/transform/cleanup/canonical.h
|
|
|
|
codon/sir/transform/cleanup/dead_code.h
|
|
|
|
codon/sir/transform/cleanup/global_demote.h
|
|
|
|
codon/sir/transform/cleanup/replacer.h
|
|
|
|
codon/sir/transform/folding/const_fold.h
|
|
|
|
codon/sir/transform/folding/const_prop.h
|
|
|
|
codon/sir/transform/folding/folding.h
|
|
|
|
codon/sir/transform/folding/rule.h
|
|
|
|
codon/sir/transform/lowering/imperative.h
|
|
|
|
codon/sir/transform/lowering/pipeline.h
|
|
|
|
codon/sir/transform/manager.h
|
|
|
|
codon/sir/transform/parallel/openmp.h
|
|
|
|
codon/sir/transform/parallel/schedule.h
|
|
|
|
codon/sir/transform/pass.h
|
|
|
|
codon/sir/transform/pythonic/dict.h
|
|
|
|
codon/sir/transform/pythonic/io.h
|
|
|
|
codon/sir/transform/pythonic/str.h
|
|
|
|
codon/sir/transform/rewrite.h
|
|
|
|
codon/sir/types/types.h
|
|
|
|
codon/sir/util/cloning.h
|
|
|
|
codon/sir/util/context.h
|
|
|
|
codon/sir/util/format.h
|
|
|
|
codon/sir/util/inlining.h
|
|
|
|
codon/sir/util/irtools.h
|
|
|
|
codon/sir/util/iterators.h
|
|
|
|
codon/sir/util/matching.h
|
|
|
|
codon/sir/util/operator.h
|
|
|
|
codon/sir/util/outlining.h
|
|
|
|
codon/sir/util/packs.h
|
2022-07-02 23:48:19 +08:00
|
|
|
codon/sir/util/side_effect.h
|
2021-10-11 07:41:52 +08:00
|
|
|
codon/sir/util/visitor.h
|
|
|
|
codon/sir/value.h
|
|
|
|
codon/sir/var.h
|
|
|
|
codon/util/common.h
|
2022-09-16 21:03:57 +08:00
|
|
|
extra/jupyter/jupyter.h
|
2022-12-19 02:12:32 +08:00
|
|
|
codon/compiler/jit_extern.h)
|
2021-10-01 03:04:26 +08:00
|
|
|
set(CODON_CPPFILES
|
2021-12-01 00:50:28 +08:00
|
|
|
codon/compiler/compiler.cpp
|
|
|
|
codon/compiler/debug_listener.cpp
|
|
|
|
codon/compiler/engine.cpp
|
|
|
|
codon/compiler/error.cpp
|
|
|
|
codon/compiler/jit.cpp
|
|
|
|
codon/compiler/memory_manager.cpp
|
2021-10-11 07:41:52 +08:00
|
|
|
codon/dsl/plugins.cpp
|
|
|
|
codon/parser/ast/expr.cpp
|
|
|
|
codon/parser/ast/stmt.cpp
|
2022-12-05 08:45:21 +08:00
|
|
|
codon/parser/ast/types/type.cpp
|
|
|
|
codon/parser/ast/types/link.cpp
|
|
|
|
codon/parser/ast/types/class.cpp
|
|
|
|
codon/parser/ast/types/function.cpp
|
|
|
|
codon/parser/ast/types/union.cpp
|
|
|
|
codon/parser/ast/types/static.cpp
|
|
|
|
codon/parser/ast/types/traits.cpp
|
2021-10-11 07:41:52 +08:00
|
|
|
codon/parser/cache.cpp
|
|
|
|
codon/parser/common.cpp
|
|
|
|
codon/parser/peg/peg.cpp
|
|
|
|
codon/parser/visitors/doc/doc.cpp
|
|
|
|
codon/parser/visitors/format/format.cpp
|
|
|
|
codon/parser/visitors/simplify/simplify.cpp
|
2022-07-27 04:06:00 +08:00
|
|
|
codon/parser/visitors/simplify/ctx.cpp
|
|
|
|
codon/parser/visitors/simplify/assign.cpp
|
|
|
|
codon/parser/visitors/simplify/basic.cpp
|
|
|
|
codon/parser/visitors/simplify/call.cpp
|
|
|
|
codon/parser/visitors/simplify/class.cpp
|
|
|
|
codon/parser/visitors/simplify/collections.cpp
|
|
|
|
codon/parser/visitors/simplify/cond.cpp
|
|
|
|
codon/parser/visitors/simplify/function.cpp
|
|
|
|
codon/parser/visitors/simplify/access.cpp
|
|
|
|
codon/parser/visitors/simplify/import.cpp
|
|
|
|
codon/parser/visitors/simplify/loops.cpp
|
|
|
|
codon/parser/visitors/simplify/op.cpp
|
|
|
|
codon/parser/visitors/simplify/error.cpp
|
2021-10-11 07:41:52 +08:00
|
|
|
codon/parser/visitors/translate/translate.cpp
|
|
|
|
codon/parser/visitors/translate/translate_ctx.cpp
|
|
|
|
codon/parser/visitors/typecheck/typecheck.cpp
|
2022-07-27 04:06:00 +08:00
|
|
|
codon/parser/visitors/typecheck/infer.cpp
|
|
|
|
codon/parser/visitors/typecheck/ctx.cpp
|
|
|
|
codon/parser/visitors/typecheck/assign.cpp
|
|
|
|
codon/parser/visitors/typecheck/basic.cpp
|
|
|
|
codon/parser/visitors/typecheck/call.cpp
|
|
|
|
codon/parser/visitors/typecheck/class.cpp
|
|
|
|
codon/parser/visitors/typecheck/collections.cpp
|
|
|
|
codon/parser/visitors/typecheck/cond.cpp
|
|
|
|
codon/parser/visitors/typecheck/function.cpp
|
|
|
|
codon/parser/visitors/typecheck/access.cpp
|
|
|
|
codon/parser/visitors/typecheck/loops.cpp
|
|
|
|
codon/parser/visitors/typecheck/op.cpp
|
|
|
|
codon/parser/visitors/typecheck/error.cpp
|
2021-10-11 07:41:52 +08:00
|
|
|
codon/parser/visitors/visitor.cpp
|
|
|
|
codon/sir/attribute.cpp
|
|
|
|
codon/sir/analyze/analysis.cpp
|
2022-07-02 23:48:19 +08:00
|
|
|
codon/sir/analyze/dataflow/capture.cpp
|
2021-10-11 07:41:52 +08:00
|
|
|
codon/sir/analyze/dataflow/cfg.cpp
|
|
|
|
codon/sir/analyze/dataflow/dominator.cpp
|
|
|
|
codon/sir/analyze/dataflow/reaching.cpp
|
|
|
|
codon/sir/analyze/module/global_vars.cpp
|
|
|
|
codon/sir/analyze/module/side_effect.cpp
|
|
|
|
codon/sir/base.cpp
|
|
|
|
codon/sir/const.cpp
|
|
|
|
codon/sir/dsl/nodes.cpp
|
|
|
|
codon/sir/flow.cpp
|
|
|
|
codon/sir/func.cpp
|
|
|
|
codon/sir/instr.cpp
|
2022-09-16 03:40:00 +08:00
|
|
|
codon/sir/llvm/gpu.cpp
|
2021-10-11 07:41:52 +08:00
|
|
|
codon/sir/llvm/llvisitor.cpp
|
2021-10-22 02:08:11 +08:00
|
|
|
codon/sir/llvm/optimize.cpp
|
2021-10-11 07:41:52 +08:00
|
|
|
codon/sir/module.cpp
|
|
|
|
codon/sir/transform/cleanup/canonical.cpp
|
|
|
|
codon/sir/transform/cleanup/dead_code.cpp
|
|
|
|
codon/sir/transform/cleanup/global_demote.cpp
|
|
|
|
codon/sir/transform/cleanup/replacer.cpp
|
|
|
|
codon/sir/transform/folding/const_fold.cpp
|
|
|
|
codon/sir/transform/folding/const_prop.cpp
|
|
|
|
codon/sir/transform/folding/folding.cpp
|
|
|
|
codon/sir/transform/lowering/imperative.cpp
|
|
|
|
codon/sir/transform/lowering/pipeline.cpp
|
|
|
|
codon/sir/transform/manager.cpp
|
|
|
|
codon/sir/transform/parallel/openmp.cpp
|
|
|
|
codon/sir/transform/parallel/schedule.cpp
|
|
|
|
codon/sir/transform/pass.cpp
|
|
|
|
codon/sir/transform/pythonic/dict.cpp
|
|
|
|
codon/sir/transform/pythonic/io.cpp
|
|
|
|
codon/sir/transform/pythonic/str.cpp
|
|
|
|
codon/sir/types/types.cpp
|
|
|
|
codon/sir/util/cloning.cpp
|
|
|
|
codon/sir/util/format.cpp
|
|
|
|
codon/sir/util/inlining.cpp
|
|
|
|
codon/sir/util/irtools.cpp
|
|
|
|
codon/sir/util/matching.cpp
|
|
|
|
codon/sir/util/outlining.cpp
|
2022-07-02 23:48:19 +08:00
|
|
|
codon/sir/util/side_effect.cpp
|
2021-10-11 07:41:52 +08:00
|
|
|
codon/sir/util/visitor.cpp
|
|
|
|
codon/sir/value.cpp
|
|
|
|
codon/sir/var.cpp
|
|
|
|
codon/util/common.cpp
|
2021-12-30 05:11:56 +08:00
|
|
|
extra/jupyter/jupyter.cpp)
|
2021-10-01 03:04:26 +08:00
|
|
|
add_library(codonc SHARED ${CODON_HPPFILES})
|
2022-12-05 08:45:21 +08:00
|
|
|
target_include_directories(codonc PRIVATE ${peglib_SOURCE_DIR} ${toml_SOURCE_DIR}/include ${semver_SOURCE_DIR}/include)
|
2021-10-11 07:41:52 +08:00
|
|
|
target_sources(codonc PRIVATE ${CODON_CPPFILES} codon_rules.cpp omp_rules.cpp)
|
2021-12-01 00:50:28 +08:00
|
|
|
if(CODON_JUPYTER)
|
2022-07-27 04:06:00 +08:00
|
|
|
add_compile_definitions(CODON_JUPYTER)
|
|
|
|
add_dependencies(codonc xeus-static nlohmann_json)
|
|
|
|
target_link_libraries(codonc PRIVATE xeus-static)
|
2021-12-01 00:50:28 +08:00
|
|
|
endif()
|
|
|
|
if(ASAN)
|
2022-07-27 04:06:00 +08:00
|
|
|
target_compile_options(
|
|
|
|
codonc PRIVATE "-fno-omit-frame-pointer" "-fsanitize=address"
|
|
|
|
"-fsanitize-recover=address")
|
|
|
|
target_link_libraries(
|
|
|
|
codonc PRIVATE "-fno-omit-frame-pointer" "-fsanitize=address"
|
|
|
|
"-fsanitize-recover=address")
|
2021-12-01 00:50:28 +08:00
|
|
|
endif()
|
2021-09-28 02:02:44 +08:00
|
|
|
if(CMAKE_BUILD_TYPE MATCHES Debug)
|
2022-07-27 04:06:00 +08:00
|
|
|
set_source_files_properties(codon_rules.cpp codon/parser/peg/peg.cpp
|
|
|
|
PROPERTIES COMPILE_FLAGS "-O2")
|
2021-09-28 02:02:44 +08:00
|
|
|
endif()
|
2022-07-27 04:06:00 +08:00
|
|
|
llvm_map_components_to_libnames(
|
|
|
|
LLVM_LIBS
|
|
|
|
AllTargetsAsmParsers
|
|
|
|
AllTargetsCodeGens
|
|
|
|
AllTargetsDescs
|
|
|
|
AllTargetsInfos
|
|
|
|
AggressiveInstCombine
|
|
|
|
Analysis
|
|
|
|
AsmParser
|
|
|
|
BitWriter
|
|
|
|
CodeGen
|
|
|
|
Core
|
|
|
|
Extensions
|
|
|
|
IPO
|
|
|
|
IRReader
|
|
|
|
InstCombine
|
|
|
|
Instrumentation
|
|
|
|
MC
|
|
|
|
MCJIT
|
|
|
|
ObjCARCOpts
|
|
|
|
OrcJIT
|
|
|
|
Remarks
|
|
|
|
ScalarOpts
|
|
|
|
Support
|
|
|
|
Symbolize
|
|
|
|
Target
|
|
|
|
TransformUtils
|
|
|
|
Vectorize
|
|
|
|
Passes)
|
2021-09-28 02:02:44 +08:00
|
|
|
if(APPLE)
|
2022-12-05 08:45:21 +08:00
|
|
|
target_link_libraries(codonc PRIVATE ${LLVM_LIBS} fmt dl codonrt)
|
2021-09-28 02:02:44 +08:00
|
|
|
else()
|
2022-12-05 08:45:21 +08:00
|
|
|
target_link_libraries(codonc PRIVATE ${STATIC_LIBCPP} ${LLVM_LIBS} fmt dl codonrt)
|
2021-09-28 02:02:44 +08:00
|
|
|
endif()
|
|
|
|
|
2021-10-11 02:41:10 +08:00
|
|
|
# Gather headers
|
|
|
|
add_custom_target(
|
2022-07-27 04:06:00 +08:00
|
|
|
headers ALL
|
|
|
|
COMMENT "Collecting headers"
|
|
|
|
BYPRODUCTS "${CMAKE_BINARY_DIR}/include"
|
|
|
|
VERBATIM
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/include/codon"
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/codon"
|
|
|
|
"${CMAKE_BINARY_DIR}/include/codon"
|
|
|
|
COMMAND find "${CMAKE_BINARY_DIR}/include" -type f ! -name "*.h" -exec rm {}
|
|
|
|
\\;)
|
2021-10-11 02:41:10 +08:00
|
|
|
add_dependencies(headers codonrt codonc)
|
|
|
|
|
2022-06-27 05:38:29 +08:00
|
|
|
# Prepare lib directory for plugin compilation
|
|
|
|
add_custom_target(
|
2022-07-27 04:06:00 +08:00
|
|
|
libs ALL
|
|
|
|
COMMENT "Collecting libraries"
|
|
|
|
BYPRODUCTS "${CMAKE_BINARY_DIR}/lib"
|
|
|
|
VERBATIM
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/lib/codon"
|
|
|
|
COMMAND
|
|
|
|
${CMAKE_COMMAND} -E copy
|
|
|
|
"${CMAKE_BINARY_DIR}/libcodonc${CMAKE_SHARED_LIBRARY_SUFFIX}"
|
|
|
|
"${CMAKE_BINARY_DIR}/lib/codon"
|
|
|
|
COMMAND
|
|
|
|
${CMAKE_COMMAND} -E copy
|
|
|
|
"${CMAKE_BINARY_DIR}/libcodonrt${CMAKE_SHARED_LIBRARY_SUFFIX}"
|
|
|
|
"${CMAKE_BINARY_DIR}/lib/codon"
|
|
|
|
COMMAND
|
|
|
|
${CMAKE_COMMAND} -E copy
|
|
|
|
"${CMAKE_BINARY_DIR}/libomp${CMAKE_SHARED_LIBRARY_SUFFIX}"
|
|
|
|
"${CMAKE_BINARY_DIR}/lib/codon")
|
2022-06-27 05:38:29 +08:00
|
|
|
add_dependencies(libs codonrt codonc)
|
|
|
|
|
2022-10-14 21:31:10 +08:00
|
|
|
if(APPLE AND APPLE_ARM)
|
2022-12-05 08:45:21 +08:00
|
|
|
# add_custom_target(
|
|
|
|
# libs_apple_arm ALL
|
|
|
|
# COMMENT "Collecting Apple-specific libraries"
|
|
|
|
# BYPRODUCTS "${CMAKE_BINARY_DIR}/lib"
|
|
|
|
# VERBATIM
|
|
|
|
# COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/lib/codon"
|
|
|
|
# COMMAND
|
|
|
|
# ${CMAKE_COMMAND} -E copy
|
|
|
|
# "${CMAKE_BINARY_DIR}/libunwind${CMAKE_SHARED_LIBRARY_SUFFIX}"
|
|
|
|
# "${CMAKE_BINARY_DIR}/lib/codon")
|
|
|
|
# add_dependencies(libs_apple_arm codonrt)
|
2022-10-14 21:31:10 +08:00
|
|
|
endif()
|
|
|
|
|
2021-10-01 03:04:26 +08:00
|
|
|
# Codon command-line tool
|
2021-10-11 07:41:52 +08:00
|
|
|
add_executable(codon codon/app/main.cpp)
|
2022-12-05 08:45:21 +08:00
|
|
|
target_link_libraries(codon PUBLIC ${STATIC_LIBCPP} fmt codonc Threads::Threads)
|
2021-09-28 02:02:44 +08:00
|
|
|
|
2022-07-27 04:06:00 +08:00
|
|
|
# Codon test Download and unpack googletest at configure time
|
2021-09-28 02:02:44 +08:00
|
|
|
include(FetchContent)
|
2022-07-27 04:06:00 +08:00
|
|
|
FetchContent_Declare(
|
|
|
|
googletest
|
|
|
|
URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip
|
|
|
|
)
|
2021-09-28 02:02:44 +08:00
|
|
|
# For Windows: Prevent overriding the parent project's compiler/linker settings
|
2022-12-13 09:54:01 +08:00
|
|
|
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
|
|
|
option(INSTALL_GTEST "Enable installation of googletest." OFF)
|
2021-09-28 02:02:44 +08:00
|
|
|
FetchContent_MakeAvailable(googletest)
|
|
|
|
enable_testing()
|
2021-10-01 03:04:26 +08:00
|
|
|
set(CODON_TEST_CPPFILES
|
2021-09-28 02:02:44 +08:00
|
|
|
test/main.cpp
|
|
|
|
test/sir/analyze/dominator.cpp
|
|
|
|
test/sir/analyze/reaching.cpp
|
|
|
|
test/sir/base.cpp
|
|
|
|
test/sir/constant.cpp
|
|
|
|
test/sir/flow.cpp
|
|
|
|
test/sir/func.cpp
|
|
|
|
test/sir/instr.cpp
|
|
|
|
test/sir/module.cpp
|
|
|
|
test/sir/transform/manager.cpp
|
|
|
|
test/sir/types/types.cpp
|
|
|
|
test/sir/util/matching.cpp
|
|
|
|
test/sir/value.cpp
|
|
|
|
test/sir/var.cpp
|
|
|
|
test/types.cpp)
|
2021-10-01 03:04:26 +08:00
|
|
|
add_executable(codon_test ${CODON_TEST_CPPFILES})
|
2022-07-27 04:06:00 +08:00
|
|
|
target_include_directories(codon_test PRIVATE test/sir
|
|
|
|
"${gc_SOURCE_DIR}/include")
|
2022-12-05 08:45:21 +08:00
|
|
|
target_link_libraries(codon_test fmt codonc codonrt gtest_main)
|
2022-07-27 04:06:00 +08:00
|
|
|
target_compile_definitions(codon_test
|
|
|
|
PRIVATE TEST_DIR="${CMAKE_CURRENT_SOURCE_DIR}/test")
|
2022-12-08 11:42:29 +08:00
|
|
|
|
|
|
|
install(TARGETS codonrt codonc DESTINATION lib/codon)
|
|
|
|
install(FILES ${CMAKE_BINARY_DIR}/libomp${CMAKE_SHARED_LIBRARY_SUFFIX} DESTINATION lib/codon)
|
|
|
|
install(TARGETS codon DESTINATION bin)
|
|
|
|
install(DIRECTORY ${CMAKE_BINARY_DIR}/include/codon DESTINATION include)
|
|
|
|
install(DIRECTORY ${CMAKE_SOURCE_DIR}/stdlib DESTINATION lib/codon)
|
2022-12-13 09:54:01 +08:00
|
|
|
install(DIRECTORY ${CMAKE_SOURCE_DIR}/extra/python/ DESTINATION python)
|
2022-12-08 11:42:29 +08:00
|
|
|
install(DIRECTORY DESTINATION lib/codon/plugins)
|