Files
Lua-compilateur/CMakeLists.txt
T
BlackAngelTV ab5ff6978a feat(compiler): add a Lua 5.4 to C++ module transpiler
Each Lua module becomes a header/source pair exposing a C++ namespace, so Lua
code can be linked and consumed like any C++ package while keeping the exact
semantics of the official 5.4 VM.
2026-11-18 08:48:05 +01:00

52 lines
1.5 KiB
CMake

cmake_minimum_required(VERSION 3.20)
project(luacpp VERSION 0.1.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
option(LUACPP_BUILD_EXAMPLES "Build the example package and program" ON)
option(LUACPP_BUILD_TESTS "Build the conformance test" ON)
# --- Lua 5.4 -----------------------------------------------------------------
find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
pkg_check_modules(LUA54 QUIET IMPORTED_TARGET lua5.4)
endif()
if(NOT LUA54_FOUND)
find_package(Lua 5.4 REQUIRED)
endif()
add_library(luacpp_rt INTERFACE)
add_library(luacpp::rt ALIAS luacpp_rt)
target_include_directories(luacpp_rt INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include")
if(LUA54_FOUND)
target_link_libraries(luacpp_rt INTERFACE PkgConfig::LUA54)
message(STATUS "luacpp: using Lua 5.4 from pkg-config")
else()
target_include_directories(luacpp_rt INTERFACE ${LUA_INCLUDE_DIR})
target_link_libraries(luacpp_rt INTERFACE ${LUA_LIBRARIES})
message(STATUS "luacpp: using Lua 5.4 from FindLua")
endif()
# --- compiler ----------------------------------------------------------------
add_executable(luacpp
src/main.cpp
src/frontend.cpp
src/codegen.cpp)
target_include_directories(luacpp PRIVATE src)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(luacpp PRIVATE -Wall -Wextra -Wpedantic)
endif()
include(cmake/lua-package.cmake)
if(LUACPP_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
if(LUACPP_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()