CMakeLists.txt 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094
  1. # Find Ogre module.
  2. # Auto-detect common OGRE install locations if the user didn't provide one.
  3. # TODO: Add candidates for other platforms.
  4. if(NOT DEFINED OGRE_ROOT)
  5. set(_OGRE_CANDIDATES
  6. "/usr/lib/x86_64-linux-gnu/OGRE"
  7. "/usr/lib/OGRE"
  8. "/usr/local/lib/OGRE"
  9. "/usr/share/OGRE"
  10. )
  11. foreach(_cand IN LISTS _OGRE_CANDIDATES)
  12. if(EXISTS "${_cand}")
  13. # If the candidate points to an include directory like
  14. # /usr/include/OGRE,set OGRE_ROOT to the system root (two
  15. # directories up) so later searches for modules/libraries find it.
  16. if(_cand MATCHES "/include/OGRE$" OR _cand MATCHES ".*/OGRE$")
  17. get_filename_component(_p "${_cand}" DIRECTORY)
  18. get_filename_component(_p2 "${_p}" DIRECTORY)
  19. set(OGRE_ROOT "${_p2}")
  20. else()
  21. set(OGRE_ROOT "${_cand}")
  22. endif()
  23. message(STATUS "Auto-detected OGRE_ROOT=${OGRE_ROOT}")
  24. break()
  25. endif()
  26. endforeach()
  27. endif()
  28. # Explicitly search for other common libraries if CMake find modules failed.
  29. if(NOT OIS_LIBRARIES)
  30. find_library(_ois_lib NAMES OIS OIS-1.3.0 libOIS-1.3.0 libOIS HINTS /usr/lib /usr/lib/x86_64-linux-gnu /usr/local/lib)
  31. if(_ois_lib)
  32. set(OIS_LIBRARIES ${_ois_lib})
  33. message(STATUS "Found OIS library: ${_ois_lib}")
  34. endif()
  35. endif()
  36. # Option: control whether deterministic filesystem fallbacks are allowed.
  37. # When ON (default), CMake will try SONAME/`/usr/lib` fallbacks and inject
  38. # generic `-lboost_*` flags as a last resort to improve out-of-tree builds on
  39. # systems without proper dev packages. Set to OFF to require proper find_package
  40. # results or user-supplied hints (preferred for packaging/CI).
  41. option(USE_DETERMINISTIC_FALLBACKS "Enable deterministic filesystem fallbacks for library detection (SONAME and /usr/lib path appends). Toggle off to require proper dev packages or OGRE_ROOT." ON)
  42. if(NOT TinyXML_LIBRARIES)
  43. find_library(_tinyxml_lib NAMES tinyxml libtinyxml TinyXML TiXml libtinyxml2 tinyxml2 libtinyxml2 HINTS /usr/lib /usr/lib/x86_64-linux-gnu /usr/local/lib)
  44. if(_tinyxml_lib)
  45. set(TinyXML_LIBRARIES ${_tinyxml_lib})
  46. message(STATUS "Found TinyXML library: ${_tinyxml_lib}")
  47. endif()
  48. endif()
  49. if(NOT OPENAL_LIBRARY)
  50. find_library(_openal_lib NAMES openal libopenal OpenAL openal32 libopenal.so.1 HINTS /usr/lib /usr/lib/x86_64-linux-gnu /usr/local/lib)
  51. if(_openal_lib)
  52. set(OPENAL_LIBRARY ${_openal_lib})
  53. message(STATUS "Fallback: Found OpenAL library: ${_openal_lib}")
  54. endif()
  55. endif()
  56. if(NOT OGGVORBIS_LIBRARIES)
  57. set(_ov)
  58. find_library(_vorbisfile_lib NAMES vorbisfile libvorbisfile libvorbisfile.so vorbisfile.so HINTS /usr/lib /usr/lib/x86_64-linux-gnu /usr/local/lib)
  59. find_library(_vorbis_lib NAMES vorbis libvorbis libvorbis.so vorbis.so HINTS /usr/lib /usr/lib/x86_64-linux-gnu /usr/local/lib)
  60. find_library(_ogg_lib NAMES ogg libogg libogg.so ogg.so HINTS /usr/lib /usr/lib/x86_64-linux-gnu /usr/local/lib)
  61. if(_vorbisfile_lib)
  62. list(APPEND _ov ${_vorbisfile_lib})
  63. endif()
  64. if(_vorbis_lib)
  65. list(APPEND _ov ${_vorbis_lib})
  66. endif()
  67. if(_ogg_lib)
  68. list(APPEND _ov ${_ogg_lib})
  69. endif()
  70. if(_ov)
  71. set(OGGVORBIS_LIBRARIES ${_ov})
  72. message(STATUS "Found Ogg/Vorbis libraries: ${_ov}")
  73. endif()
  74. endif()
  75. # Try to find additional OGRE components if they are present as system libs
  76. foreach(_comp IN ITEMS OgreOverlay OgreBites OgreRTShaderSystem OgreProperty OgrePaging OgreVolume)
  77. find_library(_comp_lib NAMES ${_comp} lib${_comp} ${_comp}.so HINTS /usr/lib /usr/lib/x86_64-linux-gnu /usr/local/lib ${OGRE_ROOT}/lib)
  78. if(_comp_lib)
  79. list(APPEND OGRE_LIBRARIES ${_comp_lib})
  80. message(STATUS "Found OGRE component ${_comp}: ${_comp_lib}")
  81. endif()
  82. endforeach()
  83. # Remove any duplicate entries that may have been appended by fallbacks
  84. list(REMOVE_DUPLICATES OGRE_LIBRARIES)
  85. # Try pkg-config to find OGRE (if available on the system)
  86. find_package(PkgConfig QUIET)
  87. if(PKG_CONFIG_FOUND)
  88. pkg_check_modules(_ogre_pkgs QUIET OGRE)
  89. if(_ogre_pkgs_FOUND)
  90. if(_ogre_pkgs.prefix)
  91. if(NOT DEFINED OGRE_ROOT)
  92. set(OGRE_ROOT "${_ogre_pkgs.prefix}")
  93. endif()
  94. message(STATUS "Found OGRE via pkg-config, OGRE_ROOT=${OGRE_ROOT}")
  95. # If pkg-config gives a prefix, try to set CMake module path.
  96. set(_candidate_cm_path "${_ogre_pkgs.prefix}/CMake")
  97. if(EXISTS "${_candidate_cm_path}")
  98. set(OGRE_CMAKE_MODULE_PATH "${_candidate_cm_path}")
  99. else()
  100. set(_candidate_cm_path "${_ogre_pkgs.prefix}/cmake")
  101. if(EXISTS "${_candidate_cm_path}")
  102. set(OGRE_CMAKE_MODULE_PATH "${_candidate_cm_path}")
  103. endif()
  104. endif()
  105. endif()
  106. # Export include dirs and libraries from pkg-config for later usage
  107. set(OGRE_INCLUDE_DIRS ${_ogre_pkgs_INCLUDE_DIRS})
  108. # Convert pkg-config library flags (e.g. "-L.. -lOgreMain -lOgreBites")
  109. # into a CMake list so target_link_libraries handles them correctly.
  110. string(REPLACE " " ";" _pkg_libs_list "${_ogre_pkgs_LIBRARIES}")
  111. list(APPEND OGRE_LIBRARIES ${_pkg_libs_list})
  112. set(OGRE_PKG_FOUND TRUE)
  113. endif()
  114. endif()
  115. # If OGRE_ROOT is not still yet, try locating Ogre headers or the OgreMain
  116. # library directly
  117. if(NOT DEFINED OGRE_ROOT)
  118. find_path(_ogre_header Ogre.h HINTS /usr/include/OGRE /usr/include /usr/local/include)
  119. if(_ogre_header)
  120. # If header was found in /usr/include/OGRE, set OGRE_ROOT to /usr
  121. get_filename_component(_hdr_dir "${_ogre_header}" DIRECTORY)
  122. if(_hdr_dir MATCHES "/include/OGRE$" OR _hdr_dir MATCHES ".*/OGRE$")
  123. get_filename_component(_p "${_hdr_dir}" DIRECTORY)
  124. get_filename_component(_p2 "${_p}" DIRECTORY)
  125. set(OGRE_ROOT "${_p2}")
  126. else()
  127. # header found in include root; set OGRE_ROOT to parent
  128. get_filename_component(_p "${_hdr_dir}" DIRECTORY)
  129. set(OGRE_ROOT "${_p}")
  130. endif()
  131. message(STATUS "Found Ogre header at ${_ogre_header}; setting OGRE_ROOT=${OGRE_ROOT}")
  132. endif()
  133. endif()
  134. # If OGRE_ROOT is not still yet, try locating Ogre headers or the OgreMain
  135. # library directly
  136. if(NOT DEFINED OGRE_ROOT)
  137. find_library(_ogre_lib OgreMain HINTS /usr/lib /usr/lib/x86_64-linux-gnu /usr/local/lib)
  138. if(_ogre_lib)
  139. get_filename_component(_lib_dir "${_ogre_lib}" DIRECTORY)
  140. # set OGRE_ROOT two levels up if libs are in /usr/lib/x86_64-linux-gnu
  141. get_filename_component(_p "${_lib_dir}" DIRECTORY)
  142. get_filename_component(_p2 "${_p}" DIRECTORY)
  143. set(OGRE_ROOT "${_p2}")
  144. message(STATUS "Found Ogre library ${_ogre_lib}; setting OGRE_ROOT=${OGRE_ROOT}")
  145. endif()
  146. endif()
  147. set(CMAKE_FRAMEWORK_PATH
  148. ${CMAKE_FRAMEWORK_PATH}
  149. ${CMAKE_SOURCE_DIR}/OgreSDK/lib/macosx/Release
  150. ${CMAKE_SOURCE_DIR}/OgreSDK/lib/macosx/Debug
  151. )
  152. set(OGRE_FRAMEWORK_INCLUDES ${CMAKE_SOURCE_DIR}/OgreSDK/include)
  153. find_path(OGRE_CMAKE_MODULE_PATH FindOGRE.cmake
  154. HINTS
  155. "$ENV{OGRE_HOME}/CMake/"
  156. "/usr/lib/x86_64-linux-gnu/OGRE/cmake"
  157. "/usr/lib/x86_64-linux-gnu/OGRE"
  158. "/usr/local/lib/OGRE/cmake"
  159. "/usr/lib/OGRE/cmake"
  160. "/usr/share/OGRE/cmake/modules"
  161. "${CMAKE_CURRENT_SOURCE_DIR}/OgreSDK/CMake"
  162. )
  163. if(NOT OGRE_CMAKE_MODULE_PATH)
  164. # Try additional conventional locations using OGRE_ROOT if set by user or
  165. # auto-detection
  166. if(DEFINED OGRE_ROOT)
  167. find_path(OGRE_CMAKE_MODULE_PATH FindOGRE.cmake HINTS "${OGRE_ROOT}/CMake" "${OGRE_ROOT}/cmake")
  168. endif()
  169. endif()
  170. if(NOT OGRE_CMAKE_MODULE_PATH)
  171. message(WARNING "FindOGRE.cmake not found in expected locations; will try pkg-config or config-mode find_package(OGRE)")
  172. else()
  173. list(APPEND CMAKE_MODULE_PATH "${OGRE_CMAKE_MODULE_PATH}" "${CMAKE_SOURCE_DIR}/CMake")
  174. endif()
  175. # Find Boost module.
  176. if (WIN32)
  177. set(Boost_USE_STATIC_LIBS TRUE)
  178. else()
  179. # Statically linking boost to a dynamic Ogre build doesn't work on Linux
  180. # 64bit.
  181. set(Boost_USE_STATIC_LIBS ${OGRE_STATIC})
  182. endif ()
  183. if (MINGW)
  184. # Ensure OgreBites is linked (provides WindowEventUtilities and related
  185. # symbols).
  186. find_library(_ogrebites_lib OgreBites HINTS ${OGRE_ROOT} /usr/lib /usr/lib/x86_64-linux-gnu /usr/local/lib)
  187. if(_ogrebites_lib)
  188. # This is probably a bug in CMake: the boost find module tries to look for
  189. # boost libraries with name libboost_*, but CMake already prefixes library
  190. # search names with "lib". This is the workaround.
  191. set(CMAKE_FIND_LIBRARY_PREFIXES ${CMAKE_FIND_LIBRARY_PREFIXES} "")
  192. endif ()
  193. # Components that need linking (NB does not include header-only components like
  194. # bind).
  195. set(OGRE_BOOST_COMPONENTS thread date_time)
  196. find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET)
  197. if (NOT Boost_FOUND)
  198. set(Boost_USE_STATIC_LIBS NOT ${Boost_USE_STATIC_LIBS})
  199. find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET)
  200. endif()
  201. if(Boost_FOUND AND Boost_VERSION GREATER 104900)
  202. set(OGRE_BOOST_COMPONENTS thread date_time system chrono)
  203. find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET)
  204. endif()
  205. # Set up referencing of Boost.
  206. if (NOT APPLE)
  207. add_definitions(-DBOOST_ALL_NO_LIB)
  208. endif()
  209. if (Boost_LIBRARIES STREQUAL "")
  210. message(STATUS "Boost_LIBRARIES is not set yet; will attempt robust fallbacks later")
  211. endif()
  212. #message(STATUS "DEBUG: entering Boost detection; BOOST_COMPONENTS=${BOOST_COMPONENTS} BOOST_LINK_LIBS=${BOOST_LINK_LIBS}")
  213. # Find packages required for V-Gears.
  214. # Prefer pkg-config discovery for OGRE (works with system packages). If
  215. # pkg-config finds OGRE, populate OGRE_INCLUDE_DIRS and OGRE_LIBRARIES and
  216. # skip find_package(OGRE). Otherwise fall back to the existing FindOGRE logic.
  217. find_package(PkgConfig QUIET)
  218. if(NOT DEFINED OGRE_PKG_FOUND)
  219. if(PKG_CONFIG_FOUND)
  220. # pkg-config already attempted above; if OGRE_PKG_FOUND is set, use it.
  221. if(DEFINED _ogre_pkgs_FOUND AND _ogre_pkgs_FOUND)
  222. set(OGRE_PKG_FOUND TRUE)
  223. # OGRE_INCLUDE_DIRS/OGRE_LIBRARIES were set earlier when
  224. # _ogre_pkgs was found.
  225. endif()
  226. endif()
  227. endif()
  228. if(NOT OGRE_PKG_FOUND)
  229. find_package(OGRE REQUIRED QUIET)
  230. else()
  231. message(STATUS "Using OGRE from pkg-config: includes=${OGRE_INCLUDE_DIRS}")
  232. endif()
  233. # If pkg-config was used, try to locate common OGRE component libraries
  234. if(OGRE_PKG_FOUND)
  235. set(_extra_ogre_libs)
  236. foreach(_comp IN ITEMS OgreOverlay OgreBites OgreRTShaderSystem)
  237. find_library(_lib ${_comp} HINTS ${OGRE_ROOT} /usr/lib /usr/lib/x86_64-linux-gnu /usr/local/lib PATHS ${OGRE_ROOT}/lib)
  238. if(_lib)
  239. list(APPEND _extra_ogre_libs ${_lib})
  240. message(STATUS "Found OGRE component ${_comp}: ${_lib}")
  241. endif()
  242. endforeach()
  243. if(_extra_ogre_libs)
  244. list(APPEND OGRE_LIBRARIES ${_extra_ogre_libs})
  245. endif()
  246. # Display final OGRE libraries that will be linked
  247. message(STATUS "Using OGRE_LIBRARIES: ${OGRE_LIBRARIES}")
  248. endif()
  249. # Find OIS.
  250. find_package(OIS QUIET)
  251. if(NOT OIS_FOUND)
  252. find_library(_ois_lib NAMES OIS libOIS ois HINTS /usr/lib /usr/lib/x86_64-linux-gnu /usr/local/lib)
  253. if(_ois_lib)
  254. set(OIS_LIBRARIES ${_ois_lib})
  255. message(STATUS "Found OIS library: ${_ois_lib}")
  256. else()
  257. message(STATUS "OIS not found by find_package; will attempt to continue and emit clearer diagnostics later.")
  258. endif()
  259. endif()
  260. # Find OpenAL.
  261. find_package(OpenAL QUIET)
  262. if(NOT OPENAL_FOUND AND PKG_CONFIG_FOUND)
  263. pkg_check_modules(_openal_pkgs QUIET openal)
  264. if(_openal_pkgs_FOUND)
  265. list(APPEND OPENAL_LIBRARY ${_openal_pkgs_LIBRARIES})
  266. list(APPEND OPENAL_INCLUDE_DIR ${_openal_pkgs_INCLUDE_DIRS})
  267. message(STATUS "Found OpenAL via pkg-config: ${_openal_pkgs_LIBRARIES}")
  268. endif()
  269. endif()
  270. if(NOT OPENAL_FOUND AND NOT OPENAL_LIBRARY)
  271. find_library(_openal_lib NAMES openal libopenal OpenAL openal32 HINTS /usr/lib /usr/lib/x86_64-linux-gnu /usr/local/lib)
  272. if(_openal_lib)
  273. set(OPENAL_LIBRARY ${_openal_lib})
  274. message(STATUS "Found OpenAL library: ${_openal_lib}")
  275. endif()
  276. endif()
  277. # Find OggVorbis.
  278. find_package(OggVorbis QUIET)
  279. if(NOT OGGVORBIS_FOUND)
  280. find_library(_vorbisfile_lib NAMES vorbisfile libvorbisfile HINTS /usr/lib /usr/lib/x86_64-linux-gnu /usr/local/lib)
  281. find_library(_vorbis_lib NAMES vorbis libvorbis HINTS /usr/lib /usr/lib/x86_64-linux-gnu /usr/local/lib)
  282. find_library(_ogg_lib NAMES ogg libogg HINTS /usr/lib /usr/lib/x86_64-linux-gnu /usr/local/lib)
  283. set(_ovlibs)
  284. if(_vorbisfile_lib)
  285. list(APPEND _ovlibs ${_vorbisfile_lib})
  286. endif()
  287. if(_vorbis_lib)
  288. list(APPEND _ovlibs ${_vorbis_lib})
  289. endif()
  290. if(_ogg_lib)
  291. list(APPEND _ovlibs ${_ogg_lib})
  292. endif()
  293. if(_ovlibs)
  294. set(OGGVORBIS_LIBRARIES ${_ovlibs})
  295. message(STATUS "Found Ogg/Vorbis libraries: ${_ovlibs}")
  296. else()
  297. message(STATUS "Ogg/Vorbis not found by find_package; will attempt to continue and emit clearer diagnostics later.")
  298. endif()
  299. endif()
  300. # If the installer is requested, ensure Qt is available. If Qt is missing,
  301. # disable the installer to avoid compilation failures.
  302. if(BUILD_INSTALLER)
  303. # Optional user-provided hint: allow passing a single path that contains
  304. # the Qt CMake config directories (e.g. '/usr/lib/x86_64-linux-gnu/cmake').
  305. set(QT_DIR_HINT "" CACHE PATH "Optional hint for Qt CMake config directory (parent of Qt5/Qt6)")
  306. if(QT_DIR_HINT)
  307. # If user passed a hint, set Qt5_DIR/Qt6_DIR to assist find_package.
  308. if(EXISTS "${QT_DIR_HINT}/Qt5")
  309. set(Qt5_DIR "${QT_DIR_HINT}/Qt5" CACHE PATH "Qt5 dir from hint" FORCE)
  310. elseif(EXISTS "${QT_DIR_HINT}/Qt5Core")
  311. set(Qt5_DIR "${QT_DIR_HINT}/Qt5Core" CACHE PATH "Qt5 dir from hint" FORCE)
  312. endif()
  313. if(EXISTS "${QT_DIR_HINT}/Qt6")
  314. set(Qt6_DIR "${QT_DIR_HINT}/Qt6" CACHE PATH "Qt6 dir from hint" FORCE)
  315. endif()
  316. endif()
  317. # Try Qt5 first, then fall back to Qt6. Prefer imported targets for linking.
  318. find_package(Qt5 COMPONENTS Core Widgets Gui QUIET)
  319. # Debugging: print detected Qt5 variables/targets when present
  320. if(TARGET Qt5::Core)
  321. message(STATUS "Qt5 imported: target Qt5::Core is available")
  322. endif()
  323. message(STATUS "Qt5Core_FOUND=${Qt5Core_FOUND} Qt5Widgets_FOUND=${Qt5Widgets_FOUND} Qt5Gui_FOUND=${Qt5Gui_FOUND}")
  324. # Some distro setups place Qt config files in nonstandard cmake dirs that
  325. # CMake may not probe. If the normal find_package didn't create imported
  326. # targets or set FOUND variables, probe common Qt config locations and
  327. # retry find_package with explicit hints.
  328. if(NOT (TARGET Qt5::Core OR Qt5Core_FOUND))
  329. set(_qt_candidate_dirs
  330. /usr/lib/x86_64-linux-gnu/cmake/Qt5
  331. /usr/lib/x86_64-linux-gnu/cmake/Qt5Core
  332. /usr/lib/cmake/Qt5
  333. /usr/lib64/cmake/Qt5
  334. /usr/local/lib/cmake/Qt5
  335. $ENV{HOME}/.local/lib/cmake/Qt5
  336. )
  337. foreach(_qd IN LISTS _qt_candidate_dirs)
  338. if(EXISTS "${_qd}/Qt5Config.cmake" OR EXISTS "${_qd}/Qt5CoreConfig.cmake")
  339. message(STATUS "Found Qt5 config file under ${_qd}; retrying find_package(Qt5) with PATHS hint")
  340. set(Qt5_DIR "${_qd}" CACHE PATH "Detected Qt5 dir" FORCE)
  341. find_package(Qt5 COMPONENTS Core Widgets Gui QUIET PATHS "${_qd}")
  342. break()
  343. endif()
  344. endforeach()
  345. endif()
  346. if(TARGET Qt5::Core OR Qt5Core_FOUND)
  347. set(QT_LINK_LIBS Qt5::Core Qt5::Widgets Qt5::Gui)
  348. if(DEFINED Qt5Core_INCLUDE_DIRS)
  349. set(QT_INCLUDE_DIRS ${Qt5Core_INCLUDE_DIRS})
  350. endif()
  351. message(STATUS "Found Qt5; installer will be built using Qt5.")
  352. else()
  353. find_package(Qt6 COMPONENTS Core Widgets Gui QUIET)
  354. if(NOT (TARGET Qt6::Core OR Qt6Core_FOUND))
  355. # Retry probing common Qt6 cmake locations as well
  356. set(_qt6_candidate_dirs
  357. /usr/lib/x86_64-linux-gnu/cmake/Qt6
  358. /usr/lib/cmake/Qt6
  359. /usr/lib64/cmake/Qt6
  360. /usr/local/lib/cmake/Qt6
  361. $ENV{HOME}/.local/lib/cmake/Qt6
  362. )
  363. foreach(_qd IN LISTS _qt6_candidate_dirs)
  364. if(EXISTS "${_qd}/Qt6Config.cmake" OR EXISTS "${_qd}/Qt6CoreConfig.cmake")
  365. message(STATUS "Found Qt6 config file under ${_qd}; retrying find_package(Qt6) with PATHS hint")
  366. set(Qt6_DIR "${_qd}" CACHE PATH "Detected Qt6 dir" FORCE)
  367. find_package(Qt6 COMPONENTS Core Widgets Gui QUIET PATHS "${_qd}")
  368. break()
  369. endif()
  370. endforeach()
  371. endif()
  372. if(TARGET Qt6::Core OR Qt6Core_FOUND)
  373. set(QT_LINK_LIBS Qt6::Core Qt6::Widgets Qt6::Gui)
  374. set(QT_INCLUDE_DIRS)
  375. message(STATUS "Found Qt6; installer will be built using Qt6.")
  376. else()
  377. # Attempt a pragmatic fallback: search for Qt headers/libs in common
  378. # distro include/lib locations and link manually if found. This is
  379. # less featureful than using the Qt CMake config (imported targets),
  380. # but it helps the installer build on systems where Qt dev packages
  381. # are installed but config-mode find_package didn't succeed.
  382. set(_qt_fallback_includes)
  383. set(_qt_fallback_libs)
  384. set(_qt_inc_candidates /usr/include/qt5 /usr/include/x86_64-linux-gnu/qt5 /usr/include)
  385. foreach(_inc IN LISTS _qt_inc_candidates)
  386. if(EXISTS "${_inc}/QtCore/QtGlobal")
  387. list(APPEND _qt_fallback_includes ${_inc})
  388. message(STATUS "Pragmatic Qt fallback: found headers under ${_inc}")
  389. break()
  390. endif()
  391. endforeach()
  392. # Try to find Qt5 libraries by SONAME/name
  393. foreach(_libname IN ITEMS Qt5Core Qt5Widgets Qt5Gui)
  394. find_library(_qtl NAMES ${_libname} ${_libname}.so lib${_libname}.so HINTS /usr/lib /usr/lib/x86_64-linux-gnu /usr/local/lib)
  395. if(_qtl)
  396. list(APPEND _qt_fallback_libs ${_qtl})
  397. message(STATUS "Pragmatic Qt fallback: found ${_libname}: ${_qtl}")
  398. endif()
  399. endforeach()
  400. if(_qt_fallback_libs AND _qt_fallback_includes)
  401. set(QT_LINK_LIBS ${_qt_fallback_libs})
  402. set(QT_INCLUDE_DIRS ${_qt_fallback_includes})
  403. message(STATUS "Using pragmatic Qt fallback (manual include/libs). Installer will be built.")
  404. else()
  405. # As a last resort, and only when deterministic fallbacks are
  406. # enabled, inject generic Qt5 linker flags and common include
  407. # paths so the installer can still be built on Debian/Ubuntu-like
  408. # systems where the config-mode package lookup didn't succeed.
  409. if(USE_DETERMINISTIC_FALLBACKS)
  410. message(STATUS "Pragmatic Qt fallback failed; using generic Qt -l flags and include paths as last resort")
  411. set(QT_LINK_LIBS -lQt5Core -lQt5Widgets -lQt5Gui)
  412. set(QT_INCLUDE_DIRS /usr/include/qt5 /usr/include/x86_64-linux-gnu/qt5)
  413. else()
  414. message(WARNING "BUILD_INSTALLER requested but Qt5/Qt6 not found and pragmatic fallback failed. Disabling installer build. Install Qt dev packages or set BUILD_INSTALLER=OFF.")
  415. set(BUILD_INSTALLER OFF CACHE BOOL "Build the V-Gears-Installer" FORCE)
  416. endif()
  417. endif()
  418. endif()
  419. endif()
  420. endif()
  421. # Find TinyXML
  422. find_package(TinyXML QUIET)
  423. if(NOT TinyXML_FOUND)
  424. find_library(_tinyxml_lib NAMES tinyxml libtinyxml TiXml TiXmlDocument HINTS /usr/lib /usr/lib/x86_64-linux-gnu /usr/local/lib)
  425. if(_tinyxml_lib)
  426. set(TinyXML_LIBRARIES ${_tinyxml_lib})
  427. message(STATUS "Found TinyXML library: ${_tinyxml_lib}")
  428. else()
  429. message(STATUS "TinyXML not found by find_package; will attempt to continue and emit clearer diagnostics later.")
  430. endif()
  431. endif()
  432. # Find Boost module with common components and fall back to robust per-component search
  433. set(BOOST_COMPONENTS program_options filesystem thread system chrono)
  434. # First try to pick up modern imported targets (Boost::component)
  435. set(BOOST_LINK_LIBS)
  436. foreach(_comp IN LISTS BOOST_COMPONENTS)
  437. if(TARGET Boost::${_comp})
  438. list(APPEND BOOST_LINK_LIBS Boost::${_comp})
  439. endif()
  440. endforeach()
  441. # Next try the classic find_package that populates Boost_LIBRARIES
  442. if(NOT BOOST_LINK_LIBS)
  443. find_package(Boost COMPONENTS ${BOOST_COMPONENTS} QUIET)
  444. if(NOT Boost_FOUND)
  445. # Try toggling static preference once
  446. set(Boost_USE_STATIC_LIBS NOT ${Boost_USE_STATIC_LIBS})
  447. find_package(Boost COMPONENTS ${BOOST_COMPONENTS} QUIET)
  448. endif()
  449. if(Boost_FOUND AND Boost_LIBRARIES)
  450. list(APPEND BOOST_LINK_LIBS ${Boost_LIBRARIES})
  451. message(STATUS "Found Boost (find_package): ${Boost_VERSION}; libraries: ${Boost_LIBRARIES}")
  452. endif()
  453. endif()
  454. # Final fallback: search for per-component shared objects in common lib dirs
  455. if(NOT BOOST_LINK_LIBS)
  456. foreach(_comp IN LISTS BOOST_COMPONENTS)
  457. # Look for any versioned libboost_${comp}*.so* file
  458. file(GLOB _found_libs
  459. /usr/lib*/libboost_${_comp}*.so*
  460. /usr/local/lib*/libboost_${_comp}*.so*
  461. )
  462. if(_found_libs)
  463. # Prefer the first (usually the SONAME symlink), but append all found to be safe
  464. list(APPEND BOOST_LINK_LIBS ${_found_libs})
  465. message(STATUS "Found boost ${_comp}: ${_found_libs}")
  466. else()
  467. message(STATUS "Not found: boost ${_comp} not found in standard lib dirs")
  468. endif()
  469. endforeach()
  470. if(NOT BOOST_LINK_LIBS)
  471. message(STATUS "No Boost libs found; linking will fail. Install libboost-*-dev packages.")
  472. endif()
  473. endif()
  474. # Try a direct SONAME-style find_library pass for each component (preferred:
  475. # yields absolute paths like /usr/lib/x86_64-linux-gnu/libboost_program_options.so.1.83.0).
  476. if(NOT BOOST_LINK_LIBS)
  477. foreach(_comp IN LISTS BOOST_COMPONENTS)
  478. # try common SONAME/filename variants so find_library returns full paths
  479. find_library(_boost_soname
  480. NAMES libboost_${_comp}.so libboost_${_comp} boost_${_comp} boost_${_comp}.so
  481. HINTS /usr/lib /usr/lib/x86_64-linux-gnu /usr/local/lib
  482. PATH_SUFFIXES . lib lib64
  483. )
  484. if(_boost_soname)
  485. list(APPEND BOOST_LINK_LIBS ${_boost_soname})
  486. message(STATUS "Found Boost SONAME for ${_comp}: ${_boost_soname}")
  487. endif()
  488. endforeach()
  489. if(NOT BOOST_LINK_LIBS)
  490. message(STATUS "SONAME pass did not find Boost libs; falling back to -l flags next.")
  491. endif()
  492. endif()
  493. # If previous attempts didn't produce usable lib paths, fall back to linker flags
  494. # using common Boost library names so the system linker searches standard paths.
  495. if(NOT BOOST_LINK_LIBS)
  496. if(USE_DETERMINISTIC_FALLBACKS)
  497. find_library(_boost_system_lib
  498. NAMES boost_system libboost_system
  499. HINTS /usr/lib /usr/lib/x86_64-linux-gnu /usr/local/lib
  500. PATH_SUFFIXES . lib lib64
  501. )
  502. set(_generic_boost_flags -lboost_program_options -lboost_filesystem -lboost_thread -lboost_chrono)
  503. if(_boost_system_lib)
  504. list(APPEND _generic_boost_flags ${_boost_system_lib})
  505. else()
  506. message(STATUS "Boost.System library not found; omitting boost_system from generic Boost flags.")
  507. endif()
  508. set(BOOST_LINK_LIBS ${_generic_boost_flags})
  509. message(STATUS "Using generic Boost flags: ${BOOST_LINK_LIBS}")
  510. else()
  511. message(WARNING "Boost libraries not found and USE_DETERMINISTIC_FALLBACKS is OFF. Install libboost-*-dev packages or provide Boost hints (Boost_DIR/Boost_INCLUDE_DIR).")
  512. endif()
  513. endif()
  514. # Deduplicate and export a stable list for later linking
  515. list(REMOVE_DUPLICATES BOOST_LINK_LIBS)
  516. message(STATUS "Final BOOST_LINK_LIBS: ${BOOST_LINK_LIBS}")
  517. # Root source dir for V-Gears sources (used for include paths).
  518. if(NOT DEFINED VGEARS_SOURCE_DIR)
  519. set(VGEARS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
  520. endif()
  521. # Ensure OgreBites (WindowEventUtilities) is explicitly found and linked when
  522. # available.
  523. if(NOT OGRE_LIBRARIES)
  524. set(OGRE_LIBRARIES)
  525. endif()
  526. find_library(_ogrebites_lib NAMES OgreBites libOgreBites OgreBites.so HINTS /usr/lib /usr/lib/x86_64-linux-gnu /usr/local/lib ${OGRE_ROOT}/lib)
  527. if(_ogrebites_lib)
  528. list(FIND OGRE_LIBRARIES ${_ogrebites_lib} _idx)
  529. if(_idx EQUAL -1)
  530. list(APPEND OGRE_LIBRARIES ${_ogrebites_lib})
  531. message(STATUS "Explicitly found OgreBites: ${_ogrebites_lib}")
  532. endif()
  533. else()
  534. message(STATUS "OgreBites not found by explicit search; OgreBites symbols may be unresolved.")
  535. endif()
  536. # As a last-resort deterministic fallback, append the system path if the file
  537. # exists.
  538. if(NOT OGRE_LIBRARIES MATCHES ".*OgreBites.*")
  539. if(USE_DETERMINISTIC_FALLBACKS)
  540. if(EXISTS "/usr/lib/x86_64-linux-gnu/libOgreBites.so")
  541. list(APPEND OGRE_LIBRARIES "/usr/lib/x86_64-linux-gnu/libOgreBites.so")
  542. message(STATUS "Appended deterministic OgreBites path: /usr/lib/x86_64-linux-gnu/libOgreBites.so")
  543. endif()
  544. else()
  545. message(WARNING "OgreBites not found and USE_DETERMINISTIC_FALLBACKS is OFF. Set OGRE_ROOT or install OGRE dev packages.")
  546. endif()
  547. endif()
  548. # Source files for libvgears and v-gears.
  549. set(VGEARS_SOURCE_FILES
  550. app/main.cpp
  551. common/FF7Character.cpp
  552. common/FF7Common.cpp
  553. app/VGearsGameState.cpp
  554. common/File.cpp
  555. common/FileSystem.cpp
  556. common/FinalFantasy7/FF7NameLookup.cpp
  557. common/LzsFile.cpp
  558. common/TypeDefine.cpp
  559. common/DataDirectory.cpp
  560. common/InstallStamp.cpp
  561. common/OgrePlugins.cpp
  562. app/VGearsApplication.cpp
  563. common/VGearsManualObject.cpp
  564. common/VGearsResource.cpp
  565. common/VGearsStringUtil.cpp
  566. core/AudioManager.cpp
  567. core/Background2DAnimation.cpp
  568. core/Background2D.cpp
  569. core/BackgroundPalette.cpp
  570. core/ScreenFade.cpp
  571. core/MovieCameraFrame.cpp
  572. core/MoviePlayer.cpp
  573. core/MovieState.cpp
  574. core/ScreenFadeState.cpp
  575. core/BattleManager.cpp
  576. core/CameraManager.cpp
  577. core/ConfigCmd.cpp
  578. core/ConfigCmdHandler.cpp
  579. core/ConfigFile.cpp
  580. core/ConfigVar.cpp
  581. core/ConfigVarHandler.cpp
  582. core/Console.cpp
  583. core/DebugDraw.cpp
  584. core/DialogsManager.cpp
  585. core/Enemy.cpp
  586. core/EntityCollision.cpp
  587. core/Entity.cpp
  588. core/EntityDirection.cpp
  589. core/EntityManager.cpp
  590. core/EntityModel.cpp
  591. core/EntityPoint.cpp
  592. core/EntityTrigger.cpp
  593. core/GameFrameListener.cpp
  594. core/InputManager.cpp
  595. core/Manager.cpp
  596. core/particles/Particle.cpp
  597. core/particles/ParticleEmitter.cpp
  598. core/particles/ParticleEmitterDictionary.cpp
  599. core/particles/ParticleEmitterTranslator.cpp
  600. core/particles/ParticleRenderer.cpp
  601. core/particles/ParticleRendererTranslator.cpp
  602. core/particles/ParticleSystem.cpp
  603. core/particles/ParticleSystemFactory.cpp
  604. core/particles/ParticleSystemManager.cpp
  605. core/particles/ParticleSystemTranslator.cpp
  606. core/particles/ParticleSystemTranslatorManager.cpp
  607. core/particles/ParticleTechnique.cpp
  608. core/particles/ParticleTechniqueTranslator.cpp
  609. core/particles/ParticleVisual.cpp
  610. core/particles/emitters/PointEmitter.cpp
  611. core/particles/emitters/PointEmitterFactory.cpp
  612. core/particles/renderer/ParticleEntityRenderer.cpp
  613. core/particles/renderer/ParticleEntityRendererDictionary.cpp
  614. core/Savemap.cpp
  615. core/SavemapHandler.cpp
  616. core/ScriptManager.cpp
  617. core/TextHandler.cpp
  618. core/Timer.cpp
  619. core/UiAnimation.cpp
  620. core/UiFont.cpp
  621. core/UiManager.cpp
  622. core/UiSprite.cpp
  623. core/UiTextArea.cpp
  624. core/UiWidget.cpp
  625. common/Utilites.cpp
  626. core/Walkmesh.cpp
  627. core/WorldMapManager.cpp
  628. core/XmlAttackFile.cpp
  629. core/XmlBackground2DFile.cpp
  630. core/XmlBattleCharactersFile.cpp
  631. core/XmlBattleScenesFile.cpp
  632. core/XmlEnemyFile.cpp
  633. core/XmlFile.cpp
  634. core/XmlFontFile.cpp
  635. core/XmlFontsFile.cpp
  636. core/XmlFormationFile.cpp
  637. core/XmlMapFile.cpp
  638. core/XmlMapsFile.cpp
  639. core/XmlMusicsFile.cpp
  640. core/XmlPrototypesFile.cpp
  641. core/XmlScreenFile.cpp
  642. core/XmlScreensFile.cpp
  643. core/XmlScriptsFile.cpp
  644. core/XmlSoundsFile.cpp
  645. core/XmlTextFile.cpp
  646. core/XmlTextsFile.cpp
  647. core/XmlWalkmeshFile.cpp
  648. data/VGearsAFile.cpp
  649. data/VGearsAFileManager.cpp
  650. data/VGearsAFileSerializer.cpp
  651. data/VGearsBackgroundFile.cpp
  652. data/VGearsBackgroundFileManager.cpp
  653. data/VGearsBackgroundFileSerializer.cpp
  654. data/VGearsCameraMatrixFile.cpp
  655. data/VGearsCameraMatrixFileManager.cpp
  656. data/VGearsCameraMatrixFileSerializer.cpp
  657. data/VGearsFLevelBackground2DLoader.cpp
  658. data/VGearsFLevelFile.cpp
  659. data/VGearsFLevelFileSerializer.cpp
  660. data/VGearsFLevelTextureLoader.cpp
  661. data/VGearsHRCFile.cpp
  662. data/VGearsHRCFileManager.cpp
  663. data/VGearsHRCFileSerializer.cpp
  664. data/VGearsHRCMeshLoader.cpp
  665. data/VGearsHRCSkeletonLoader.cpp
  666. data/VGearsLGPArchive.cpp
  667. data/VGearsLGPArchiveFactory.cpp
  668. data/VGearsLGPArchiveSerializer.cpp
  669. data/VGearsLZSDataStream.cpp
  670. data/VGearsLZSFLevelFile.cpp
  671. data/VGearsLZSFLevelFileManager.cpp
  672. data/VGearsMapListFile.cpp
  673. data/VGearsPaletteFile.cpp
  674. data/VGearsPaletteFileManager.cpp
  675. data/VGearsPaletteFileSerializer.cpp
  676. data/VGearsPFile.cpp
  677. data/VGearsPFileManager.cpp
  678. data/VGearsPFileSerializer.cpp
  679. data/VGearsRSDFile.cpp
  680. data/VGearsRSDFileManager.cpp
  681. data/VGearsRSDFileSerializer.cpp
  682. data/VGearsSerializer.cpp
  683. data/VGearsTexCodec.cpp
  684. data/VGearsTexFile.cpp
  685. data/VGearsTriggersFile.cpp
  686. data/VGearsXMLSerializer.cpp
  687. data/FinalFantasy7/FF7ModelListFile.cpp
  688. data/FinalFantasy7/FF7ModelListFileManager.cpp
  689. data/FinalFantasy7/FF7ModelListFileSerializer.cpp
  690. data/worldmap/WorldmapFile.cpp
  691. data/worldmap/WorldmapFileManager.cpp
  692. data/worldmap/WorldmapFileSerializer.cpp
  693. data/worldmap/TxzFile.cpp
  694. data/worldmap/TxzFileSerializer.cpp
  695. map/VGearsBackground2DFile.cpp
  696. map/VGearsBackground2DFileManager.cpp
  697. map/VGearsBackground2DFileXMLSerializer.cpp
  698. map/VGearsWalkmeshFile.cpp
  699. map/VGearsWalkmeshFileManager.cpp
  700. map/VGearsWalkmeshFileXMLSerializer.cpp
  701. map/FinalFantasy7/FF7WalkmeshFileSerializer.cpp
  702. modules/worldmap/WorldmapModule.cpp
  703. )
  704. endif()
  705. # Compiler options.
  706. if(APPLE) # Apple specific options
  707. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
  708. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
  709. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
  710. endif()
  711. if(WIN32) # Check usage and remove if uneccessary
  712. add_definitions(-DWIN32 -D__WIN32__ -D_WINDOWS)
  713. add_definitions(-W -mthreads -fmessage-length=0 -fexceptions -fident)
  714. # Linker options
  715. add_definitions(
  716. -Wl,--enable-runtime-pseudo-reloc
  717. -Wl,--enable-auto-image-base
  718. -Wl,--add-stdcall-alias
  719. )
  720. endif()
  721. if (MSVC)
  722. # Build cpp files on all cores, up virtual mem for PCH's as cotire really
  723. # makes the compiler scream.
  724. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /Zm193")
  725. add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  726. endif()
  727. if (UNIX AND $ENV{COVERAGE}==1) # Coverage options (disables optimization)
  728. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0") # debug, no optimisation
  729. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") # enabling coverage
  730. endif()
  731. # Prefer target-level compile definitions and options below (kept conservative).
  732. # Generate libvgears.
  733. if(NOT VGEARS_SOURCE_FILES)
  734. file(GLOB_RECURSE VGEARS_SOURCE_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cpp")
  735. list(LENGTH VGEARS_SOURCE_FILES _vgears_auto_count)
  736. message(STATUS "Auto-collected VGEARS_SOURCE_FILES count: ${_vgears_auto_count}")
  737. endif()
  738. # If installer is disabled, remove installer sources from the collected list
  739. if(NOT BUILD_INSTALLER)
  740. set(_removed_count 0)
  741. foreach(_f IN LISTS VGEARS_SOURCE_FILES)
  742. if(_f MATCHES "installer/")
  743. list(REMOVE_ITEM VGEARS_SOURCE_FILES ${_f})
  744. math(EXPR _removed_count "${_removed_count} + 1")
  745. endif()
  746. endforeach()
  747. if(_removed_count GREATER 0)
  748. message(STATUS "Removed ${_removed_count} installer source(s) because BUILD_INSTALLER=OFF")
  749. endif()
  750. endif()
  751. # Conservative global Qt include probe (ensure headers visible when
  752. # generating libvgears target). Prefer distro qt5 include locations.
  753. set(_qt_global_candidates /usr/include/x86_64-linux-gnu/qt5 /usr/include/qt5 /usr/include)
  754. foreach(_qinc IN LISTS _qt_global_candidates)
  755. if(EXISTS "${_qinc}/QtCore/QtGlobal")
  756. message(STATUS "Global probe: adding Qt include directory ${_qinc}")
  757. include_directories(BEFORE PRIVATE ${_qinc})
  758. break()
  759. endif()
  760. endforeach()
  761. # Ensure UI headers generated by uic are available before compiling
  762. # libvgears. Some build order setups (unity/PCH/cotire) may attempt to
  763. # compile sources that include generated `ui_*.h` before uic runs, so add
  764. # an explicit custom command/target to generate the header.
  765. set(_ui_src "${CMAKE_CURRENT_SOURCE_DIR}/installer/MainWindow.ui")
  766. # Place generated headers under the build tree parallel to the source dir
  767. # CMAKE_CURRENT_BINARY_DIR is <build>/src so append 'installer' (not
  768. # 'src/installer').
  769. set(_ui_out "${CMAKE_CURRENT_BINARY_DIR}/installer/ui_MainWindow.h")
  770. find_program(QT_UIC_EXECUTABLE NAMES uic uic-qt5 PATHS /usr/lib/qt5/bin /usr/bin /usr/local/bin)
  771. if(QT_UIC_EXECUTABLE AND EXISTS "${_ui_src}")
  772. add_custom_command(
  773. OUTPUT "${_ui_out}"
  774. COMMAND ${QT_UIC_EXECUTABLE} -o "${_ui_out}" "${_ui_src}"
  775. DEPENDS "${_ui_src}"
  776. COMMENT "Generating ui_MainWindow.h via uic"
  777. VERBATIM
  778. )
  779. add_custom_target(generate_ui_files DEPENDS "${_ui_out}")
  780. set(_GENERATED_UI_TARGET generate_ui_files)
  781. endif()
  782. # Exclude unit tests under installer/decompiler/test from the main
  783. # library to avoid pulling test-only dependencies (gtest/gmock).
  784. set(_test_removed_count 0)
  785. foreach(_f IN LISTS VGEARS_SOURCE_FILES)
  786. if(_f MATCHES "installer/decompiler/test/")
  787. list(REMOVE_ITEM VGEARS_SOURCE_FILES ${_f})
  788. math(EXPR _test_removed_count "${_test_removed_count} + 1")
  789. endif()
  790. endforeach()
  791. if(_test_removed_count GREATER 0)
  792. message(STATUS "Removed ${_test_removed_count} decompiler test source(s) from libvgears")
  793. endif()
  794. # Directory with the system's Ogre plugins (RenderSystem_GL, Codec_STBI...). V-Gears looks for the plugins listed in
  795. # plugins.cfg there after the data directory and the directory of the executable (see common/OgrePlugins.h).
  796. # Packagers can set it, for example -DVGEARS_OGRE_PLUGIN_DIR=/usr/lib/x86_64-linux-gnu/OGRE.
  797. set(_vgears_default_plugin_dir "")
  798. if(OGRE_PLUGIN_DIR)
  799. set(_vgears_default_plugin_dir "${OGRE_PLUGIN_DIR}")
  800. elseif(PKG_CONFIG_FOUND)
  801. pkg_get_variable(_vgears_default_plugin_dir OGRE plugindir)
  802. endif()
  803. set(VGEARS_OGRE_PLUGIN_DIR "${_vgears_default_plugin_dir}" CACHE PATH "Directory of the Ogre plugins")
  804. message(STATUS "Ogre plugin directory: ${VGEARS_OGRE_PLUGIN_DIR}")
  805. add_library(libvgears STATIC ${VGEARS_SOURCE_FILES})
  806. target_sources(libvgears PRIVATE installer/SfxDump.c)
  807. # Ensure generated ui headers are created before compiling libvgears
  808. if(DEFINED _GENERATED_UI_TARGET)
  809. add_dependencies(libvgears ${_GENERATED_UI_TARGET})
  810. # Generated ui headers live in <build>/src/installer
  811. target_include_directories(libvgears PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/installer")
  812. endif()
  813. # Ensure platform macro for scummsys.h selection on Unix
  814. if(UNIX)
  815. target_compile_definitions(libvgears PRIVATE POSIX)
  816. endif()
  817. if(USE_COTIRE)
  818. cotire(libvgears)
  819. endif()
  820. SET_PROPERTY(TARGET libvgears PROPERTY FOLDER "build/libvgears")
  821. # Attach include directories and compile definitions to `libvgears` target.
  822. target_include_directories(libvgears
  823. PUBLIC
  824. ${VGEARS_SOURCE_DIR}
  825. ${CMAKE_CURRENT_SOURCE_DIR}
  826. ${CMAKE_CURRENT_SOURCE_DIR}/installer
  827. ${CMAKE_CURRENT_BINARY_DIR}/installer
  828. ${Boost_INCLUDE_DIR}
  829. ${OIS_INCLUDE_DIRS}
  830. ${OGRE_INCLUDE_DIRS}
  831. ${OGRE_INCLUDE_DIRS}/Overlay
  832. ${OGRE_INCLUDE_DIRS}/Bites
  833. ${VGEARS_LUAJIT_INCLUDE_DIRS}
  834. ${QT_INCLUDE_DIRS}
  835. )
  836. if(DEFINED _GENERATED_UI_TARGET)
  837. target_include_directories(libvgears BEFORE PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/installer")
  838. endif()
  839. target_link_libraries(libvgears PUBLIC ${VGEARS_LUAJIT_LIBRARIES})
  840. target_compile_definitions(libvgears PUBLIC TIXML_USE_STL)
  841. target_compile_definitions(libvgears PUBLIC VGEARS_OGRE_PLUGIN_DIR="${VGEARS_OGRE_PLUGIN_DIR}")
  842. if(NOT MSVC)
  843. target_compile_options(libvgears PRIVATE -fPIC)
  844. endif()
  845. # If Qt link libraries were detected (imported targets or fallback libs), link
  846. # them to libvgears so imported-target include directories are propagated to
  847. # installer/source compilation. This ensures Qt headers are available when
  848. # compiling installer sources into the static lib.
  849. if(QT_LINK_LIBS)
  850. message(STATUS "Linking libvgears with Qt libraries: ${QT_LINK_LIBS}")
  851. target_link_libraries(libvgears PUBLIC ${QT_LINK_LIBS})
  852. endif()
  853. # If QT_LINK_LIBS were provided but QT_INCLUDE_DIRS ended up empty (for example
  854. # when generic -l flags were injected), try a conservative probe for common Qt
  855. # include locations and attach them to the target so compiler `-I` flags are
  856. # present when building installer sources.
  857. if(QT_LINK_LIBS AND (NOT QT_INCLUDE_DIRS))
  858. set(_qt_probe_candidates /usr/include/qt5 /usr/include/x86_64-linux-gnu/qt5 /usr/include)
  859. foreach(_qi IN LISTS _qt_probe_candidates)
  860. if(EXISTS "${_qi}/QtCore/QtGlobal")
  861. message(STATUS "Detected Qt headers under ${_qi}; setting QT_INCLUDE_DIRS")
  862. set(QT_INCLUDE_DIRS ${_qi} CACHE PATH "Detected Qt include dir" FORCE)
  863. break()
  864. endif()
  865. endforeach()
  866. endif()
  867. if(QT_INCLUDE_DIRS)
  868. message(STATUS "Adding Qt include dirs to libvgears: ${QT_INCLUDE_DIRS}")
  869. target_include_directories(libvgears PUBLIC ${QT_INCLUDE_DIRS})
  870. endif()
  871. # Generate v-gears executable
  872. # Ensure installer sources are not compiled into the main executable; the
  873. # installer is built separately under `src/installer`. Remove any installer
  874. # sources from the source list used for the `v-gears` executable.
  875. foreach(_f IN LISTS VGEARS_SOURCE_FILES)
  876. if(_f MATCHES "^installer/")
  877. list(REMOVE_ITEM VGEARS_SOURCE_FILES ${_f})
  878. endif()
  879. endforeach()
  880. add_executable(v-gears ${VGEARS_SOURCE_FILES})
  881. SET_PROPERTY(TARGET v-gears PROPERTY FOLDER "build/v-gears")
  882. if(APPLE)
  883. target_link_libraries(v-gears "-framework CoreFoundation -framework Cocoa -framework IOKit" ${ois_lib})
  884. endif()
  885. if(WIN32 AND NOT (CMAKE_BUILD_TYPE MATCHES "Debug"))
  886. set_target_properties( v-gears PROPERTIES WIN32_EXECUTABLE ON )
  887. if (MSVC)
  888. set_target_properties(v-gears PROPERTIES LINK_FLAGS "/SUBSYSTEM:CONSOLE")
  889. endif()
  890. endif()
  891. set(VGEARS_LIBRARIES
  892. ${VGEARS_LUAJIT_LIBRARIES}
  893. ${OPENAL_LIBRARY}
  894. ${OGGVORBIS_LIBRARIES}
  895. ${OGRE_LIBRARIES}
  896. )
  897. # Boost 1.70 and newer ship CMake config files that create the Boost::<component> targets. Use them if the search
  898. # above found nothing. Note that, outside MinGW, that search doesn't run: the if(MINGW) block near the top of this file
  899. # is never closed where it should be, and it covers all the library detection down to the source list.
  900. # Boost.System and Boost.Chrono are optional: System is header-only in recent versions.
  901. if(NOT BOOST_LINK_LIBS)
  902. find_package(Boost CONFIG QUIET COMPONENTS program_options filesystem thread OPTIONAL_COMPONENTS system chrono)
  903. foreach(_comp IN ITEMS program_options filesystem thread system chrono)
  904. if(TARGET Boost::${_comp})
  905. list(APPEND BOOST_LINK_LIBS Boost::${_comp})
  906. endif()
  907. endforeach()
  908. if(BOOST_LINK_LIBS)
  909. message(STATUS "Found Boost ${Boost_VERSION} (CMake config): ${BOOST_LINK_LIBS}")
  910. endif()
  911. endif()
  912. # Ensure we have something for Boost; if BOOST_LINK_LIBS is empty, inject
  913. # generic `-lboost_*` flags directly so the system linker will attempt to
  914. # resolve them from standard library search paths.
  915. if(NOT BOOST_LINK_LIBS)
  916. if(USE_DETERMINISTIC_FALLBACKS)
  917. find_library(_boost_system_lib
  918. NAMES boost_system libboost_system
  919. HINTS /usr/lib /usr/lib/x86_64-linux-gnu /usr/local/lib
  920. PATH_SUFFIXES . lib lib64
  921. )
  922. set(_generic_boost_flags -lboost_program_options -lboost_filesystem -lboost_thread -lboost_chrono)
  923. if(_boost_system_lib)
  924. list(APPEND _generic_boost_flags -lboost_system)
  925. endif()
  926. set(BOOST_LINK_LIBS ${_generic_boost_flags})
  927. message(STATUS "Injecting generic Boost -l flags into link list: ${_generic_boost_flags}")
  928. else()
  929. message(WARNING "Boost not found and deterministic fallbacks disabled; build may fail. Install libboost-*-dev or provide Boost hints.")
  930. endif()
  931. endif()
  932. # `BOOST_LINK_LIBS` should have been computed earlier (imported targets,
  933. # find_package, or the robust per-component fallback). Append whatever was found
  934. # into the final link list for the executable.
  935. list(APPEND VGEARS_LIBRARIES ${BOOST_LINK_LIBS} ${OIS_LIBRARIES} ${TinyXML_LIBRARIES})
  936. if(QT_LINK_LIBS)
  937. list(APPEND VGEARS_LIBRARIES ${QT_LINK_LIBS})
  938. endif()
  939. message(STATUS "Resolved library variables:")
  940. message(STATUS " OPENAL_LIBRARY=${OPENAL_LIBRARY}")
  941. message(STATUS " OGGVORBIS_LIBRARIES=${OGGVORBIS_LIBRARIES}")
  942. message(STATUS " OGRE_LIBRARIES=${OGRE_LIBRARIES}")
  943. message(STATUS " Boost_LIBRARIES=${Boost_LIBRARIES}")
  944. message(STATUS " OIS_LIBRARIES=${OIS_LIBRARIES}")
  945. message(STATUS " TinyXML_LIBRARIES=${TinyXML_LIBRARIES}")
  946. if(MULTITHREADING)
  947. find_package (Threads REQUIRED) # Find Threads
  948. set(VGEARS_LIBRARIES
  949. ${VGEARS_LIBRARIES}
  950. ${CMAKE_THREAD_LIBS_INIT}
  951. )
  952. endif()
  953. message(STATUS "Final VGEARS_LIBRARIES list: ${VGEARS_LIBRARIES}")
  954. # If OgreBites SONAME exists on the system but wasn't picked up earlier, append
  955. # it directly to the final link list so WindowEventUtilities symbols are
  956. #resolved at link time.
  957. if(USE_DETERMINISTIC_FALLBACKS)
  958. if(EXISTS "/usr/lib/x86_64-linux-gnu/libOgreBites.so")
  959. list(FIND VGEARS_LIBRARIES "/usr/lib/x86_64-linux-gnu/libOgreBites.so" _found_bites)
  960. if(_found_bites EQUAL -1)
  961. list(APPEND VGEARS_LIBRARIES "/usr/lib/x86_64-linux-gnu/libOgreBites.so")
  962. message(STATUS "Appending system OgreBites to VGEARS_LIBRARIES: /usr/lib/x86_64-linux-gnu/libOgreBites.so")
  963. endif()
  964. endif()
  965. else()
  966. # When deterministic fallbacks are disabled, warn if OgreBites is likely
  967. # missing.
  968. if(NOT OGRE_LIBRARIES MATCHES ".*OgreBites.*")
  969. message(WARNING "OgreBites not present in OGRE_LIBRARIES and deterministic fallbacks are disabled. Link errors may occur if OGRE dev packages are not installed.")
  970. endif()
  971. endif()
  972. target_link_libraries(v-gears ${VGEARS_LIBRARIES})
  973. # Attach include dirs/defs/options to executable as well (uses same sources).
  974. target_include_directories(v-gears
  975. PRIVATE
  976. ${VGEARS_SOURCE_DIR}
  977. ${CMAKE_CURRENT_SOURCE_DIR}
  978. ${CMAKE_CURRENT_SOURCE_DIR}/installer
  979. ${CMAKE_CURRENT_BINARY_DIR}/installer
  980. ${Boost_INCLUDE_DIR}
  981. ${OIS_INCLUDE_DIRS}
  982. ${OGRE_INCLUDE_DIRS}
  983. ${OGRE_INCLUDE_DIRS}/Overlay
  984. ${OGRE_INCLUDE_DIRS}/Bites
  985. ${VGEARS_LUAJIT_INCLUDE_DIRS}
  986. ${QT_INCLUDE_DIRS}
  987. )
  988. # If UI files are generated by the uic custom target, make sure the executable
  989. # depends on it and can see the generated headers.
  990. if(DEFINED _GENERATED_UI_TARGET)
  991. add_dependencies(v-gears ${_GENERATED_UI_TARGET})
  992. target_include_directories(v-gears PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/installer")
  993. endif()
  994. # Ensure platform macro for scummsys.h selection on Unix when building the main
  995. # executable as well (same as done for libvgears).
  996. if(UNIX)
  997. target_compile_definitions(v-gears PRIVATE POSIX)
  998. endif()
  999. target_compile_definitions(v-gears PRIVATE TIXML_USE_STL)
  1000. target_compile_definitions(v-gears PRIVATE VGEARS_OGRE_PLUGIN_DIR="${VGEARS_OGRE_PLUGIN_DIR}")
  1001. if(NOT MSVC)
  1002. target_compile_options(v-gears PRIVATE -fPIC)
  1003. endif()
  1004. # Install v-gears (see CMake/InstallDirs.cmake).
  1005. install(TARGETS v-gears RUNTIME DESTINATION ${VGEARS_INSTALL_BINDIR} BUNDLE DESTINATION ${VGEARS_INSTALL_BINDIR})
  1006. # If installer build is enabled, ensure Qt includes/links are available for the
  1007. # `installer` subdirectory. Do this before adding the subdirectory so its
  1008. # targets inherit the settings.
  1009. if(BUILD_INSTALLER)
  1010. # If pragmatic detection earlier set `QT_INCLUDE_DIRS`, expose them as
  1011. # global include dirs so installer targets find headers.
  1012. if(QT_INCLUDE_DIRS)
  1013. include_directories(${QT_INCLUDE_DIRS})
  1014. else()
  1015. # Last-resort add common system Qt include paths.
  1016. if(EXISTS "/usr/include/qt5/QtCore/QDir")
  1017. include_directories(/usr/include/qt5 /usr/include/x86_64-linux-gnu/qt5)
  1018. message(STATUS "Added generic Qt include paths: /usr/include/qt5")
  1019. endif()
  1020. endif()
  1021. # Make sure any QT_LINK_LIBS are visible to subdirectories by appending
  1022. # them to the global link list variable used when creating targets.
  1023. if(QT_LINK_LIBS)
  1024. list(APPEND VGEARS_LIBRARIES ${QT_LINK_LIBS})
  1025. endif()
  1026. message(STATUS "Building installer as requested (BUILD_INSTALLER=ON)")
  1027. add_subdirectory(installer)
  1028. endif()