Skip to content

Commit 411c649

Browse files
committed
[CHORE] restructure files
1 parent c8ed50b commit 411c649

4 files changed

Lines changed: 114 additions & 363 deletions

File tree

CMakeLists.txt

Lines changed: 113 additions & 220 deletions
Original file line numberDiff line numberDiff line change
@@ -1,247 +1,140 @@
1-
cmake_minimum_required (VERSION 3.22)
2-
3-
project(inLimbo
4-
LANGUAGES CXX
5-
VERSION 2.7
6-
)
1+
cmake_minimum_required(VERSION 3.20)
2+
project(dirsort-test LANGUAGES CXX)
73

4+
# -----------------------------------------------------------
5+
# Build configuration
6+
# -----------------------------------------------------------
87
set(CMAKE_CXX_STANDARD 20)
98
set(CMAKE_CXX_STANDARD_REQUIRED ON)
109
set(CMAKE_CXX_EXTENSIONS OFF)
1110
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
12-
set(CONFIG_TOML_FILE "$ENV{HOME}/.config/inLimbo/config.toml")
13-
set(INLIMBO_CACHE_DIR "$ENV{HOME}/.cache/inLimbo")
14-
set(MINIAUDIO_FILE_RELATIVE "src/music/miniaudio.h")
15-
set(CIMG_FILE_RELATIVE "src/ui/components/libs/CImg.h")
16-
set(TOML_FILE_RELATIVE "src/parser/toml.hpp")
17-
set(INLIMBO_DEBUG_BUILD OFF)
18-
19-
enable_testing()
2011

21-
add_library(tiv
22-
${CMAKE_CURRENT_SOURCE_DIR}/src/ui/components/libs/tiv_lib.cpp
23-
)
24-
25-
# Option to select between local or global build
26-
option(BUILD_GLOBAL "Build globally and install" OFF)
12+
add_compile_options(-Wall -Wextra -Wpedantic -g)
2713

