aboutsummaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-13 03:54:49 +0000
committer_ov4 <ov4@ov4.org>2026-10-13 03:54:49 +0000
commite28cbb2efac9ed6e56cd9ab6eb1a3f16810d575a (patch)
treea0402247ba92259f6b7f3a2ad2c8ed0ca8eab3de /CMakeLists.txt
parentba1b65f4a20566405c53d4ded90b483ec9aa7d09 (diff)
feat: embed a statically linked LLVM execution engine
Add EMBEDDED mode to run generated modules in-process without lli or PATH lookup. Link LLVM and support archives plus the C++ runtime statically, while retaining the system C runtime on Linux. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt32
1 files changed, 25 insertions, 7 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b2cead4..c311928 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,10 +1,10 @@
cmake_minimum_required(VERSION 3.13)
project(cps_compiler)
-set(CPSC_RUN_MODE "" CACHE STRING "Execution mode: PATH or NONE (required)")
-set_property(CACHE CPSC_RUN_MODE PROPERTY STRINGS PATH NONE)
-if(NOT CPSC_RUN_MODE MATCHES "^(PATH|NONE)$")
- message(FATAL_ERROR "Specify -DCPSC_RUN_MODE=PATH or -DCPSC_RUN_MODE=NONE")
+set(CPSC_RUN_MODE "" CACHE STRING "Execution mode: PATH, EMBEDDED or NONE (required)")
+set_property(CACHE CPSC_RUN_MODE PROPERTY STRINGS PATH EMBEDDED NONE)
+if(NOT CPSC_RUN_MODE MATCHES "^(PATH|EMBEDDED|NONE)$")
+ message(FATAL_ERROR "Specify -DCPSC_RUN_MODE=PATH, EMBEDDED or NONE")
endif()
find_package(LLVM REQUIRED CONFIG)
@@ -18,15 +18,15 @@ set(CMAKE_CXX_STANDARD 17)
include_directories(include)
-add_library(CPSLexer lib/Lexer/Lexer.cc)
-add_library(CPSParser
+add_library(CPSLexer STATIC lib/Lexer/Lexer.cc)
+add_library(CPSParser STATIC
lib/Parser/Parser.cc
lib/Parser/ParserFunction.cc
lib/Parser/ParserFile.cc
lib/Parser/ParserType.cc
)
-add_library(CPSCodeGen
+add_library(CPSCodeGen STATIC
lib/CodeGen/CodeGen.cc
lib/CodeGen/Designator.cc
lib/CodeGen/ArrayHandler.cc
@@ -40,9 +40,27 @@ add_library(CPSCodeGen
)
llvm_map_components_to_libnames(llvm_libs core support)
+if(CPSC_RUN_MODE STREQUAL "EMBEDDED")
+ llvm_map_components_to_libnames(llvm_libs core support native mcjit)
+ foreach(llvm_lib IN LISTS llvm_libs)
+ get_target_property(llvm_type ${llvm_lib} TYPE)
+ if(NOT llvm_type STREQUAL "STATIC_LIBRARY")
+ message(FATAL_ERROR "EMBEDDED requires static LLVM libraries: ${llvm_lib}")
+ endif()
+ endforeach()
+ include(cmake/EmbeddedLLVM.cmake)
+endif()
add_executable(cpsc tools/driver/main.cc)
target_compile_definitions(cpsc PRIVATE CPSC_RUN_${CPSC_RUN_MODE})
+if(CPSC_RUN_MODE STREQUAL "EMBEDDED")
+ target_sources(cpsc PRIVATE tools/driver/EmbeddedRunner.cc)
+ if(MINGW)
+ target_link_options(cpsc PRIVATE -static)
+ elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" AND UNIX AND NOT APPLE)
+ target_link_options(cpsc PRIVATE -static-libstdc++ -static-libgcc)
+ endif()
+endif()
target_link_libraries(cpsc
CPSCodeGen
CPSParser