Skip to content

Commit

Permalink
Update Cmake for SDl
Browse files Browse the repository at this point in the history
  • Loading branch information
JustDoom committed Dec 16, 2024
1 parent 95542c0 commit 34b925f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 30 deletions.
30 changes: 1 addition & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,11 @@ VERSION 0.1)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
option(SDL_VENDORED "Use vendored libraries" ON)

add_executable(8ChocChip)

#option(BUILD_SHARED_LIBS "Build shared libraries" OFF)

#file(GLOB ASSETS "${CMAKE_SOURCE_DIR}/assets/*")
#
#foreach(ASSET ${ASSETS})
# configure_file(${ASSET} ${CMAKE_BINARY_DIR}/assets COPYONLY)
#endforeach()

add_subdirectory(dependencies)
add_subdirectory(src)

Expand All @@ -29,31 +21,11 @@ endif()

target_link_libraries(8ChocChip PRIVATE SDL3::SDL3 SDL3_ttf::SDL3_ttf nfd ${libname}++)

# Set the RPATH of the executable to include the directory where SFML libraries are located
set_target_properties(8ChocChip PROPERTIES
INSTALL_RPATH "$ORIGIN"
BUILD_RPATH "$ORIGIN"
)

# Copy DLLs needed for runtime on Windows
if(WIN32)
add_custom_command(
TARGET 8ChocChip
COMMENT "Copy OpenAL DLL"
PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${SFML_SOURCE_DIR}/extlibs/bin/$<IF:$<EQUAL:${CMAKE_SIZEOF_VOID_P},8>,x64,x86>/openal32.dll $<TARGET_FILE_DIR:${PROJECT_NAME}>
VERBATIM)

if (BUILD_SHARED_LIBS)
add_custom_command(TARGET 8ChocChip POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:sfml-graphics>
$<TARGET_FILE:sfml-window>
$<TARGET_FILE:sfml-system>
$<TARGET_FILE:sfml-audio>
$<TARGET_FILE_DIR:8ChocChip>)
endif()
endif()

# Copy nfd and config++ libraries to the executable directory
if (UNIX AND NOT APPLE)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
Expand Down
12 changes: 11 additions & 1 deletion dependencies/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
add_subdirectory(nativefiledialog)
add_subdirectory(libconfig)
add_subdirectory(sdl)

if(SDL_VENDORED)
# This assumes you have added SDL as a submodule in vendored/SDL
add_subdirectory(sdl EXCLUDE_FROM_ALL)
else()
# 1. Look for a SDL3 package,
# 2. look for the SDL3-shared component, and
# 3. fail if the shared component cannot be found.
find_package(SDL3 REQUIRED CONFIG REQUIRED COMPONENTS SDL3-shared)
endif()

add_subdirectory(sdl_ttf)
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ int main(int argc, char **argv) {
}
}

// Do not change, this makes multiple windows not crash
for (size_t i = 0; i < windows.size(); ++i) {
windows[i]->update();
windows[i]->render();
Expand Down

0 comments on commit 34b925f

Please sign in to comment.