libsuperderpy/cmake/libsuperderpy-gamestates.cmake

36 lines
1.8 KiB
CMake
Raw Permalink Normal View History

FILE (GLOB gamestates CONFIGURE_DEPENDS "*.c")
if(LIBSUPERDERPY_STATIC_GAMESTATES)
set(LIBSUPERDERPY_GAMESTATES_CONSTRUCTOR "")
set(LIBSUPERDERPY_GAMESTATES_STUB "")
FOREACH(gamestate ${gamestates})
get_filename_component(gamestate_name ${gamestate} NAME_WE)
set(LIBSUPERDERPY_GAMESTATES_CONSTRUCTOR "${LIBSUPERDERPY_GAMESTATES_CONSTRUCTOR} void __libsuperderpy_init_${gamestate_name}_gamestate(void); __libsuperderpy_init_${gamestate_name}_gamestate();")
set(LIBSUPERDERPY_GAMESTATES_STUB "${LIBSUPERDERPY_GAMESTATES_STUB} GAMESTATE_STUB(${gamestate_name}) ")
ENDFOREACH(gamestate)
configure_file("${LIBSUPERDERPY_DIR}/src/gamestates-constructor.c.in" "${CMAKE_BINARY_DIR}/gen/gamestates-constructor.c")
configure_file("${LIBSUPERDERPY_DIR}/src/gamestates-stub.c.in" "${CMAKE_BINARY_DIR}/gen/gamestates-stub.c")
add_library(libsuperderpy-gamestates STATIC "${CMAKE_BINARY_DIR}/gen/gamestates-constructor.c")
add_library(libsuperderpy-gamestates-stub STATIC "${CMAKE_BINARY_DIR}/gen/gamestates-stub.c")
endif(LIBSUPERDERPY_STATIC_GAMESTATES)
FOREACH(gamestate ${gamestates})
get_filename_component(gamestate_name ${gamestate} NAME_WE)
set(sources "${gamestate_name}.c")
FILE (GLOB submodules CONFIGURE_DEPENDS "${gamestate_name}/*.c")
FOREACH(submodule ${submodules})
get_filename_component(submodule_name ${submodule} NAME_WE)
list(APPEND sources "${gamestate_name}/${submodule_name}.c")
ENDFOREACH(submodule)
register_gamestate(${gamestate_name} "${sources}")
if (LIBSUPERDERPY_STATIC_GAMESTATES)
target_link_libraries("libsuperderpy-gamestates" lib${LIBSUPERDERPY_GAMENAME}-${gamestate_name})
endif (LIBSUPERDERPY_STATIC_GAMESTATES)
ENDFOREACH(gamestate)
if (LIBSUPERDERPY_STATIC_GAMESTATES)
target_link_libraries("libsuperderpy-gamestates" "-Wl,--allow-multiple" libsuperderpy-gamestates-stub)
endif (LIBSUPERDERPY_STATIC_GAMESTATES)