From de87ddb8d52b793563e15d5ab0b65aca1f83387a Mon Sep 17 00:00:00 2001 From: Kreijstal Date: Sun, 22 Oct 2023 23:25:11 +0200 Subject: [PATCH] Update CMakeLists.txt #fix 88 Simply adds conditions for when it is being compiled from mingw, and get the appropiate libraries --- CMakeLists.txt | 100 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 65 insertions(+), 35 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a4e52c0..951b2b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,38 +72,61 @@ endif() if (WIN32) option(OIS_WIN32_XINPUT_SUPPORT "Add support XInput." ON) - if(CMAKE_CROSSCOMPILING) - MESSAGE(STATUS "Cross-compiling ... search libraries instead of WindowsSDK") - find_library(DINPUT8_LIBRARY NAMES libdinput8.a dinput8.lib) - find_library(XINPUT8_LIBRARY NAMES libxinput.a) - find_library(DXGUID_LIBRARY NAMES libdxguid.a) - if (NOT DINPUT8_LIBRARY) - MESSAGE(FATAL_ERROR " could not locate dinput8 DirectX library") + if ("${CMAKE_CXX_PLATFORM_ID}" STREQUAL "MinGW") + # Directly specify the MinGW DirectX library paths + set(DINPUT8_LIBRARY "$ENV{MSYSTEM_PREFIX}/lib/libdinput8.a") + set(XINPUT8_LIBRARY "$ENV{MSYSTEM_PREFIX}/lib/libxinput.a") + set(DXGUID_LIBRARY "$ENV{MSYSTEM_PREFIX}/lib/libdxguid.a") + + if (NOT EXISTS ${DINPUT8_LIBRARY}) + MESSAGE(FATAL_ERROR "Could not locate dinput8 DirectX library") endif() - if (NOT XINPUT8_LIBRARY) - MESSAGE(FATAL_ERROR " could not locate xinput DirectX library") + if (NOT EXISTS ${XINPUT8_LIBRARY}) + MESSAGE(FATAL_ERROR "Could not locate xinput DirectX library") endif() - if (NOT DXGUID_LIBRARY) - MESSAGE(FATAL_ERROR " could not locate dxguid DirectX library") + if (NOT EXISTS ${DXGUID_LIBRARY}) + MESSAGE(FATAL_ERROR "Could not locate dxguid DirectX library") endif() - MESSAGE(STATUS " using " ${DINPUT8_LIBRARY} ", " ${XINPUT8_LIBRARY} " and " ${DXGUID_LIBRARY}) - else() - find_package(WindowsSDK) - # I'm assuming that this will be set under all normal circumstances - # if not, the user can set it themselves - if(WINDOWSSDK_FOUND) - set(OIS_WIN32_DXSDK_DIR ${WINDOWSSDK_PREFERRED_DIR} CACHE PATH "Location of the DirectX SDK on your system.") - else() - set(OIS_WIN32_DXSDK_DIR "$ENV{DXSDK_DIR}" CACHE PATH "Location of the DirectX SDK on your system.") + + MESSAGE(STATUS "Using ${DINPUT8_LIBRARY}, ${XINPUT8_LIBRARY} and ${DXGUID_LIBRARY}") + + if(BUILD_SHARED_LIBS) + add_definitions(-DOIS_DYNAMIC_LIB) endif() - if("${OIS_WIN32_DXSDK_DIR}" STREQUAL "") - MESSAGE(FATAL_ERROR "Could not locate DirectX SDK on this system") + else() + # Existing code for non-MinGW platforms + if(CMAKE_CROSSCOMPILING) + MESSAGE(STATUS "Cross-compiling ... search libraries instead of WindowsSDK") + find_library(DINPUT8_LIBRARY NAMES libdinput8.a dinput8.lib) + find_library(XINPUT8_LIBRARY NAMES libxinput.a) + find_library(DXGUID_LIBRARY NAMES libdxguid.a) + if (NOT DINPUT8_LIBRARY) + MESSAGE(FATAL_ERROR "Could not locate dinput8 DirectX library") + endif() + if (NOT XINPUT8_LIBRARY) + MESSAGE(FATAL_ERROR "Could not locate xinput DirectX library") + endif() + if (NOT DXGUID_LIBRARY) + MESSAGE(FATAL_ERROR "Could not locate dxguid DirectX library") + endif() + MESSAGE(STATUS "Using ${DINPUT8_LIBRARY}, ${XINPUT8_LIBRARY} and ${DXGUID_LIBRARY}") else() - MESSAGE(STATUS "Found DirectX SDK at ${OIS_WIN32_DXSDK_DIR}") + find_package(WindowsSDK) + if(WINDOWSSDK_FOUND) + set(OIS_WIN32_DXSDK_DIR ${WINDOWSSDK_PREFERRED_DIR} CACHE PATH "Location of the DirectX SDK on your system.") + else() + set(OIS_WIN32_DXSDK_DIR "$ENV{DXSDK_DIR}" CACHE PATH "Location of the DirectX SDK on your system.") + endif() + + if("${OIS_WIN32_DXSDK_DIR}" STREQUAL "") + MESSAGE(FATAL_ERROR "Could not locate DirectX SDK on this system") + else() + MESSAGE(STATUS "Found DirectX SDK at ${OIS_WIN32_DXSDK_DIR}") + endif() + + include_directories("${OIS_WIN32_DXSDK_DIR}/Include") endif() - - include_directories("${OIS_WIN32_DXSDK_DIR}/Include") endif() if(BUILD_SHARED_LIBS) @@ -170,21 +193,28 @@ if (APPLE) endif() if (WIN32) - if (CMAKE_CL_64) - set(DIRECTX_ARCH x64) + if ("${CMAKE_CXX_PLATFORM_ID}" STREQUAL "MinGW") + # Directly specify the MinGW DirectX library paths + link_directories("$ENV{MSYSTEM_PREFIX}/lib") + target_link_libraries(OIS "$ENV{MSYSTEM_PREFIX}/lib/libdinput8.a" "$ENV{MSYSTEM_PREFIX}/lib/libxinput.a" "$ENV{MSYSTEM_PREFIX}/lib/libdxguid.a") else() - set(DIRECTX_ARCH x86) - endif() + if (CMAKE_CL_64) + set(DIRECTX_ARCH x64) + else() + set(DIRECTX_ARCH x86) + endif() - if (WINDOWSSDK_FOUND) - target_link_libraries(OIS "dinput8.lib" "dxguid.lib") - elseif(CMAKE_CROSSCOMPILING) - target_link_libraries(OIS "${DINPUT8_LIBRARY}" "${XINPUT8_LIBRARY}" "${DXGUID_LIBRARY}") - else() - target_link_libraries(OIS "${DXSDK_DIR}/Lib/${DIRECTX_ARCH}/dinput8.lib" "${DXSDK_DIR}/Lib/${DIRECTX_ARCH}/dxguid.lib") + if (WINDOWSSDK_FOUND) + target_link_libraries(OIS "dinput8.lib" "dxguid.lib") + elseif(CMAKE_CROSSCOMPILING) + target_link_libraries(OIS "${DINPUT8_LIBRARY}" "${XINPUT8_LIBRARY}" "${DXGUID_LIBRARY}") + else() + target_link_libraries(OIS "${DXSDK_DIR}/Lib/${DIRECTX_ARCH}/dinput8.lib" "${DXSDK_DIR}/Lib/${DIRECTX_ARCH}/dxguid.lib") + endif() endif() endif() + if(UNIX) if (NOT APPLE)