-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
88 lines (72 loc) · 3.61 KB
/
CMakeLists.txt
File metadata and controls
88 lines (72 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
cmake_minimum_required(VERSION 3.26 FATAL_ERROR)
project(CFBox
VERSION 0.2.0
DESCRIPTION "A Modern C++ Toy Busybox"
HOMEPAGE_URL "https://github.com/Awesome-Embedded-Learning-Studio/CFBox"
LANGUAGES CXX
)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# ── CPM dependency manager ────────────────────────────────────
include(cmake/third_party/CPM.cmake)
# ── Compiler flags ────────────────────────────────────────────
include(cmake/compile/CompilerFlag.cmake)
# ── Dependencies ──────────────────────────────────────────────
# (zlib removed — using built-in deflate/inflate implementation)
# ── Applet configuration ─────────────────────────────────────
include(cmake/Config.cmake)
# ── Applet sources (conditional on config) ───────────────────
set(CFBOX_APPLET_SOURCES)
# Multi-file applets
if(CFBOX_ENABLE_SH)
file(GLOB_RECURSE SH_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/applets/sh/*.cpp)
list(APPEND CFBOX_APPLET_SOURCES ${SH_SOURCES})
endif()
if(CFBOX_ENABLE_AWK)
file(GLOB_RECURSE AWK_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/applets/awk/*.cpp)
list(APPEND CFBOX_APPLET_SOURCES ${AWK_SOURCES})
endif()
if(CFBOX_ENABLE_INIT)
file(GLOB_RECURSE INIT_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/applets/init/*.cpp)
list(APPEND CFBOX_APPLET_SOURCES ${INIT_SOURCES})
endif()
if(CFBOX_ENABLE_TOP)
file(GLOB_RECURSE TOP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/applets/top/*.cpp)
list(APPEND CFBOX_APPLET_SOURCES ${TOP_SOURCES})
endif()
# Single-file applets
foreach(applet IN LISTS CFBOX_APPLETS)
string(TOUPPER "${applet}" APPLET_UPPER)
if(NOT applet STREQUAL "sh" AND NOT applet STREQUAL "awk" AND NOT applet STREQUAL "init" AND NOT applet STREQUAL "top" AND CFBOX_ENABLE_${APPLET_UPPER})
list(APPEND CFBOX_APPLET_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/applets/${applet}.cpp)
endif()
endforeach()
# ── Main executable ───────────────────────────────────────────
add_executable(cfbox src/main.cpp ${CFBOX_APPLET_SOURCES})
target_include_directories(cfbox PUBLIC include)
target_include_directories(cfbox PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/include)
target_link_libraries(cfbox PRIVATE cfbox_compiler_flags)
# ── Install target ─────────────────────────────────────────────
install(TARGETS cfbox DESTINATION bin)
# ── GTest via CPM (FetchContent) ──────────────────────────────
if(NOT CMAKE_CROSSCOMPILING)
CPMAddPackage(
NAME GTest
GITHUB_REPOSITORY google/googletest
GIT_TAG v1.14.0
)
if(GTest_ADDED)
enable_testing()
file(GLOB_RECURSE CFBOX_TEST_SOURCES CONFIGURE_DEPENDS tests/unit/*.cpp)
if(CFBOX_TEST_SOURCES)
add_executable(cfbox_tests ${CFBOX_TEST_SOURCES} ${CFBOX_APPLET_SOURCES})
target_include_directories(cfbox_tests PUBLIC include)
target_include_directories(cfbox_tests PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/include)
target_link_libraries(cfbox_tests PRIVATE
cfbox_compiler_flags
GTest::gtest_main
)
include(GoogleTest)
gtest_discover_tests(cfbox_tests)
endif()
endif()
endif()