Files
camellya/CMakeLists.txt
2026-01-19 23:12:02 +08:00

90 lines
1.7 KiB
CMake

cmake_minimum_required(VERSION 3.30)
project(camellya)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
option(CAMELLYA_BUILD_TESTS "Build tests" ON)
option(CAMELLYA_BUILD_STATIC "Build static library" ON)
option(CAMELLYA_BUILD_CLI "Build command line interface" ON)
# Library sources
set(LIB_SOURCES
src/lexer.cpp
src/parser.cpp
src/value.cpp
src/interpreter.cpp
src/state.cpp
src/chunk.cpp
src/compiler.cpp
src/vm.cpp
)
# Library headers
set(LIB_HEADERS
src/camellya.h
src/lexer.h
src/parser.h
src/ast.h
src/value.h
src/interpreter.h
src/state.h
src/chunk.h
src/compiler.h
src/vm.h
src/opcode.h
src/exceptions.h
)
if(CAMELLYA_BUILD_STATIC)
add_library(camellya STATIC ${LIB_SOURCES} ${LIB_HEADERS})
elseif()
add_library(camellya SHARED ${LIB_SOURCES} ${LIB_HEADERS})
endif()
target_include_directories(camellya PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
if(CAMELLYA_BUILD_CLI)
add_executable(chun
cli/main.cpp
)
target_link_libraries(chun
PRIVATE
camellya
)
endif()
if(CAMELLYA_BUILD_TESTS)
include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.12.0
)
FetchContent_MakeAvailable(Catch2)
enable_testing()
add_executable(camellya_tests
tests/test_basic.cpp
tests/test_utf8.cpp
tests/test_vm.cpp
)
target_include_directories(camellya_tests
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
)
target_link_libraries(camellya_tests
PRIVATE
camellya
Catch2::Catch2WithMain
)
add_test(NAME camellya_tests COMMAND camellya_tests)
endif()