cmake: need SDL2main on Windows (and other platforms) + link to m on GNU/clang

This commit is contained in:
Anonymous Maarten 2021-01-02 20:37:11 +01:00
parent 7f0b98f960
commit 4d260a631b
2 changed files with 28 additions and 5 deletions

View File

@ -1,16 +1,19 @@
find_package(PkgConfig QUIET) find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND) if(PKG_CONFIG_FOUND)
pkg_check_modules(SDL2 IMPORTED_TARGET "sdl2") pkg_check_modules(SDL2 IMPORTED_TARGET "sdl2")
if(TARGET PkgConfig::SDL2 AND NOT TARGET sdl2::sdl2) if(TARGET PkgConfig::SDL2 AND NOT TARGET SDL2::SDL2)
add_library(_sdl2 INTERFACE) add_library(SDL2::SDL2 INTERFACE IMPORTED)
target_link_libraries(_sdl2 INTERFACE PkgConfig::SDL2) set_property(TARGET SDL2::SDL2 PROPERTY INTERFACE_LINK_LIBRARIES PkgConfig::SDL2)
add_library(SDL2::SDL2 ALIAS _sdl2)
endif() endif()
endif() endif()
find_library(SDL2main_LIBRARY SDL2main)
if(NOT SDL2_FOUND) if(NOT SDL2_FOUND)
find_path(SDL2_INCLUDE_DIR sdl2.h) find_path(SDL2_INCLUDE_DIR sdl2.h)
find_library(SDL2_LIBRARY sdl2) find_library(SDL2_LIBRARY SDL2 SDL2d)
find_library(SDL2main_LIBRARY SDL2main)
include(FindPackageHandleStandardArgs) include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(libuv find_package_handle_standard_args(libuv
@ -25,3 +28,11 @@ if(NOT SDL2_FOUND)
) )
endif() endif()
endif() endif()
if(SDL2main_LIBRARY AND NOT TARGET SDL2::SDL2main)
add_library(SDL2::SDL2main UNKNOWN IMPORTED)
set_target_properties(SDL2::SDL2main PROPERTIES
IMPORTED_LOCATION "${SDL2main_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}"
)
endif()

View File

@ -107,6 +107,12 @@ target_compile_definitions(librw
"RW_${LIBRW_PLATFORM}" "RW_${LIBRW_PLATFORM}"
) )
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_link_libraries(librw
PRIVATE
m
)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
target_compile_options(librw target_compile_options(librw
PRIVATE PRIVATE
@ -161,6 +167,12 @@ if(LIBRW_PLATFORM_GL3)
PUBLIC PUBLIC
SDL2::SDL2 SDL2::SDL2
) )
if(TARGET SDL2::SDL2main)
target_link_libraries(librw
PUBLIC
SDL2::SDL2main
)
endif()
endif() endif()
elseif(LIBRW_PLATFORM_D3D9) elseif(LIBRW_PLATFORM_D3D9)
target_link_libraries(librw target_link_libraries(librw