Changes
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c3af10c..a73bc67 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -16,38 +16,64 @@ endif()
# Dependencies
include(FetchContent)
-FetchContent_Declare(
- googletest
- URL https://github.com/google/googletest/archive/refs/heads/main.zip
-)
-
FetchContent_Declare(
uni-algo
URL https://github.com/uni-algo/uni-algo/archive/refs/tags/v1.2.0.zip
)
-
-# For Windows: Prevent overriding the parent project's compiler/linker settings
-set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
-FetchContent_MakeAvailable(googletest uni-algo)
+FetchContent_MakeAvailable(uni-algo)
# Source Configuration
-include_directories(include)
+# 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)
-# We will add source files explicitly to targets to avoid GLOB issues in larger projects,
-# but for now we will just list them manually or add a library target.
-# Let's create a core library for the logic to share between main and tests.
+target_include_directories(macrodown_lib PUBLIC
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
+ $<INSTALL_INTERFACE:include>
+)
-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)
-target_include_directories(macrodown_lib PUBLIC include)
target_link_libraries(macrodown_lib PUBLIC uni-algo::uni-algo)
-add_executable(macrodown src/main.cpp)
-target_link_libraries(macrodown PRIVATE macrodown_lib)
+# 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()
-# 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)
-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()
\ No newline at end of file
diff --git a/README.md b/README.md
index 06f6952..5b2f37d 100644
--- a/README.md
+++ b/README.md
@@ -33,6 +33,27 @@ cmake ..
make
```
+## Integration
+
+### Using FetchContent
+
+You can add MacroDown to your project using CMake's `FetchContent`.
+
+```cmake
+include(FetchContent)
+
+FetchContent_Declare(
+ macrodown
+ GIT_REPOSITORY https://git.xeno.darksair.org/macrodown.git
+ GIT_TAG master # Or a specific tag/commit
+)
+
+FetchContent_MakeAvailable(macrodown)
+
+# Link to the library
+target_link_libraries(your_target PRIVATE MacroDown::MacroDown)
+```
+
## Usage
### CLI