FindWine.cmake 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. # - Try to find the wine libraries
  2. # Once done this will define
  3. #
  4. # WINE_FOUND - System has wine
  5. # WINE_INCLUDE_DIRS - The wine include directories
  6. # WINE_LIBRARIES - The libraries needed to use wine
  7. # WINE_DEFINITIONS - Compiler switches required for using wine
  8. #
  9. MACRO(_findwine_find_flags output expression result)
  10. STRING(REPLACE " " ";" WINEBUILD_FLAGS "${output}")
  11. FOREACH(FLAG ${WINEBUILD_FLAGS})
  12. IF("${FLAG}" MATCHES "${expression}")
  13. SET(${result} "${FLAG}")
  14. ENDIF()
  15. ENDFOREACH()
  16. ENDMACRO()
  17. LIST(APPEND CMAKE_PREFIX_PATH /opt/wine-stable /opt/wine-devel /opt/wine-staging /usr/lib/wine/)
  18. FIND_PROGRAM(WINE_CXX
  19. NAMES wineg++ winegcc winegcc64 winegcc32 winegcc-stable
  20. PATHS /usr/lib/wine
  21. )
  22. FIND_PROGRAM(WINE_BUILD NAMES winebuild)
  23. # Detect wine paths and handle linking problems
  24. IF(WINE_CXX)
  25. EXEC_PROGRAM(${WINE_CXX} ARGS "-m32 -v /dev/zero" OUTPUT_VARIABLE WINEBUILD_OUTPUT_32)
  26. EXEC_PROGRAM(${WINE_CXX} ARGS "-m64 -v /dev/zero" OUTPUT_VARIABLE WINEBUILD_OUTPUT_64)
  27. _findwine_find_flags("${WINEBUILD_OUTPUT_32}" "^-isystem/usr/include$" BUGGED_WINEGCC)
  28. _findwine_find_flags("${WINEBUILD_OUTPUT_32}" "^-isystem" WINEGCC_INCLUDE_DIR)
  29. _findwine_find_flags("${WINEBUILD_OUTPUT_32}" "libwinecrt0\\.a.*" WINECRT_32)
  30. _findwine_find_flags("${WINEBUILD_OUTPUT_64}" "libwinecrt0\\.a.*" WINECRT_64)
  31. STRING(REGEX REPLACE "^-isystem" "" WINE_INCLUDE_HINT "${WINEGCC_INCLUDE_DIR}")
  32. STRING(REGEX REPLACE "/wine/windows$" "" WINE_INCLUDE_HINT "${WINE_INCLUDE_HINT}")
  33. STRING(REGEX REPLACE "libwinecrt0\\.a.*" "" WINE_32_LIBRARY_DIR "${WINECRT_32}")
  34. STRING(REGEX REPLACE "libwinecrt0\\.a.*" "" WINE_64_LIBRARY_DIR "${WINECRT_64}")
  35. IF(BUGGED_WINEGCC)
  36. MESSAGE(WARNING "Your winegcc is unusable due to https://bugs.winehq.org/show_bug.cgi?id=46293,\n
  37. Consider either upgrading or downgrading wine.")
  38. RETURN()
  39. ENDIF()
  40. IF(WINE_32_LIBRARY_DIR STREQUAL WINE_64_LIBRARY_DIR)
  41. MESSAGE(STATUS "Old winegcc detected, trying to use workaround linking")
  42. # Fix library search directory according to the target bitness
  43. IF(WINE_32_LIBRARY_DIR MATCHES "/lib/(x86_64|i386)-")
  44. # Debian systems
  45. STRING(REPLACE "/lib/x86_64-" "/lib/i386-" WINE_32_LIBRARY_DIR "${WINE_32_LIBRARY_DIR}")
  46. STRING(REPLACE "/lib/i386-" "/lib/x86_64-" WINE_64_LIBRARY_DIR "${WINE_64_LIBRARY_DIR}")
  47. ELSEIF(WINE_32_LIBRARY_DIR MATCHES "/(lib|lib64)/wine/$")
  48. # WineHQ (/opt/wine-stable, /opt/wine-devel, /opt/wine-staging)
  49. STRING(REGEX REPLACE "/lib64/wine/$" "/lib/wine/" WINE_32_LIBRARY_DIR "${WINE_32_LIBRARY_DIR}")
  50. STRING(REGEX REPLACE "/lib/wine/$" "/lib64/wine/" WINE_64_LIBRARY_DIR "${WINE_64_LIBRARY_DIR}")
  51. ELSEIF(WINE_32_LIBRARY_DIR MATCHES "/lib32/.*/wine/")
  52. # Systems with old multilib layout
  53. STRING(REPLACE "/lib32/" "/lib/" WINE_64_LIBRARY_DIR "${WINE_32_LIBRARY_DIR}")
  54. ELSEIF(WINE_32_LIBRARY_DIR MATCHES "/lib64/.*/wine/")
  55. # We need to test if the corresponding 64bit library directory is lib or lib32
  56. STRING(REPLACE "/lib64/" "/lib32/" WINE_32_LIBRARY_DIR "${WINE_64_LIBRARY_DIR}")
  57. IF(NOT EXISTS "${WINE_32_LIBRARY_DIR}")
  58. STRING(REPLACE "/lib64/" "/lib/" WINE_32_LIBRARY_DIR "${WINE_64_LIBRARY_DIR}")
  59. ENDIF()
  60. ELSEIF(WINE_32_LIBRARY_DIR MATCHES "/lib/.*/wine/")
  61. # Test if this directory is for 32bit or 64bit
  62. STRING(REPLACE "/lib/" "/lib32/" WINE_32_LIBRARY_DIR "${WINE_64_LIBRARY_DIR}")
  63. IF(NOT EXISTS "${WINE_32_LIBRARY_DIR}")
  64. SET(WINE_32_LIBRARY_DIR "${WINE_64_LIBRARY_DIR}")
  65. STRING(REPLACE "/lib/" "/lib64/" WINE_64_LIBRARY_DIR "${WINE_64_LIBRARY_DIR}")
  66. ENDIF()
  67. ELSE()
  68. MESSAGE(WARNING "Can't detect wine installation layout. You may get some build errors.")
  69. ENDIF()
  70. SET(WINE_LIBRARY_FIX "${WINE_32_LIBRARY_DIR} and ${WINE_64_LIBRARY_DIR}")
  71. ENDIF()
  72. ENDIF()
  73. FIND_PATH(WINE_INCLUDE_DIR wine/exception.h
  74. HINTS "${WINE_INCLUDE_HINT}"
  75. )
  76. SET(_ARCHITECTURE ${CMAKE_LIBRARY_ARCHITECTURE})
  77. FIND_LIBRARY(WINE_LIBRARY NAMES wine
  78. PATH_SUFFIXES wine i386-linux-gnu/wine
  79. HINTS "${WINE_32_LIBRARY_DIR}" "${WINE_64_LIBRARY_DIR}"
  80. )
  81. SET(CMAKE_LIBRARY_ARCHITECTURE ${_ARCHITECTURE})
  82. SET(WINE_INCLUDE_DIRS ${WINE_INCLUDE_DIR} )
  83. SET(WINE_LIBRARIES ${WINE_LIBRARY})
  84. include(FindPackageHandleStandardArgs)
  85. find_package_handle_standard_args(Wine DEFAULT_MSG WINE_CXX WINE_LIBRARIES WINE_INCLUDE_DIRS)
  86. mark_as_advanced(WINE_INCLUDE_DIR WINE_LIBRARY WINE_CXX WINE_BUILD)
  87. IF(WINE_32_LIBRARY_DIR)
  88. IF(WINE_32_LIBRARY_DIR MATCHES "wine*/lib")
  89. SET(WINE_32_FLAGS "-L${WINE_32_LIBRARY_DIR} -L${WINE_32_LIBRARY_DIR}../")
  90. SET(WINE_32_LIBRARY_DIRS "${WINE_32_LIBRARY_DIR}:${WINE_32_LIBRARY_DIR}/..")
  91. ELSE()
  92. SET(WINE_32_FLAGS "-L${WINE_32_LIBRARY_DIR}")
  93. SET(WINE_32_LIBRARY_DIRS "${WINE_32_LIBRARY_DIR}")
  94. ENDIF()
  95. ENDIF()
  96. IF(WINE_64_LIBRARY_DIR)
  97. IF(WINE_64_LIBRARY_DIR MATCHES "wine*/lib")
  98. SET(WINE_64_FLAGS "-L${WINE_64_LIBRARY_DIR} -L${WINE_64_LIBRARY_DIR}../")
  99. SET(WINE_64_LIBRARY_DIRS "${WINE_64_LIBRARY_DIR}:${WINE_64_LIBRARY_DIR}/..")
  100. ELSE()
  101. SET(WINE_64_FLAGS "-L${WINE_64_LIBRARY_DIR}")
  102. SET(WINE_64_LIBRARY_DIRS "${WINE_64_LIBRARY_DIR}")
  103. ENDIF()
  104. ENDIF()
  105. # Create winegcc wrapper
  106. configure_file(${CMAKE_CURRENT_LIST_DIR}/winegcc_wrapper.in winegcc_wrapper @ONLY)
  107. SET(WINEGCC "${CMAKE_CURRENT_BINARY_DIR}/winegcc_wrapper")