artichoke-lang/CMakeLists.txt
erick-alcachofa e1b9e054f3
feat(test, tokenizer): Add test suite, in Tokenizer fixed catched issues and range-based API
Signed-off-by: erick-alcachofa <erick@artichoke.dev>

This commit introduces a comprehensive test suite for the tokenizer
using the Catch2 framework. To support this and improve the project
structure, the build system and the tokenizer's API have been
significantly updated.

- Removed `cmake/testing.cmake` as it's no longer needed.
- A new `TokenizerRange` class provides a C++20-style range interface,
  allowing for simple `for-each` loop iteration over tokens. This is
  used extensively in the new tests.

- The CMake build system has been refactored:
    - An `ENABLE_TESTING` option (OFF by default) now controls whether
      the test suite is built.
    - The core library is now compiled into an object library, which is
      then used to produce both a shared (`.so`/`.dll`) and a static
      (`.a`/`.lib`) library. This improves build efficiency and provides
      more flexible linkage options.
    - The frontend executable now links against the static version of
      the library.

- Implemented tests for tokenizer using Catch2 framework, covering
  various cases like identifiers, keywords, numbers, etc. that already
  catched some issues in current implementation.

- Several parsing bugs and edge cases in the tokenizer were fixed,
  including the handling of unterminated strings and invalid numeric
  literals. The README has been updated with instructions for building
  and running tests.
2025-10-03 12:54:41 -06:00

74 lines
1.4 KiB
CMake

cmake_minimum_required(VERSION 3.20)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(
artichoke
VERSION 0.1.0
DESCRIPTION "artichoke programming language"
LANGUAGES CXX
)
set(PROJECT_URL "lang.artichoke.dev")
set(PROJECT_AUTHOR "erick-alcachofa")
set(PROJECT_AUTHOR_GITHUB "@erick-alcachofa")
option(ENABLE_TESTING "Enable build of tests for library" OFF)
add_subdirectory(lib)
add_subdirectory(frontend)
install(
TARGETS frontend
RUNTIME DESTINATION bin
)
get_target_property(
EXECUTABLE_NAME frontend
OUTPUT_NAME
)
install(
CODE "execute_process(
COMMAND ${CMAKE_COMMAND} -E create_symlink
\${CMAKE_INSTALL_PREFIX}/bin/${EXECUTABLE_NAME}
\${CMAKE_INSTALL_PREFIX}/bin/arti-c
)"
)
install(
TARGETS library library_static
EXPORT artichokeTargets
FILE_SET HEADERS
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)
install(
EXPORT artichokeTargets
FILE artichokeTargets.cmake
NAMESPACE artichoke::
DESTINATION lib/cmake/artichoke
)
include (CMakePackageConfigHelpers)
write_basic_package_version_file(
"artichokeConfigVersion.cmake"
VERSION ${artichoke_VERSION}
COMPATIBILITY AnyNewerVersion
)
install(
FILES "cmake/artichokeConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/artichokeConfigVersion.cmake"
DESTINATION lib/cmake/artichoke
)
if(ENABLE_TESTING)
add_subdirectory(tests)
endif()