From a4884f7b42659638eb1bfb59d131454878c1a71f Mon Sep 17 00:00:00 2001 From: 0scar Date: Fri, 28 Jul 2023 13:25:09 +0200 Subject: test --- tools/cmake/DawAddState.cmake | 46 +++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 15 deletions(-) (limited to 'tools/cmake/DawAddState.cmake') 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 \n") + # Append header inclusion of state to common state header + file(APPEND ${CMAKE_BINARY_DIR}/include/states/all_states.h + "#include \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() -- cgit v1.3