summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt16
-rw-r--r--include/engine/state.h2
-rw-r--r--src/state.c12
-rw-r--r--state_type_list.h.in0
-rw-r--r--tools/cmake/DawAddState.cmake46
-rw-r--r--tools/cmake/all_states.h.in (renamed from include_states.h.in)0
-rw-r--r--tools/cmake/list_of_states.h.in1
7 files changed, 47 insertions, 30 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 655e664..ebe9aae 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -5,7 +5,8 @@ project(daw VERSION 0.0.1 LANGUAGES C)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON CACHE BOOL "Prevents cmake -S. -B.")
set(CMAKE_DISABLE_SOURCE_CHANGES ON CACHE BOOL "Prevent writing files to CMAKE_SOURCE_DIR under configure")
-if(NOT CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
+# Check if we are used as a sub project/module or not
+if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
set(NOT_SUBPROJECT ON)
else()
set(NOT_SUBPROJECT OFF)
@@ -13,8 +14,8 @@ endif()
include(CMakeDependentOption)
-option(ASAN "Enable address sanitizer")
-option(UBSAN "Enable undefined behaviour sanitizer")
+option(ASAN "Enable address sanitizer. Only enabled when DAW_BUILD_DEBUG=ON")
+option(UBSAN "Enable undefined behaviour sanitizer. Only enabled when DAW_BUILD_DEBUG=ON")
cmake_dependent_option(DAW_BUILD_DEBUG
"Compile daw engine with debugging features" ON
@@ -99,11 +100,11 @@ target_compile_definitions(${PROJECT_NAME} PUBLIC
)
-configure_file(${CMAKE_CURRENT_LIST_DIR}/state_type_list.h.in
- ${CMAKE_BINARY_DIR}/include/state_type_list.h)
+configure_file(${CMAKE_CURRENT_LIST_DIR}/tools/cmake/list_of_states.h.in
+ ${CMAKE_BINARY_DIR}/include/list_of_states.h.in)
-configure_file(${CMAKE_CURRENT_LIST_DIR}/include_states.h.in
- ${CMAKE_BINARY_DIR}/include/include_states.h)
+configure_file(${CMAKE_CURRENT_LIST_DIR}/tools/cmake/all_states.h.in
+ ${CMAKE_BINARY_DIR}/include/states/all_states.h)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/tools/cmake")
@@ -112,7 +113,6 @@ if (NOT NOT_SUBPROJECT)
endif()
include(DawAddState)
-
message("Configured ${PROJECT_NAME} ${PROJECT_VERSION}")
message("Build type: ${CMAKE_BUILD_TYPE}")
message("enable debug: ${DAW_BUILD_DEBUG}")
diff --git a/include/engine/state.h b/include/engine/state.h
index 83b57a2..e0ec6f9 100644
--- a/include/engine/state.h
+++ b/include/engine/state.h
@@ -6,7 +6,7 @@
typedef enum StateType {
STATE_null,
#define State(name) STATE_##name,
-#include <state_type_list.h>
+#include <states/list_of_states.h>
#undef State
STATE_quit,
} StateType;
diff --git a/src/state.c b/src/state.c
index ee8b2fd..59729a5 100644
--- a/src/state.c
+++ b/src/state.c
@@ -1,14 +1,14 @@
#include <engine/state.h>
#include <engine/logging.h>
-#include <include_states.h>
+#include <states/all_states.h>
typedef StateType state_update_t (void*);
const char *StateTypeStr[] = {
"null",
#define State(name) #name,
-#include <state_type_list.h>
+#include <states/list_of_states.h>
#undef State
"quit",
};
@@ -20,7 +20,7 @@ void State_init(StateType type, memory *mem) {
name##_init(memory_allocate(mem, sizeof(name##_state))); \
break; \
}
-#include <state_type_list.h>
+#include <states/list_of_states.h>
#undef State
case STATE_null:
case STATE_quit:
@@ -39,7 +39,7 @@ void State_free(StateType type, memory *mem) {
name##_free(mem->data); \
break; \
}
-#include <state_type_list.h>
+#include <states/list_of_states.h>
#undef State
case STATE_null:
case STATE_quit:
@@ -59,7 +59,7 @@ StateType (*State_updateFunc(StateType type))(void*) {
return (state_update_t*)&name##_update; \
break; \
}
-#include <state_type_list.h>
+#include <states/list_of_states.h>
#undef State
case STATE_null:
case STATE_quit:
@@ -79,7 +79,7 @@ StateType State_update(StateType type, memory *mem) {
next_state = name##_update(mem->data); \
break; \
}
-#include <state_type_list.h>
+#include <states/list_of_states.h>
#undef State
case STATE_null:
case STATE_quit:
diff --git a/state_type_list.h.in b/state_type_list.h.in
deleted file mode 100644
index e69de29..0000000
--- a/state_type_list.h.in
+++ /dev/null
diff --git a/tools/cmake/DawAddState.cmake b/tools/cmake/DawAddState.cmake
index a20aac7..4739b3c 100644
--- a/tools/cmake/DawAddState.cmake
+++ b/tools/cmake/DawAddState.cmake
@@ -1,36 +1,52 @@
# Add the directory to the list of states.
# The directories contents will be compiled into a shared object file and linked
-# to the main daw library
-macro(daw_add_state STATEDIR)
+# to the main daw library, unless you compile statically, or link during runtime.
+#
+# Say you want to add a new state, called ${STATENAME} to your project, localted
+# at ${PROJECT_ROOT}, Then your directory structure for your main project should
+# be as follows:
+# ${PROJECT_ROOT}/
+# ├ state_${STATENAME}/
+# │ ├ includes/states/${STATENAME}.h
+# │ └ src/ ..
+# ├ state_foo/ ..
+# └ state_bar/ ..
+#
+# Then call `daw_add_state(${STATENAME}) for each of your states.
+macro(daw_add_state STATENAME)
+ # Add state include directory to the engines target
set_property(TARGET daw
APPEND PROPERTY INCLUDE_DIRECTORIES
- ${CMAKE_SOURCE_DIR}/state_${STATEDIR}/include)
+ ${CMAKE_SOURCE_DIR}/state_${STATENAME}/include)
- file(APPEND ${CMAKE_BINARY_DIR}/include/state_type_list.h
- "State(${STATEDIR})\n")
+ # Append state to list of states
+ file(APPEND ${CMAKE_BINARY_DIR}/include/states/list_of_states.h
+ "State(${STATENAME})\n")
- file(APPEND ${CMAKE_BINARY_DIR}/include/include_states.h
- "#include <states/${STATEDIR}.h>\n")
+ # Append header inclusion of state to common state header
+ file(APPEND ${CMAKE_BINARY_DIR}/include/states/all_states.h
+ "#include <states/${STATENAME}.h>\n")
+ # Glob the states sources, not my proudest moment
file(GLOB STATE_SOURCES
LIST_DIRECTORIES false
- state_${STATEDIR}/src/*.c
+ state_${STATENAME}/src/*.c
)
# TODO: When state reloading is implemented properly, add MODULE library
# option In general, this should only be available when debugging.
if(BUILD_SHARED_LIBS)
if(DAW_BUILD_DEBUG AND DAW_BUILD_HOTRELOAD)
- add_library(${STATEDIR} MODULE ${STATE_SOURCES})
+ add_library(${STATENAME} MODULE ${STATE_SOURCES})
else()
- add_library(${STATEDIR} SHARED ${STATE_SOURCES})
+ add_library(${STATENAME} SHARED ${STATE_SOURCES})
endif()
else()
- add_library(${STATEDIR} OBJECT ${STATE_SOURCES})
+ add_library(${STATENAME} OBJECT ${STATE_SOURCES})
endif()
- target_include_directories(${STATEDIR} PUBLIC
- state_${STATEDIR}/include
+ target_include_directories(${STATENAME} PUBLIC
+ state_${STATENAME}/include
${daw_SOURCE_DIR}/include
${CMAKE_BINARY_DIR}/include
include
@@ -38,7 +54,7 @@ macro(daw_add_state STATEDIR)
set_property(TARGET daw
APPEND PROPERTY LINK_LIBRARIES
- ${STATEDIR})
+ ${STATENAME})
- list(APPEND STATE_LIST ${STATEDIR})
+ list(APPEND STATE_LIST ${STATENAME})
endmacro()
diff --git a/include_states.h.in b/tools/cmake/all_states.h.in
index e69de29..e69de29 100644
--- a/include_states.h.in
+++ b/tools/cmake/all_states.h.in
diff --git a/tools/cmake/list_of_states.h.in b/tools/cmake/list_of_states.h.in
new file mode 100644
index 0000000..1f7fbc6
--- /dev/null
+++ b/tools/cmake/list_of_states.h.in
@@ -0,0 +1 @@
+#define STATES_LIST \