28-
# --- Fetch FTXUI --------------------------------------------------------------
29-
include(FetchContent)
14+
# -----------------------------------------------------------
15+
# External Dependencies
16+
# -----------------------------------------------------------
17+
set(EXTERNAL_DIR ${CMAKE_SOURCE_DIR}/external)
18+
set(SPDLOG_GH_URL https://github.com/gabime/spdlog.git)
3019

31-
set(FETCHCONTENT_UPDATES_DISCONNECTED ON)
32-
set(FETCHCONTENT_QUIET OFF)
20+
# --- TOML++ (header-only)
21+
add_library(tomlplusplus INTERFACE)
22+
target_include_directories(tomlplusplus INTERFACE ${EXTERNAL_DIR}/tomlplusplus)
3323

34-
FetchContent_Declare(ftxui
35-
GIT_REPOSITORY https://github.com/arthursonzogni/ftxui.git
36-
GIT_TAG v5.0.0
37-
GIT_PROGRESS TRUE
38-
GIT_SHALLOW TRUE
39-
EXCLUDE_FROM_ALL
40-
)
41-
FetchContent_MakeAvailable(ftxui)
42-
# ------------------------------------------------------------------------------
43-
44-
# --- Set Executable Name -------------------------------------------------------
45-
# Change executable name based on build type
46-
if(CMAKE_BUILD_TYPE STREQUAL "Debug-ASan")
47-
set(EXECUTABLE_NAME "inLimbo-DBG-Asan")
48-
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug-TSan")
49-
set(EXECUTABLE_NAME "inLimbo-DBG-TSan")
50-
else()
51-
set(CMAKE_BUILD_TYPE "Local Release")
52-
set(EXECUTABLE_NAME "inLimbo")
53-
endif()
24+
# --- Miniaudio (header-only)
25+
add_library(miniaudio INTERFACE)
26+
target_include_directories(miniaudio INTERFACE ${EXTERNAL_DIR}/miniaudio)
5427

55-
# --- Add Executable --------------------------------------------------------
56-
add_executable(${EXECUTABLE_NAME}
57-
src/main.cpp
58-
src/ui/components/scroller.cpp
59-
src/ui/components/image_view.cpp
60-
src/ui/components/libs/tiv_lib.cpp
61-
)
28+
# --- Cereal (header-only)
29+
add_library(cereal INTERFACE)
30+
target_include_directories(cereal INTERFACE ${EXTERNAL_DIR}/cereal/include/cereal)
6231

63-
# Set include directories for source files
64-
target_include_directories(${EXECUTABLE_NAME} PRIVATE src)
65-
66-
# --- Debugging Flags --------------------------------------------------------
67-
68-
if(CMAKE_BUILD_TYPE STREQUAL "Debug-ASan")
69-
set(INLIMBO_DEBUG_BUILD ON)
70-
message(STATUS "Enabling AddressSanitizer for Debug-AddressSanitizer build")
71-
72-
target_compile_options(${EXECUTABLE_NAME} PRIVATE
73-
-fsanitize=address
74-
-fsanitize=undefined
75-
-g
76-
-Wall
77-
-Wextra
78-
)
79-
80-
target_link_options(${EXECUTABLE_NAME} PRIVATE
81-
-fsanitize=address
82-
)
83-
84-
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug-TSan")
85-
set(INLIMBO_DEBUG_BUILD ON)
86-
message(STATUS "Enabling ThreadSanitizer for Debug-ThreadSanitizer build")
87-
88-
target_compile_options(${EXECUTABLE_NAME} PRIVATE
89-
-fsanitize=thread
90-
-fsanitize=undefined
91-
-g
92-
-Wall
93-
-Wextra
94-
)
95-
96-
target_link_options(${EXECUTABLE_NAME} PRIVATE
97-
-fsanitize=thread
98-
)
99-
100-
else()
101-
message(STATUS "Skipping Sanitizers for Release build")
102-
endif()
32+
# --- spdlog (compiled)
33+
set(SPDLOG_DIR ${EXTERNAL_DIR}/spdlog)
10334

104-
# --- Handle Emscripten-specific flags and files ---------------------------------
105-
if (EMSCRIPTEN)
106-
# Emscripten-specific flags
107-
string(APPEND CMAKE_CXX_FLAGS " -s USE_PTHREADS")
108-
string(APPEND CMAKE_EXE_LINKER_FLAGS " -s ASYNCIFY")
109-
string(APPEND CMAKE_EXE_LINKER_FLAGS " -s PROXY_TO_PTHREAD")
110-
111-
# Ensure the necessary files are copied for web build
112-
foreach(file "index.html" "run_webassembly.py")
113-
configure_file("src/${file}" ${file})
114-
endforeach(file)
115-
116-
# Disable TagLib for Emscripten build
117-
message(STATUS "Building for Emscripten: TagLib will be excluded")
118-
else()
119-
target_link_libraries(${EXECUTABLE_NAME})
35+
if(NOT EXISTS ${SPDLOG_DIR}/CMakeLists.txt)
36+
message(STATUS "spdlog not found — cloning into ${SPDLOG_DIR}")
37+
execute_process(
38+
COMMAND git clone --branch master ${SPDLOG_GH_URL} ${SPDLOG_DIR}
39+
WORKING_DIRECTORY ${EXTERNAL_DIR}
40+
)
12041
endif()
12142

122-
# --- Handle Global Build ---------------------------------------------------------
123-
if(DEFINED BUILD_GLOBAL AND BUILD_GLOBAL)
124-
set(CMAKE_BUILD_TYPE "Global")
125-
set(CMAKE_INSTALL_PREFIX "/usr/")
126-
message(STATUS "Starting GLOBAL_BUILD for inLimbo...")
127-
128-
install(TARGETS ${EXECUTABLE_NAME} DESTINATION bin)
129-
130-
install(FILES assets/inLimbo.desktop DESTINATION share/applications)
131-
install(FILES assets/logo/inLimbo.png DESTINATION share/icons/hicolor/256x256/apps)
132-
install(FILES assets/manpage/inLimbo.1 DESTINATION share/man/man1)
133-
install(FILES ./VERSION DESTINATION share/inLimbo/)
134-
else()
135-
# Local build (build in ./build directory)
136-
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/build")
137-
message(STATUS "Building locally, binaries will be located in ./build/")
138-
endif()
43+
add_subdirectory(${SPDLOG_DIR} ${CMAKE_BINARY_DIR}/spdlog_build EXCLUDE_FROM_ALL)
44+
set_target_properties(spdlog PROPERTIES POSITION_INDEPENDENT_CODE ON)
45+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
13946

140-
# Ensure that pkg-config is available
47+
# -----------------------------------------------------------
48+
# System Dependencies
49+
# -----------------------------------------------------------
14150
find_package(PkgConfig REQUIRED)
51+
pkg_check_modules(TAGLIB REQUIRED taglib)
52+
53+
# -----------------------------------------------------------
54+
# Backend Shared Library
55+
# -----------------------------------------------------------
56+
set(INLIMBO_CORE_SOURCES
57+
src/core/RBTree.cc
58+
src/core/SongTree.cc
59+
src/core/taglib/Parser.cc
60+
)
14261

143-
# Try to find GLib and Gio using pkg-config
144-
pkg_check_modules(GLIB REQUIRED glib-2.0 gio-2.0)
145-
146-
# If pkg-config is not available or fails to find the libraries, fall back to manual search
147-
if (NOT GLIB_FOUND)
148-
message(STATUS "pkg-config not found or failed to find GLib and Gio, attempting manual search...")
149-
150-
# Try searching for the libraries using standard system directories
151-
find_library(GLIB_LIBRARY NAMES glib-2.0 gio-2.0)
152-
153-
if (NOT GLIB_LIBRARY)
154-
message(FATAL_ERROR "GLib and Gio libraries not found. Install libglib-2.0-dev and libgio-2.0-dev.")
155-
endif()
156-
157-
# Manually find the include directories for GLib and Gio
158-
find_path(GLIB_INCLUDE_DIR glib.h)
159-
find_path(GIO_INCLUDE_DIR gio.h)
160-
161-
# If the includes or libraries are not found, give an error
162-
if (NOT GLIB_INCLUDE_DIR OR NOT GIO_INCLUDE_DIR)
163-
message(FATAL_ERROR "GLib and Gio include files not found.")
164-
endif()
165-
166-
set(GLIB_LIBRARIES ${GLIB_LIBRARY})
167-
set(GLIB_INCLUDE_DIRS ${GLIB_INCLUDE_DIR} ${GIO_INCLUDE_DIR})
168-
endif()
62+
add_library(inlimbo-core SHARED ${INLIMBO_CORE_SOURCES})
16963

170-
include_directories(${GLIB_INCLUDE_DIRS})
171-
link_directories(${GLIB_LIBRARY_DIRS})
64+
target_include_directories(inlimbo-core
65+
PUBLIC
66+
include/inlimbo
67+
${TAGLIB_INCLUDE_DIRS}
68+
${EXTERNAL_DIR}/tomlplusplus
69+
)
17270

173-
add_definitions(${GLIB_CFLAGS_OTHER})
71+
target_link_libraries(inlimbo-core
72+
PUBLIC
73+
${TAGLIB_LIBRARIES}
74+
spdlog::spdlog
75+
tomlplusplus
76+
cereal
77+
miniaudio
78+
backtrace
79+
)
17480

175-
target_link_libraries(${EXECUTABLE_NAME}
176-
PRIVATE tiv
177-
PRIVATE X11
178-
PRIVATE ftxui::screen
179-
PRIVATE ftxui::dom
180-
PRIVATE ftxui::component
181-
PRIVATE ${GLIB_LIBRARIES}
182-
PRIVATE tag
81+
set_target_properties(inlimbo-core PROPERTIES
82+
OUTPUT_NAME "inlimbo-core"
83+
POSITION_INDEPENDENT_CODE ON
18384
)
18485

185-
# --- Ensure the config.toml file is created in the correct directory ---------------------
186-
if (NOT EXISTS ${CONFIG_TOML_FILE})
187-
message(STATUS "Creating config.toml...")
188-
file(MAKE_DIRECTORY "$ENV{HOME}/.config/inLimbo")
189-
configure_file("${CMAKE_SOURCE_DIR}/src/parser/examples/config.toml" ${CONFIG_TOML_FILE} COPYONLY)
190-
endif()
191-
if (NOT EXISTS ${INLIMBO_CACHE_DIR})
192-
file(MAKE_DIRECTORY ${INLIMBO_CACHE_DIR})
193-
endif()
86+
# -----------------------------------------------------------
87+
# Test Executable
88+
# -----------------------------------------------------------
89+
set(SOURCES
90+
src/test.cpp
91+
)
19492

195-
# --- Add Tests Directory Only if INLIMBO_TESTING is Defined ----------------------
196-
if(DEFINED INLIMBO_TESTING AND INLIMBO_TESTING)
197-
set(CMAKE_BUILD_TYPE "Build-Test")
198-
message("--> Enabling TESTING for INLIMBO...")
199-
add_subdirectory(tests)
200-
else()
201-
message("--> TESTING is disabled for INLIMBO.")
202-
endif()
93+
add_executable(${PROJECT_NAME} ${SOURCES})
20394

204-
# --- Sanity check for required headers ----
205-
message(STATUS "================== SANITY CHECKS ==========================")
206-
if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${MINIAUDIO_FILE_RELATIVE}")
207-
message(FATAL_ERROR "**Miniaudio header not found. File should exist at the expected location: ${MINIAUDIO_FILE_RELATIVE} (Maybe run init.sh?)**")
208-
else()
209-
message(STATUS "Found Miniaudio header...")
210-
endif()
95+
target_include_directories(${PROJECT_NAME}
96+
PRIVATE
97+
../../include/inlimbo
98+
)
21199

212-
if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${CIMG_FILE_RELATIVE}")
213-
message(FATAL_ERROR "**CImg header not found. File should exist at the expected location: ${CIMG_FILE_RELATIVE} (Maybe run init.sh?)**")
214-
else()
215-
message(STATUS "Found CImg header...")
216-
endif()
100+
target_link_libraries(${PROJECT_NAME}
101+
PRIVATE
102+
inlimbo-core
103+
)
217104

218-
if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${TOML_FILE_RELATIVE}")
219-
message(FATAL_ERROR "**TOML++ header not found. File should exist at the expected location: ${TOML_FILE_RELATIVE} (Maybe run init.sh?)**")
220-
else()
221-
message(STATUS "Found TOML++ header...")
105+
# -----------------------------------------------------------
106+
# RPATH & Build Options
107+
# -----------------------------------------------------------
108+
if(UNIX AND NOT APPLE)
109+
set_target_properties(${PROJECT_NAME} PROPERTIES
110+
BUILD_RPATH_USE_ORIGIN ON
111+
SKIP_BUILD_RPATH FALSE
112+
)
222113
endif()
223-
message(STATUS "================== SANITY CHECKS END ========================")
224-
225-
# --- Print Build Configuration ----------------------------------------------------
226-
message(STATUS "\n\n-- Building the ${PROJECT_NAME} project v${PROJECT_VERSION}...\n")
227-
message(STATUS "┌─ Build Configuration for inLimbo ────────────────────────")
228-
message(STATUS "│ Operating System : ${CMAKE_SYSTEM_NAME}")
229-
message(STATUS "│ Build Type : ${CMAKE_BUILD_TYPE} (ALPHA)")
230-
message(STATUS "│ CMake Version : ${CMAKE_VERSION}")
231-
message(STATUS "│ Compiler : ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_VERSION}")
232-
message(STATUS "│ Compiler Flags : ${CMAKE_CXX_FLAGS}")
233-
message(STATUS "│ Executable Name : ${EXECUTABLE_NAME}")
234-
message(STATUS "│ C++ Standard : ${CMAKE_CXX_STANDARD}")
235-
message(STATUS "│ Install Prefix (GLOBAL) : ${CMAKE_INSTALL_PREFIX}")
236-
message(STATUS "│ Local Build Directory : ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
237-
message(STATUS "│ Miniaudio header : YES (${MINIAUDIO_FILE_RELATIVE})")
238-
message(STATUS "│ CImg header : YES (${CIMG_FILE_RELATIVE})")
239-
message(STATUS "│ TOML++ header : YES (${TOML_FILE_RELATIVE})")
240-
message(STATUS "│ GLib/Gio Libraries : ${GLIB_LIBRARIES}")
241-
message(STATUS "│ FTXUI Fetched : YES")
242-
message(STATUS "│ Config file location : ${CONFIG_TOML_FILE}")
243-
message(STATUS "│ Cache dir location : ${INLIMBO_CACHE_DIR}")
244-
message(STATUS "│ Build Global Option : ${BUILD_GLOBAL}")
245-
message(STATUS "│ Enable Testing : ${INLIMBO_TESTING}")
246-
message(STATUS "│ Enable Debug Build : ${INLIMBO_DEBUG_BUILD}")
247-
message(STATUS "└──────────────────────────────────────────────────────────\n")
114+
115+
# -----------------------------------------------------------
116+
# Diagnostics Summary
117+
# -----------------------------------------------------------
118+
set(LINE_TOP "┌───────────────────────────── Build Summary ─────────────────────────────┐")
119+
set(LINE_BOTTOM "└──────────────────────────────────────────────────────────────────────────┘")
120+
set(SEP "│")
121+
122+
message(STATUS "${LINE_TOP}")
123+
message(STATUS "${SEP} Project Name : ${PROJECT_NAME}")
124+
message(STATUS "${SEP} Build Type : ${CMAKE_BUILD_TYPE}")
125+
message(STATUS "${SEP} System : ${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_PROCESSOR}")
126+
message(STATUS "${SEP} Compiler : ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
127+
message(STATUS "${SEP} C++ Standard : C++${CMAKE_CXX_STANDARD}")
128+
message(STATUS "${SEP} Build Directory : ${CMAKE_BINARY_DIR}")
129+
message(STATUS "${SEP} Source Directory : ${CMAKE_SOURCE_DIR}")
130+
message(STATUS "${SEP}")
131+
message(STATUS "${SEP} ── External Dependencies ───────────────────────────────")
132+
message(STATUS "${SEP} • TOML++ : ${EXTERNAL_DIR}/tomlplusplus")
133+
message(STATUS "${SEP} • miniaudio : ${EXTERNAL_DIR}/miniaudio")
134+
message(STATUS "${SEP} • cereal : ${EXTERNAL_DIR}/cereal/include/cereal")
135+
message(STATUS "${SEP} • spdlog : ${SPDLOG_DIR}")
136+
message(STATUS "${SEP}")
137+
message(STATUS "${SEP} ── System Libraries ────────────────────────────────────")
138+
message(STATUS "${SEP} • TagLib : ${TAGLIB_INCLUDE_DIRS}")
139+
message(STATUS "${SEP} • backtrace : linked manually")
140+
message(STATUS "${LINE_BOTTOM}\n")

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121

2222
> [!CAUTION]
2323
>
24-
> This is the develop branch!
25-
>
26-
> Currently u need to go to `src/` and run:
24+
> This is the develop branch!
2725
>
2826
> Firstly ensure that you have **ALL** the dependencies resolved.
2927
> (**spdlog**, **toml++**, **miniaudio** and **cereal** should all be resolved by git and cmake itself!)

0 commit comments

Comments
 (0)