build: factor per-frontend CMake into essim_add_frontend()
Every frontend repeated the same target wiring (glob sources minus main.cpp → essim_<name> lib linking essim_core; essim exe from main.cpp linking the lib + essim_frontend; RUNTIME_OUTPUT_DIRECTORY=build/). Move it into a reusable helper cmake/EssimFrontend.cmake::essim_add_frontend(name LIBS ...), included once at the top level. The tui CMakeLists now just fetches FTXUI and calls essim_add_frontend(tui LIBS ftxui::screen ftxui::dom ftxui::component). A new frontend's CMakeLists is its toolkit setup + one call. No behaviour change; binary stays ./build/essim, tests green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
30
cmake/EssimFrontend.cmake
Normal file
30
cmake/EssimFrontend.cmake
Normal file
@@ -0,0 +1,30 @@
|
||||
# essim_add_frontend(<name> [LIBS <toolkit link targets>...])
|
||||
#
|
||||
# Builds the boilerplate shared by every frontend under src/frontends/<name>/:
|
||||
# * a static library essim_<name> from every .cpp in the current directory
|
||||
# except main.cpp, linking essim_core plus the frontend's own GUI/TUI
|
||||
# toolkit (LIBS);
|
||||
# * the `essim` executable from main.cpp, linking essim_<name> and the shared,
|
||||
# toolkit-free launcher essim_frontend, emitted at the top of the build tree
|
||||
# (./build/essim) whichever frontend produced it.
|
||||
#
|
||||
# A per-frontend CMakeLists only sets up its toolkit (FetchContent /
|
||||
# find_package, and any directory-scoped include dirs / definitions) and then
|
||||
# calls this with the toolkit's link targets — no target wiring repeated.
|
||||
function(essim_add_frontend name)
|
||||
cmake_parse_arguments(FE "" "" "LIBS" ${ARGN})
|
||||
|
||||
set(dir "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
|
||||
# Frontend library = every .cpp here except the entry point.
|
||||
file(GLOB FE_SOURCES "${dir}/*.cpp")
|
||||
list(REMOVE_ITEM FE_SOURCES "${dir}/main.cpp")
|
||||
|
||||
add_library(essim_${name} STATIC ${FE_SOURCES})
|
||||
target_link_libraries(essim_${name} PUBLIC essim_core ${FE_LIBS})
|
||||
|
||||
add_executable(essim "${dir}/main.cpp")
|
||||
target_link_libraries(essim PRIVATE essim_${name} essim_frontend)
|
||||
set_target_properties(essim PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
|
||||
endfunction()
|
||||
Reference in New Issue
Block a user