DetectMachine.cmake 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. IF(WIN32)
  2. SET(LMMS_BUILD_WIN32 1)
  3. ELSEIF(APPLE)
  4. SET(LMMS_BUILD_APPLE 1)
  5. ELSEIF(${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD")
  6. SET(LMMS_BUILD_OPENBSD 1)
  7. ELSEIF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
  8. SET(LMMS_BUILD_FREEBSD 1)
  9. ELSEIF(HAIKU)
  10. SET(LMMS_BUILD_HAIKU 1)
  11. ELSE()
  12. SET(LMMS_BUILD_LINUX 1)
  13. ENDIF(WIN32)
  14. # LMMS_BUILD_MSYS also set in build_winXX.sh
  15. IF(LMMS_BUILD_WIN32 AND CMAKE_COMPILER_IS_GNUCXX AND DEFINED ENV{MSYSCON})
  16. SET(LMMS_BUILD_MSYS TRUE)
  17. ENDIF()
  18. MESSAGE("PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}")
  19. SET(LMMS_HOST_X86 FALSE)
  20. SET(LMMS_HOST_X86_64 FALSE)
  21. SET(LMMS_HOST_ARM32 FALSE)
  22. SET(LMMS_HOST_ARM64 FALSE)
  23. SET(LMMS_HOST_RISCV32 FALSE)
  24. SET(LMMS_HOST_RISCV64 FALSE)
  25. IF(NOT DEFINED WIN64 AND CMAKE_SIZEOF_VOID_P EQUAL 8)
  26. # TODO: This seems a bit presumptous
  27. SET(WIN64 ON)
  28. ENDIF()
  29. IF(WIN32)
  30. if(MSVC)
  31. SET(MSVC_VER ${CMAKE_CXX_COMPILER_VERSION})
  32. # Detect target architecture
  33. IF(CMAKE_GENERATOR_PLATFORM)
  34. STRING(TOLOWER "${CMAKE_GENERATOR_PLATFORM}" MSVC_TARGET_PLATFORM)
  35. ELSE()
  36. STRING(TOLOWER "${CMAKE_VS_PLATFORM_NAME_DEFAULT}" MSVC_TARGET_PLATFORM)
  37. ENDIF()
  38. IF(MSVC_TARGET_PLATFORM MATCHES "x64")
  39. SET(IS_X86_64 TRUE)
  40. SET(LMMS_BUILD_WIN64 TRUE)
  41. ELSEIF(MSVC_TARGET_PLATFORM MATCHES "win32")
  42. SET(IS_X86 TRUE)
  43. ELSEIF(MSVC_TARGET_PLATFORM MATCHES "arm64")
  44. SET(IS_ARM64 TRUE)
  45. ELSEIF(MSVC_TARGET_PLATFORM MATCHES "arm")
  46. SET(IS_ARM32 TRUE)
  47. ELSEIF(CMAKE_CXX_COMPILER MATCHES "amd64/cl.exe$" OR CMAKE_CXX_COMPILER MATCHES "x64/cl.exe$")
  48. SET(IS_X86_64 TRUE)
  49. SET(LMMS_BUILD_WIN64 TRUE)
  50. ELSEIF(CMAKE_CXX_COMPILER MATCHES "bin/cl.exe$" OR CMAKE_CXX_COMPILER MATCHES "x86/cl.exe$")
  51. SET(IS_X86 TRUE)
  52. ELSEIF(CMAKE_CXX_COMPILER MATCHES "arm64/cl.exe$")
  53. SET(IS_ARM64 TRUE)
  54. ELSEIF(CMAKE_CXX_COMPILER MATCHES "arm/cl.exe$")
  55. SET(IS_ARM32 TRUE)
  56. ELSE()
  57. MESSAGE(WARNING "Unknown target architecture: ${MSVC_TARGET_PLATFORM}")
  58. ENDIF()
  59. IF(MSVC_VER VERSION_GREATER 19.20 OR MSVC_VER VERSION_EQUAL 19.20)
  60. SET(LMMS_MSVC_GENERATOR "Visual Studio 16 2019")
  61. SET(LMMS_MSVC_YEAR 2019) # Qt only provides binaries for MSVC 2017, but 2019 is binary compatible
  62. ELSEIF(MSVC_VER VERSION_GREATER 19.10 OR MSVC_VER VERSION_EQUAL 19.10)
  63. SET(LMMS_MSVC_GENERATOR "Visual Studio 15 2017")
  64. SET(LMMS_MSVC_YEAR 2017)
  65. ELSEIF(MSVC_VER VERSION_GREATER 19.0 OR MSVC_VER VERSION_EQUAL 19.0)
  66. SET(LMMS_MSVC_GENERATOR "Visual Studio 14 2015")
  67. SET(LMMS_MSVC_YEAR 2015)
  68. ELSE()
  69. MESSAGE(SEND_WARNING "Can't detect MSVC version: ${MSVC_VER}")
  70. ENDIF()
  71. unset(MSVC_VER)
  72. else()
  73. # Cross-compiled
  74. # TODO: Handle Windows ARM64 targets
  75. IF(WIN64)
  76. SET(IS_X86_64 TRUE)
  77. SET(LMMS_BUILD_WIN64 TRUE)
  78. ELSE(WIN64)
  79. SET(IS_X86 TRUE)
  80. ENDIF(WIN64)
  81. endif()
  82. ELSE()
  83. # Detect target architecture based on compiler target triple e.g. "x86_64-pc-linux"
  84. EXEC_PROGRAM( ${CMAKE_C_COMPILER} ARGS "-dumpmachine ${CMAKE_C_FLAGS}" OUTPUT_VARIABLE Machine )
  85. MESSAGE("Machine: ${Machine}")
  86. STRING(REGEX MATCH "i.86" IS_X86 "${Machine}")
  87. STRING(REGEX MATCH "86_64|amd64" IS_X86_64 "${Machine}")
  88. IF(Machine MATCHES "arm|aarch64")
  89. IF(Machine MATCHES "arm64|aarch64")
  90. SET(IS_ARM64 TRUE)
  91. ELSE()
  92. SET(IS_ARM32 TRUE)
  93. ENDIF()
  94. ELSEIF(Machine MATCHES "rv|riscv")
  95. IF(Machine MATCHES "rv64|riscv64")
  96. SET(IS_RISCV64 TRUE)
  97. ELSE()
  98. SET(IS_RISCV32 TRUE)
  99. ENDIF()
  100. ENDIF()
  101. ENDIF()
  102. IF(IS_X86)
  103. MESSAGE("-- Target host is 32 bit, Intel")
  104. SET(LMMS_HOST_X86 TRUE)
  105. ELSEIF(IS_X86_64)
  106. MESSAGE("-- Target host is 64 bit, Intel")
  107. SET(LMMS_HOST_X86_64 TRUE)
  108. ELSEIF(IS_ARM32)
  109. MESSAGE("-- Target host is 32 bit, ARM")
  110. SET(LMMS_HOST_ARM32 TRUE)
  111. ELSEIF(IS_ARM64)
  112. MESSAGE("-- Target host is 64 bit, ARM")
  113. SET(LMMS_HOST_ARM64 TRUE)
  114. ELSEIF(IS_RISCV32)
  115. MESSAGE("-- Target host is 32 bit, RISC-V")
  116. SET(LMMS_HOST_RISCV32 TRUE)
  117. ELSEIF(IS_RISCV64)
  118. MESSAGE("-- Target host is 64 bit, RISC-V")
  119. SET(LMMS_HOST_RISCV64 TRUE)
  120. ELSE()
  121. MESSAGE("Can't identify target host. Assuming 32 bit platform.")
  122. ENDIF()
  123. IF(CMAKE_INSTALL_LIBDIR)
  124. SET(LIB_DIR "${CMAKE_INSTALL_LIBDIR}")
  125. ELSE(CMAKE_INSTALL_LIBDIR)
  126. SET(LIB_DIR lib)
  127. ENDIF(CMAKE_INSTALL_LIBDIR)
  128. IF(LMMS_BUILD_WIN32)
  129. SET(BIN_DIR .)
  130. SET(PLUGIN_DIR plugins)
  131. SET(DATA_DIR data)
  132. SET(LMMS_DATA_DIR data)
  133. ELSE(LMMS_BUILD_WIN32)
  134. SET(BIN_DIR bin)
  135. SET(PLUGIN_DIR ${LIB_DIR}/lmms)
  136. SET(DATA_DIR share)
  137. SET(LMMS_DATA_DIR ${DATA_DIR}/lmms)
  138. ENDIF(LMMS_BUILD_WIN32)
  139. IF(LMMS_BUILD_APPLE)
  140. # Detect Homebrew versus Macports environment
  141. EXECUTE_PROCESS(COMMAND brew --prefix RESULT_VARIABLE DETECT_HOMEBREW OUTPUT_VARIABLE HOMEBREW_PREFIX ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
  142. EXECUTE_PROCESS(COMMAND which port RESULT_VARIABLE DETECT_MACPORTS OUTPUT_VARIABLE MACPORTS_PREFIX ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
  143. IF(${DETECT_HOMEBREW} EQUAL 0)
  144. SET(HOMEBREW 1)
  145. SET(APPLE_PREFIX "${HOMEBREW_PREFIX}")
  146. ELSEIF(${DETECT_MACPORTS} EQUAL 0)
  147. SET(MACPORTS 1)
  148. GET_FILENAME_COMPONENT(MACPORTS_PREFIX ${MACPORTS_PREFIX} DIRECTORY)
  149. GET_FILENAME_COMPONENT(MACPORTS_PREFIX ${MACPORTS_PREFIX} DIRECTORY)
  150. SET(APPLE_PREFIX "${MACPORTS_PREFIX}")
  151. LINK_DIRECTORIES(${LINK_DIRECTORIES} ${APPLE_PREFIX}/lib)
  152. ENDIF()
  153. # Detect OS Version
  154. EXECUTE_PROCESS(COMMAND sw_vers -productVersion OUTPUT_VARIABLE APPLE_OS_VER ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
  155. STRING(REGEX REPLACE "\\.[0-9]*$" "" APPLE_OS_VER "${APPLE_OS_VER}")
  156. SET(CMAKE_MACOSX_RPATH 1)
  157. ENDIF()