FindWine.cmake 5.2 KB

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