diff --git a/.gitignore b/.gitignore index 09e5455..3b91ada 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ Makefile # Generated files *.log *.out +.cache/ # macOS .DS_Store diff --git a/CMakeLists.txt b/CMakeLists.txt index 184c923..50b1137 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,56 +1,78 @@ cmake_minimum_required(VERSION 3.30) project(camellya) -set(CMAKE_CXX_STANDARD 23) +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 - library.cpp - lexer.cpp - parser.cpp - value.cpp - interpreter.cpp - state.cpp + src/lexer.cpp + src/parser.cpp + src/value.cpp + src/interpreter.cpp + src/state.cpp ) +# Library headers set(LIB_HEADERS - library.h - lexer.h - parser.h - ast.h - value.h - interpreter.h - state.h + src/camellya.h + src/lexer.h + src/parser.h + src/ast.h + src/value.h + src/interpreter.h + src/state.h ) -# Build static library -add_library(camellya STATIC ${LIB_SOURCES} ${LIB_HEADERS}) +if(CAMELLYA_BUILD_STATIC) + add_library(libcamellya STATIC ${LIB_SOURCES} ${LIB_HEADERS}) +elseif() + add_library(libcamellya SHARED ${LIB_SOURCES} ${LIB_HEADERS}) +endif() -include(FetchContent) +target_include_directories(libcamellya PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src) -FetchContent_Declare( - Catch2 - GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG v3.6.0 -) +if(CAMELLYA_BUILD_CLI) + add_executable(camellya + cli/main.cpp + ) + target_link_libraries(camellya + PRIVATE + libcamellya + ) +endif() -FetchContent_MakeAvailable(Catch2) +if(CAMELLYA_BUILD_TESTS) + include(FetchContent) -enable_testing() + FetchContent_Declare( + Catch2 + GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GIT_TAG v3.12.0 + ) -add_executable(camellya_tests - tests/test_basic.cpp -) + FetchContent_MakeAvailable(Catch2) -target_include_directories(camellya_tests - PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR} -) + enable_testing() -target_link_libraries(camellya_tests - PRIVATE - camellya - Catch2::Catch2WithMain -) + add_executable(camellya_tests + tests/test_basic.cpp + ) -add_test(NAME camellya_tests COMMAND camellya_tests) \ No newline at end of file + target_include_directories(camellya_tests + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ) + + target_link_libraries(camellya_tests + PRIVATE + libcamellya + Catch2::Catch2WithMain + ) + + add_test(NAME camellya_tests COMMAND camellya_tests) +endif() diff --git a/cli/main.cpp b/cli/main.cpp new file mode 100644 index 0000000..efc6b19 --- /dev/null +++ b/cli/main.cpp @@ -0,0 +1,18 @@ +#include "camellya.h" +#include +#include +#include + +int main(int argc, char** argv) { + if(argc < 2){ + std::cout << std::format("Usage: camellya