Skip to content

Commit

Permalink
Fix for SDL on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszkax86 committed Nov 26, 2022
1 parent b7cb268 commit 21b6572
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
13 changes: 10 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,20 @@ include("${colobot_SOURCE_DIR}/cmake/colobot-lint.cmake")
##

find_package(OpenGL 1.4 REQUIRED)
find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
find_package(SDL2_ttf REQUIRED)
find_package(PNG 1.2 REQUIRED)
find_package(Gettext REQUIRED)
find_package(PhysFS REQUIRED)

if(PLATFORM_WINDOWS)
find_package(SDL2 CONFIG REQUIRED)
find_package(SDL2_image CONFIG REQUIRED)
find_package(SDL2_ttf CONFIG REQUIRED)
else()
find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
find_package(SDL2_ttf REQUIRED)
endif()

set(Boost_USE_STATIC_LIBS ${BOOST_STATIC})
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME ${USE_STATIC_RUNTIME})
Expand Down
24 changes: 20 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,6 @@ target_include_directories(colobotbase PUBLIC
target_link_libraries(colobotbase PUBLIC
CBot
localename
SDL2::Core
SDL2::Image
SDL2::TTF
OpenGL::GL
PNG::PNG
GLEW::GLEW
Expand All @@ -507,6 +504,20 @@ if(mp3lame_FOUND)
)
endif()

if(PLATFORM_WINDOWS)
target_link_libraries(colobotbase PUBLIC
$<IF:$<TARGET_EXISTS:SDL2::SDL2>,SDL2::SDL2,SDL2::SDL2-static>
$<IF:$<TARGET_EXISTS:SDL2_image::SDL2_image>,SDL2_image::SDL2_image,SDL2_image::SDL2_image-static>
$<IF:$<TARGET_EXISTS:SDL2_ttf::SDL2_ttf>,SDL2_ttf::SDL2_ttf,SDL2_ttf::SDL2_ttf-static>
)
elseif()
target_link_libraries(colobotbase PUBLIC
SDL2::Core
SDL2::Image
SDL2::TTF
)
endif()

# Optional libraries
if(OPENAL_SOUND)
target_sources(colobotbase PRIVATE
Expand Down Expand Up @@ -601,7 +612,12 @@ endif()
if(PLATFORM_WINDOWS)
target_sources(colobot PRIVATE ../desktop/colobot.rc)
endif()
target_link_libraries(colobot colobotbase SDL2::Main)

if(PLATFORM_WINDOWS)
target_link_libraries(colobot colobotbase SDL2::SDL2main)
elseif()
target_link_libraries(colobot colobotbase SDL2::Main)
endif()

# Install
install(TARGETS colobot RUNTIME DESTINATION ${COLOBOT_INSTALL_BIN_DIR})
Expand Down

0 comments on commit 21b6572

Please sign in to comment.