From c2a7c27477062873c747862ca494e6407faed078 Mon Sep 17 00:00:00 2001 From: "Victor D. Montero" Date: Tue, 20 Jan 2026 00:20:55 -0800 Subject: [PATCH] Fixing for Windows and Linux --- CMakeLists.txt | 118 +++------------- cmake-module/fetchSDLProjectFromSource.cmake | 11 ++ includes/DOEngine_SDL_includes.h | 6 +- sample/CMakeLists.txt | 140 ++++++++++++++----- sample/SpaceInvader/SpaceInvader.cpp | 4 +- src/Application/SDLTTFText.cpp | 2 +- src/Application/SDLTexture.cpp | 4 +- src/Application/SDLWindowManager.cpp | 4 +- 8 files changed, 145 insertions(+), 144 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f32d27..00dae6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,11 +17,6 @@ set(DOENGINE_PREFERED_LANGUAGE 17) set(CMAKE_BUILD_TYPE Debug) set(CMAKE_CXX_STANDARD ${DOENGINE_PREFERED_LANGUAGE}) -set(SDL2IMAGE_INSTALL OFF) -set(BUILD_SHARED_LIBS FALSE) -set(SDL2_DISABLE_INSTALL OFF) -set(SDL2TTF_VENDORED TRUE) - if(FETCH_SDL_FROM_GIT) include(cmake-module/fetchSDLProjectFromSource.cmake) else() @@ -30,6 +25,26 @@ endif() set(ASSETS_DIR ${CMAKE_SOURCE_DIR}/assets) +set(DOENGINE_LIBRARIES ) +if(FETCH_SDL_FROM_GIT) + set(DOENGINE_LIBRARIES ${DOENGINE_LIBRARIES} + SDL2::SDL2 + SDL2::SDL2main + SDL2_ttf + SDL2_image + SDL2_mixer + ) +else() + set(DOENGINE_LIBRARIES ${DOENGINE_LIBRARIES} + SDL2 + SDL2main + SDL2_ttf + SDL2_image + SDL2_mixer + GL + ) +endif() + if(DOENGINE_TESTS) enable_testing() add_subdirectory(src/test) @@ -131,26 +146,6 @@ add_library(${PROJECT_NAME} ${DOENGINE_SRC} ) -set(DOENGINE_LIBRARIES ) -if(FETCH_SDL_FROM_GIT) - set(DOENGINE_LIBRARIES ${DOENGINE_LIBRARIES} - SDL2::SDL2 - SDL2::SDL2main - SDL2_ttf - SDL2_image - SDL2_mixer - ) -else() - set(DOENGINE_LIBRARIES ${DOENGINE_LIBRARIES} - SDL2 - SDL2main - SDL2_ttf - SDL2_image - SDL2_mixer - GL - ) -endif() - target_link_libraries(${PROJECT_NAME} PRIVATE ${DOENGINE_LIBRARIES}) message("Copying asssets to buils dir.") @@ -158,76 +153,3 @@ file(COPY ${ASSETS_DIR} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) # install(TARGETS ${PROJECT_NAME} DESTINATION /home/afl/Desktop/doengine ) - -#add_executable(${PROJECT_NAME}-sample -# sample/ignored_main.cpp -#) -add_executable(${PROJECT_NAME}-pong-sample - sample/pong/SimplePong.cpp -) - -add_executable(${PROJECT_NAME}-SpaceInvader-sample - sample/SpaceInvader/SpaceInvader.cpp -) - -add_executable(${PROJECT_NAME}-Tetris-sample - sample/tetris/Tetris.cpp -) - -add_executable(${PROJECT_NAME}-MusicPlayer-sample - sample/MusicPlayer/MusicPlayer.cpp -) -add_executable(BattleSpawn - sample/BattleSpawn/BattleSpawn.cpp -) -add_executable(PacmanClone - sample/Pacman/Pacman.cpp -) - -add_executable(BattleCityRecreation - sample/BattleCityRecreation/BattleCityRecreation.cpp -) - -# to build sample needs -# Zip support, ubuntu sudo apt-get install libzip-dev -#target_link_libraries(${PROJECT_NAME}-sample PRIVATE -# ${PROJECT_NAME} -# ${DOENGINE_LIBRARIES} -#) - -target_link_libraries(${PROJECT_NAME}-pong-sample PRIVATE - ${PROJECT_NAME} - ${DOENGINE_LIBRARIES} -) - -target_link_libraries(${PROJECT_NAME}-SpaceInvader-sample PRIVATE - ${PROJECT_NAME} - ${DOENGINE_LIBRARIES} -) - -target_link_libraries(${PROJECT_NAME}-Tetris-sample PRIVATE - ${PROJECT_NAME} - ${DOENGINE_LIBRARIES} -) - -target_link_libraries(${PROJECT_NAME}-MusicPlayer-sample PRIVATE - ${PROJECT_NAME} - ${DOENGINE_LIBRARIES} -) - -target_link_libraries(BattleSpawn PRIVATE - ${PROJECT_NAME} - ${DOENGINE_LIBRARIES} -) - -target_link_libraries(PacmanClone PRIVATE - ${PROJECT_NAME} - ${DOENGINE_LIBRARIES} -) - - -target_link_libraries(BattleCityRecreation PRIVATE - ${PROJECT_NAME} - ${DOENGINE_LIBRARIES} -) - diff --git a/cmake-module/fetchSDLProjectFromSource.cmake b/cmake-module/fetchSDLProjectFromSource.cmake index bdd0f06..4b8852e 100644 --- a/cmake-module/fetchSDLProjectFromSource.cmake +++ b/cmake-module/fetchSDLProjectFromSource.cmake @@ -1,5 +1,16 @@ include(FetchContent) + +SET(SDL2IMAGE_INSTALL OFF) +SET(BUILD_SHARED_LIBS FALSE) +SET(SDL2_DISABLE_INSTALL OFF) +SET(SDL2TTF_VENDORED ON) + +SET(SDL2IMAGE_SAMPLES OFF) +SET(SDL2IMAGE_TESTS OFF) +SET(SDL2IMAGE_AVIF OFF) +SET(SDL2IMAGE_VENDORED ON) + message("Fecthing SDL Source code") # SDL2 # SET(SDL_SHARED FALSE) diff --git a/includes/DOEngine_SDL_includes.h b/includes/DOEngine_SDL_includes.h index b7c7679..865c113 100644 --- a/includes/DOEngine_SDL_includes.h +++ b/includes/DOEngine_SDL_includes.h @@ -8,9 +8,9 @@ extern "C" #include #include #include -#include -#include -#include +#include +#include +#include } #endif diff --git a/sample/CMakeLists.txt b/sample/CMakeLists.txt index a31fc68..d07150c 100644 --- a/sample/CMakeLists.txt +++ b/sample/CMakeLists.txt @@ -5,6 +5,19 @@ project(DOSAMPLE) include_directories(DOSAMPLE PRIVATE ../includes) include_directories(MUSIC_SAMPLE PRIVATE ../includes) +set(ASSETS_DIR_OUTPUT_DIR "") + +if (CMAKE_SYSTEM_NAME STREQUAL "Linux") + message(STATUS "Linux") + set(ASSETS_DIR_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}") +elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows") + message(STATUS "Windows") + set(ASSETS_DIR_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}") +endif () + +file(COPY ${ASSETS_DIR} + DESTINATION "${ASSETS_DIR_OUTPUT_DIR}") + add_executable(DoSample main.cpp ) @@ -20,52 +33,109 @@ add_executable(Sound add_executable(Particles Particles/Particles.cpp ) -add_executable(VideoPlayer - VideoPlayer/VideoPlayer.cpp -) - -file(COPY ${ASSETS_DIR} - DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) - target_link_libraries(DoSample PRIVATE DOENGINE - SDL2 - SDL2main - SDL2_ttf SDL2_image - SDL2_mixer) + ${DOENGINE_LIBRARIES} +) target_link_libraries(Music PRIVATE DOENGINE - SDL2 - SDL2main - SDL2_ttf SDL2_image - SDL2_mixer) + ${DOENGINE_LIBRARIES} +) target_link_libraries(Sound PRIVATE DOENGINE - SDL2 - SDL2main - SDL2_ttf SDL2_image - SDL2_mixer) + ${DOENGINE_LIBRARIES} +) target_link_libraries(Particles PRIVATE DOENGINE - SDL2 - SDL2main - SDL2_ttf SDL2_image - SDL2_mixer) + ${DOENGINE_LIBRARIES} +) + +if(NOT FETCH_SDL_FROM_GIT) + add_executable(VideoPlayer + VideoPlayer/VideoPlayer.cpp + ) + # sudo apt install libsdl2-dev libavcodec-dev libavformat-dev libavutil-dev libswscale-dev + target_link_libraries(VideoPlayer PRIVATE + DOENGINE + ${DOENGINE_LIBRARIES} + avformat + avcodec + avutil + swscale + ) +endif() + +#add_executable(${PROJECT_NAME}-sample +# sample/ignored_main.cpp +#) +add_executable(SimplePong + pong/SimplePong.cpp +) + +add_executable(SpaceInvader + SpaceInvader/SpaceInvader.cpp +) + +add_executable(Tetris + tetris/Tetris.cpp +) + +add_executable(MusicPlayer + MusicPlayer/MusicPlayer.cpp +) +add_executable(BattleSpawn + BattleSpawn/BattleSpawn.cpp +) +add_executable(PacmanClone + Pacman/Pacman.cpp +) + +add_executable(BattleCityRecreation + BattleCityRecreation/BattleCityRecreation.cpp +) + +# to build sample needs +# Zip support, ubuntu sudo apt-get install libzip-dev +#target_link_libraries(${PROJECT_NAME}-sample PRIVATE +# ${PROJECT_NAME} +# ${DOENGINE_LIBRARIES} +#) + +target_link_libraries(SimplePong PRIVATE + DOENGINE + ${DOENGINE_LIBRARIES} +) + +target_link_libraries(SpaceInvader PRIVATE + DOENGINE + ${DOENGINE_LIBRARIES} +) + +target_link_libraries(Tetris PRIVATE + DOENGINE + ${DOENGINE_LIBRARIES} +) + +target_link_libraries(MusicPlayer PRIVATE + DOENGINE + ${DOENGINE_LIBRARIES} +) + +target_link_libraries(BattleSpawn PRIVATE + DOENGINE + ${DOENGINE_LIBRARIES} +) + +target_link_libraries(PacmanClone PRIVATE + DOENGINE + ${DOENGINE_LIBRARIES} +) -# sudo apt install libsdl2-dev libavcodec-dev libavformat-dev libavutil-dev libswscale-dev -target_link_libraries(VideoPlayer PRIVATE +target_link_libraries(BattleCityRecreation PRIVATE DOENGINE - SDL2 - SDL2main - SDL2_ttf - SDL2_image - SDL2_mixer - avformat - avcodec - avutil - swscale - ) \ No newline at end of file + ${DOENGINE_LIBRARIES} +) \ No newline at end of file diff --git a/sample/SpaceInvader/SpaceInvader.cpp b/sample/SpaceInvader/SpaceInvader.cpp index eaf8607..51acc9a 100644 --- a/sample/SpaceInvader/SpaceInvader.cpp +++ b/sample/SpaceInvader/SpaceInvader.cpp @@ -291,13 +291,13 @@ struct SpacerInvaderState : public doengine::GameState float gap = (wscreen - (wobstacle * cnt)) / 5; for(int i=0;i(offset_x), 400,0,0}}); } bool practice_mode = false; if(practice_mode){ for(int i=0;i(offset_x), 200,0,0}}); } } } diff --git a/src/Application/SDLTTFText.cpp b/src/Application/SDLTTFText.cpp index c1e0eb6..a1a0f41 100644 --- a/src/Application/SDLTTFText.cpp +++ b/src/Application/SDLTTFText.cpp @@ -1,7 +1,7 @@ #include "SDLTTFText.h" #include "Application.h" #include "Logger.h" -#include +#include "DOEngine_SDL_includes.h" #include #include diff --git a/src/Application/SDLTexture.cpp b/src/Application/SDLTexture.cpp index 9f391e0..da30724 100644 --- a/src/Application/SDLTexture.cpp +++ b/src/Application/SDLTexture.cpp @@ -1,6 +1,4 @@ -#include -#include -#include +#include "DOEngine_SDL_includes.h" #include #include "Application.h" diff --git a/src/Application/SDLWindowManager.cpp b/src/Application/SDLWindowManager.cpp index 55b21a0..834ab17 100644 --- a/src/Application/SDLWindowManager.cpp +++ b/src/Application/SDLWindowManager.cpp @@ -1,6 +1,6 @@ #include "SDLWindowManager.h" -#include -#include +#include "DOEngine_SDL_includes.h" + namespace doengine { bool SDLWindowManager::createWindow()