Files
Lua-compilateur/CMakeLists.txt
T
BlackAngelTV 51fd2d5b4a chore: trim the ignore rules and drop stale build output
The gitignore came from a generic C++ template in which almost no pattern
applies here, and build/ still held files from the removed example project.
The generated luacpp-build directory is now ignored too.
2026-11-18 08:48:05 +01:00

64 lines
2.2 KiB
CMake

cmake_minimum_required(VERSION 3.20)
project(luacpp VERSION 0.2.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
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 ----------------------------------------------------------------
# `luacpp run` needs to invoke the C++ compiler and link the Lua VM itself, so
# the include path and link flags are baked into the binary at configure time.
if(LUA54_FOUND)
execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --cflags lua5.4
OUTPUT_VARIABLE _lua_cflags OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --libs lua5.4
OUTPUT_VARIABLE _lua_libs OUTPUT_STRIP_TRAILING_WHITESPACE)
else()
set(_lua_cflags "-I${LUA_INCLUDE_DIR}")
string(REPLACE ";" " " _lua_libs "${LUA_LIBRARIES}")
endif()
set(LUACPP_RUNTIME_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
set(LUACPP_LUA_CFLAGS "${_lua_cflags}")
set(LUACPP_LUA_LIBS "${_lua_libs}")
configure_file(cmake/luacpp-config.hpp.in
"${CMAKE_CURRENT_BINARY_DIR}/generated/luacpp-config.hpp" @ONLY)
add_executable(luacpp
src/main.cpp
src/frontend.cpp
src/codegen.cpp)
target_include_directories(luacpp PRIVATE src "${CMAKE_CURRENT_BINARY_DIR}/generated")
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_TESTS)
enable_testing()
add_subdirectory(tests)
endif()