mirror of https://github.com/aap/librw.git
Resolve WinMain linking issues with CMake
This commit is contained in:
parent
b1781f4189
commit
77753c8539
|
@ -1,22 +1,21 @@
|
|||
find_package(PkgConfig QUIET)
|
||||
if(PKG_CONFIG_FOUND)
|
||||
pkg_check_modules(SDL2 IMPORTED_TARGET "sdl2")
|
||||
if(TARGET PkgConfig::SDL2 AND NOT TARGET SDL2::SDL2)
|
||||
add_library(SDL2::SDL2 INTERFACE IMPORTED)
|
||||
set_property(TARGET SDL2::SDL2 PROPERTY INTERFACE_LINK_LIBRARIES PkgConfig::SDL2)
|
||||
# On Windows, SDL2main is included as part of the pkg-config output, which isn't desirable when linking.
|
||||
if(NOT WIN32)
|
||||
find_package(PkgConfig QUIET)
|
||||
if(PKG_CONFIG_FOUND)
|
||||
pkg_check_modules(SDL2 IMPORTED_TARGET "sdl2")
|
||||
if(TARGET PkgConfig::SDL2 AND NOT TARGET SDL2::SDL2)
|
||||
add_library(SDL2::SDL2 INTERFACE IMPORTED)
|
||||
set_property(TARGET SDL2::SDL2 PROPERTY INTERFACE_LINK_LIBRARIES PkgConfig::SDL2)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
find_library(SDL2main_LIBRARY SDL2main)
|
||||
|
||||
if(NOT SDL2_FOUND)
|
||||
find_path(SDL2_INCLUDE_DIR sdl2.h)
|
||||
find_path(SDL2_INCLUDE_DIR SDL.h PATH_SUFFIXES SDL2)
|
||||
find_library(SDL2_LIBRARY SDL2 SDL2d)
|
||||
|
||||
find_library(SDL2main_LIBRARY SDL2main)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(libuv
|
||||
find_package_handle_standard_args(SDL2
|
||||
REQUIRED_VARS SDL2_INCLUDE_DIR SDL2_LIBRARY
|
||||
)
|
||||
|
||||
|
@ -29,6 +28,8 @@ if(NOT SDL2_FOUND)
|
|||
endif()
|
||||
endif()
|
||||
|
||||
find_library(SDL2main_LIBRARY SDL2main)
|
||||
|
||||
if(SDL2main_LIBRARY AND NOT TARGET SDL2::SDL2main)
|
||||
add_library(SDL2::SDL2main UNKNOWN IMPORTED)
|
||||
set_target_properties(SDL2::SDL2main PROPERTIES
|
||||
|
|
|
@ -19,7 +19,6 @@ add_library(librw_skeleton
|
|||
imgui/stb_textedit.h
|
||||
imgui/stb_truetype.h
|
||||
)
|
||||
add_library(librw::skeleton ALIAS librw_skeleton)
|
||||
|
||||
set_target_properties(librw_skeleton
|
||||
PROPERTIES
|
||||
|
@ -38,6 +37,20 @@ target_include_directories(librw_skeleton
|
|||
$<INSTALL_INTERFACE:${LIBRW_INSTALL_INCLUDEDIR}/skeleton>
|
||||
)
|
||||
|
||||
# HACK: When building with MinGW, it's necessary to link to libmingw32.a *before* the library
|
||||
# that provides WinMain. To work around this, an intermediate target is created when using MinGW
|
||||
# that specifies the correct linking order.
|
||||
#
|
||||
# TODO: Use SDL_main on platforms that require it
|
||||
if(MINGW AND LIBRW_PLATFORM_D3D9)
|
||||
add_library(librw_skeleton_main INTERFACE)
|
||||
find_library(MINGW32_LIBRARY NAMES mingw32)
|
||||
target_link_libraries(librw_skeleton_main INTERFACE ${MINGW32_LIBRARY} librw_skeleton)
|
||||
add_library(librw::skeleton ALIAS librw_skeleton_main)
|
||||
else()
|
||||
add_library(librw::skeleton ALIAS librw_skeleton)
|
||||
endif()
|
||||
|
||||
if(LIBRW_INSTALL)
|
||||
install(
|
||||
FILES
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
#ifdef LIBRW_SDL2
|
||||
|
||||
#ifdef _WIN32
|
||||
#define SDL_MAIN_HANDLED
|
||||
#endif
|
||||
#include <rw.h>
|
||||
#include "skeleton.h"
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#ifdef _WIN32
|
||||
#define SDL_MAIN_HANDLED
|
||||
#include <windows.h>
|
||||
#include <rw.h>
|
||||
#include "skeleton.h"
|
||||
|
@ -291,7 +292,7 @@ SetMousePosition(int x, int y)
|
|||
|
||||
#endif
|
||||
|
||||
#ifdef RW_OPENGL
|
||||
#if defined(RW_OPENGL) && !defined(__MINGW32__)
|
||||
int main(int argc, char *argv[]);
|
||||
|
||||
int WINAPI
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <cstring>
|
||||
#include <cassert>
|
||||
|
||||
#define SDL_MAIN_HANDLED
|
||||
#include <rw.h>
|
||||
|
||||
using namespace std;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define SDL_MAIN_HANDLED
|
||||
#include <rw.h>
|
||||
#include <args.h>
|
||||
|
||||
|
|
Loading…
Reference in New Issue