Skip to content

Commit

Permalink
Update CMakeLists.txt
Browse files Browse the repository at this point in the history
#fix 88
Simply adds conditions for when it is being compiled from mingw, and get the appropiate libraries
  • Loading branch information
Kreijstal authored Oct 22, 2023
1 parent 7344e96 commit de87ddb
Showing 1 changed file with 65 additions and 35 deletions.
100 changes: 65 additions & 35 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit de87ddb

Please sign in to comment.