@@ -4,48 +4,139 @@ project(CXXStateTree VERSION 0.4.0 LANGUAGES CXX)
44set (CMAKE_CXX_STANDARD 20)
55set (CMAKE_CXX_STANDARD_REQUIRED ON )
66
7- add_library (CXXStateTree INTERFACE )
8- target_include_directories (CXXStateTree INTERFACE include )
7+ file (GLOB_RECURSE SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR} /src/*.cpp" )
98
10- add_executable (basic examples/basic.cpp)
11- target_link_libraries (basic PRIVATE CXXStateTree)
9+ option (STATIC_LIB "Enable Static Library instead of Dynamic" OFF )
1210
11+ if (STATIC_LIB)
12+ add_library (CXXStateTree STATIC ${SRC_FILES} )
13+ target_include_directories (CXXStateTree INTERFACE include ${CMAKE_CURRENT_SOURCE_DIR} /include )
14+ else ()
15+ add_library (CXXStateTree SHARED ${SRC_FILES} )
16+ target_include_directories (CXXStateTree INTERFACE include ${CMAKE_CURRENT_SOURCE_DIR} /include )
17+ endif ()
1318
14- add_executable (nested examples/nested.cpp)
15- target_link_libraries (nested PRIVATE CXXStateTree)
1619
17- add_executable (export_dot_example examples/export_dot.cpp)
18- target_include_directories (export_dot_example PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} /include )
19- add_executable (export_dot_nested_example examples/export_dot_nested.cpp)
20- target_include_directories (export_dot_nested_example PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} /include )
21- add_executable (export_dot_context_example examples/export_dot_context.cpp)
22- target_include_directories (export_dot_context_example PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} /include )
2320
24- add_executable (context_example examples/context_example.cpp)
25- target_include_directories (context_example PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} /include )
26-
27- # GoogleTest setup
28- include (FetchContent)
29- FetchContent_Declare(
30- googletest
31- URL https://github.com/google/googletest/archive/refs/heads/main.zip
21+ set_target_properties (CXXStateTree PROPERTIES
22+ RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR} /Release"
23+ ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR} /Release"
24+ LIBRARY_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR} /Release"
3225)
33- # For Windows: Prevent overriding the parent project's compiler/linker settings
34- set (gtest_force_shared_crt ON CACHE BOOL "" FORCE)
35- FetchContent_MakeAvailable(googletest)
3626
27+ option (ENABLE_TEST "Enable Test" OFF )
28+
29+ if (ENABLE_TEST)
30+ # GoogleTest setup
31+ include (FetchContent)
32+ FetchContent_Declare(
33+ googletest
34+ URL https://github.com/google/googletest/archive/refs/heads/main.zip
35+ DOWNLOAD_EXTRACT_TIMESTAMP true
36+ )
37+ # For Windows: Prevent overriding the parent project's compiler/linker settings
38+ set (gtest_force_shared_crt ON CACHE BOOL "" FORCE)
39+ FetchContent_MakeAvailable(googletest)
40+
41+
42+ enable_testing ()
43+ add_executable (state_tree_test tests/state_tree_test.cpp)
44+ target_link_libraries (state_tree_test PRIVATE CXXStateTree gtest_main)
45+
46+ include (GoogleTest)
47+ gtest_discover_tests(state_tree_test)
48+
49+ endif ()
3750
38- enable_testing ()
39- add_executable (state_tree_test tests/state_tree_test.cpp)
40- target_link_libraries (state_tree_test PRIVATE CXXStateTree gtest_main)
4151
42- include (GoogleTest)
43- gtest_discover_tests(state_tree_test)
52+ option (ENABLE_EXAMPLE "Enable Example" OFF )
53+
54+ if (ENABLE_EXAMPLE)
55+ add_executable (basic examples/basic.cpp)
56+ target_include_directories (basic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} /include )
57+ target_link_libraries (basic PRIVATE CXXStateTree)
58+
59+ add_executable (nested examples/nested.cpp)
60+ target_include_directories (basic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} /include )
61+ target_link_libraries (nested PRIVATE CXXStateTree)
62+
63+ add_executable (export_dot_example examples/export_dot.cpp)
64+ target_include_directories (export_dot_example PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} /include )
65+ target_link_libraries (export_dot_example PRIVATE CXXStateTree)
66+ add_executable (export_dot_nested_example examples/export_dot_nested.cpp)
67+ target_include_directories (export_dot_nested_example PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} /include )
68+ target_link_libraries (export_dot_nested_example PRIVATE CXXStateTree)
69+ add_executable (export_dot_context_example examples/export_dot_context.cpp)
70+ target_include_directories (export_dot_context_example PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} /include )
71+ target_link_libraries (export_dot_context_example PRIVATE CXXStateTree)
72+
73+ add_executable (context_example examples/context_example.cpp)
74+ target_include_directories (context_example PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} /include )
75+ target_link_libraries (context_example PRIVATE CXXStateTree)
76+
77+ endif ()
4478
4579option (ENABLE_COVERAGE "Enable coverage reporting" OFF )
4680
4781if (ENABLE_COVERAGE)
4882 message (STATUS "Building with coverage flags" )
4983 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 --coverage" )
5084 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage" )
85+ endif ()
86+
87+ option (ENABLE_SINGLE_HEADER "Enable Single Header Generation" OFF )
88+
89+ if (ENABLE_SINGLE_HEADER)
90+ find_package (Python3 REQUIRED COMPONENTS Interpreter)
91+ include (FetchContent)
92+
93+ # ----- Download the script (configure‑time, once, cached in build dir) -----
94+ FetchContent_Declare(
95+ edlund_amalgamate
96+ GIT_REPOSITORY https://github.com/edlund/amalgamate.git
97+ GIT_TAG master # ↔ pin a commit / tag for reproducible builds
98+ )
99+ FetchContent_MakeAvailable(edlund_amalgamate) # populates edlund_amalgamate_SOURCE_DIR
100+
101+ set (AMALGAMATE_PY "${edlund_amalgamate_SOURCE_DIR} /amalgamate.py" ) # :contentReference[oaicite:0]{index=0}
102+
103+ set (AMALGAMATE_CFG "${CMAKE_CURRENT_SOURCE_DIR} /config_CXXStateTree.json" )
104+ set (AMALGAMATE_PRO "${CMAKE_CURRENT_SOURCE_DIR} /config_CXXStateTree.prologue" )
105+ set (AMALGAMATE_OUT "${CMAKE_CURRENT_SOURCE_DIR} /single_include/CXXStateTree.hpp" )
106+
107+ add_custom_command (
108+ OUTPUT ${AMALGAMATE_OUT}
109+ COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_SOURCE_DIR} /single_include # ensure /dist
110+ COMMAND python3 ${AMALGAMATE_PY} -c ${AMALGAMATE_CFG} -s ${CMAKE_CURRENT_SOURCE_DIR} -p ${AMALGAMATE_PRO} --verbose yes
111+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
112+ DEPENDS ${AMALGAMATE_PY} ${AMALGAMATE_CFG}
113+ COMMENT "Generating single‑header CXXStateTree.hpp with edlund/amalgamate"
114+ VERBATIM
115+ )
116+
117+ add_custom_target (amalgamate ALL DEPENDS ${AMALGAMATE_OUT} )
118+
119+ if (ENABLE_TEST)
120+ # GoogleTest setup
121+ include (FetchContent)
122+ FetchContent_Declare(
123+ googletest
124+ URL https://github.com/google/googletest/archive/refs/heads/main.zip
125+ DOWNLOAD_EXTRACT_TIMESTAMP true
126+ )
127+ # For Windows: Prevent overriding the parent project's compiler/linker settings
128+ set (gtest_force_shared_crt ON CACHE BOOL "" FORCE)
129+ FetchContent_MakeAvailable(googletest)
130+
131+
132+ enable_testing ()
133+ add_executable (state_tree_singleheader_test tests/state_tree_singleheader_test.cpp)
134+ target_include_directories (state_tree_singleheader_test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} /single_include)
135+ target_link_libraries (state_tree_singleheader_test PRIVATE CXXStateTree gtest_main)
136+
137+ include (GoogleTest)
138+ gtest_discover_tests(state_tree_singleheader_test)
139+
140+ endif ()
141+
51142endif ()
0 commit comments