@@ -7,15 +7,22 @@ project(cmcpp
77 LANGUAGES CXX
88)
99
10+ # ============================================================================
11+ # CMake Module Path
12+ # ============================================================================
13+ list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} /cmake" )
14+
15+ # ============================================================================
16+ # Build Options
17+ # ============================================================================
1018# Determine default for BUILD_SAMPLES: OFF on Windows, ON elsewhere
11- set (_BUILD_SAMPLES_DEFAULT ON )
12- if (WIN32 )
13- set (_BUILD_SAMPLES_DEFAULT ON )
14- endif ()
15- option (BUILD_SAMPLES "Build samples" ${_BUILD_SAMPLES_DEFAULT} )
19+ option (BUILD_SAMPLES "Build samples" ON )
1620option (BUILD_TESTING "Build tests" ON )
17- option (WIT_CODEGEN "Generate code from ANTLR grammar" ON )
21+ option (BUILD_WIT_CODEGEN "Generate code from ANTLR grammar" ON )
1822
23+ # ============================================================================
24+ # Core Library Target
25+ # ============================================================================
1926add_library (cmcpp INTERFACE )
2027
2128target_include_directories (cmcpp INTERFACE
@@ -25,45 +32,37 @@ target_include_directories(cmcpp INTERFACE
2532
2633target_compile_features (cmcpp INTERFACE cxx_std_20 )
2734
35+ # ============================================================================
36+ # Testing Setup
37+ # ============================================================================
2838# Enable testing early so subdirectories (including samples) can register tests
29- if (BUILD_TESTING)
39+ if (BUILD_TESTING)
3040 enable_testing ()
3141endif ()
3242
33- if (BUILD_SAMPLES AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR} /samples/CMakeLists.txt" )
34- if (NOT DEFINED WASI_SDK_PREFIX OR WASI_SDK_PREFIX STREQUAL "" )
35- set (_wasi_sdk_candidates)
36- if (DEFINED VCPKG_TARGET_TRIPLET)
37- list (APPEND _wasi_sdk_candidates "${CMAKE_CURRENT_BINARY_DIR} /vcpkg_installed/${VCPKG_TARGET_TRIPLET} /wasi-sdk" )
38- endif ()
39- file (GLOB _wasi_sdk_glob "${CMAKE_CURRENT_BINARY_DIR} /vcpkg_installed/*/wasi-sdk" )
40- list (APPEND _wasi_sdk_candidates ${_wasi_sdk_glob} )
41- list (FILTER _wasi_sdk_candidates EXCLUDE REGEX "^$" )
42- list (REMOVE_DUPLICATES _wasi_sdk_candidates)
43- if (_wasi_sdk_candidates)
44- list (GET _wasi_sdk_candidates 0 _wasi_sdk_default)
45- set (WASI_SDK_PREFIX "${_wasi_sdk_default} " CACHE PATH "Path to the WASI SDK used by the samples" FORCE )
46- else ()
47- set (WASI_SDK_PREFIX "" CACHE PATH "Path to the WASI SDK used by the samples" FORCE )
48- endif ()
49- endif ()
50- message ("WASI_SDK_PREFIX: ${WASI_SDK_PREFIX} " )
43+ # ============================================================================
44+ # Subdirectories
45+ # ============================================================================
46+ # Samples
47+ if (BUILD_SAMPLES)
5148 add_subdirectory (samples )
5249endif ()
5350
51+ # Grammar and code generation tools
5452# Grammar must be added before tools/test so the generate-grammar target is available
55- if (WIT_CODEGEN AND EXISTS " ${CMAKE_CURRENT_SOURCE_DIR} /grammar/CMakeLists.txt" )
53+ if (BUILD_WIT_CODEGEN )
5654 add_subdirectory (grammar )
57- # Add tools that use the grammar
58- if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR} /tools/wit-codegen/CMakeLists.txt" )
59- add_subdirectory (tools/wit-codegen )
60- endif ()
55+ add_subdirectory (tools/wit-codegen )
6156endif ()
6257
63- if (BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR} /test/CMakeLists.txt" )
58+ # Tests
59+ if (BUILD_TESTING)
6460 add_subdirectory (test )
6561endif ()
6662
63+ # ============================================================================
64+ # Installation
65+ # ============================================================================
6766include (GNUInstallDirs )
6867include (CMakePackageConfigHelpers )
6968
@@ -105,44 +104,6 @@ install(FILES
105104 DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/cmcpp
106105)
107106
108- # Install wit-codegen tool if it was built
109- if (WIT_CODEGEN AND TARGET wit-codegen)
110- install (TARGETS wit-codegen
111- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
112- COMPONENT tools
113- )
114-
115- # Install ANTLR4 runtime DLL on Windows
116- if (WIN32 )
117- # Find and install the ANTLR4 runtime DLL
118- set (ANTLR4_DLL_PATH "${CMAKE_BINARY_DIR} /vcpkg_installed/${VCPKG_TARGET_TRIPLET} /bin/antlr4-runtime.dll" )
119- if (EXISTS "${ANTLR4_DLL_PATH} " )
120- install (FILES "${ANTLR4_DLL_PATH} "
121- DESTINATION ${CMAKE_INSTALL_BINDIR}
122- COMPONENT tools
123- )
124- message (STATUS "Will install ANTLR4 runtime DLL: ${ANTLR4_DLL_PATH} " )
125- else ()
126- message (WARNING "ANTLR4 runtime DLL not found at: ${ANTLR4_DLL_PATH} " )
127- endif ()
128- elseif (UNIX AND TARGET antlr4_shared)
129- # On Linux/macOS, try to find and install the shared library
130- if (APPLE )
131- set (ANTLR4_LIB_PATTERN "libantlr4-runtime*.dylib" )
132- else ()
133- set (ANTLR4_LIB_PATTERN "libantlr4-runtime.so*" )
134- endif ()
135-
136- file (GLOB ANTLR4_LIBS "${CMAKE_BINARY_DIR} /vcpkg_installed/${VCPKG_TARGET_TRIPLET} /lib/${ANTLR4_LIB_PATTERN} " )
137- if (ANTLR4_LIBS)
138- install (FILES ${ANTLR4_LIBS}
139- DESTINATION ${CMAKE_INSTALL_LIBDIR}
140- COMPONENT tools
141- )
142- endif ()
143- endif ()
144- endif ()
145-
146107# CPack configuration for package generation
147108set (CPACK_PACKAGE_NAME "cmcpp" )
148109set (CPACK_PACKAGE_VENDOR "GordonSmith" )
0 commit comments