cmake_minimum_required(VERSION 3.24)
project(MacroDown LANGUAGES CXX VERSION 0.1.0)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
# Strict compiler options
if(MSVC)
add_compile_options(/W4 /WX)
else()
add_compile_options(-Wall -Wextra -Wpedantic -Werror)
endif()
# Dependencies
include(FetchContent)
FetchContent_Declare(
uni-algo
URL https://github.com/uni-algo/uni-algo/archive/refs/tags/v1.2.0.zip
)
FetchContent_MakeAvailable(uni-algo)
# Source Configuration
# We will add source files explicitly to targets to avoid GLOB issues in larger projects.
add_library(macrodown_lib STATIC
src/macro_engine.cpp
src/parser.cpp
src/block_parser.cpp
src/converter.cpp
src/standard_library.cpp
src/macrodown.cpp
)
# Export the library as a namespaced target
add_library(MacroDown::MacroDown ALIAS macrodown_lib)
target_include_directories(macrodown_lib PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(macrodown_lib PUBLIC uni-algo::uni-algo)
# Executables and Testing
# Only build these if MacroDown is the top-level project, avoiding pollution of consumer builds.
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/refs/heads/main.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
add_executable(macrodown src/main.cpp)
target_link_libraries(macrodown PRIVATE macrodown_lib)
# Testing
enable_testing()
add_executable(macrodown_test
tests/test_main.cpp
tests/test_macro_engine.cpp
tests/test_block_parser.cpp
tests/test_nodes.cpp
tests/test_macrodown.cpp
tests/test_custom_markup.cpp
)
target_link_libraries(macrodown_test PRIVATE macrodown_lib GTest::gtest_main)
target_include_directories(macrodown_test PRIVATE include)
include(GoogleTest)
gtest_discover_tests(macrodown_test)
endif()