UrhoCommon.cmake 117 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974
  1. #
  2. # Copyright (c) 2008-2017 the Urho3D project.
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining a copy
  5. # of this software and associated documentation files (the "Software"), to deal
  6. # in the Software without restriction, including without limitation the rights
  7. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. # copies of the Software, and to permit persons to whom the Software is
  9. # furnished to do so, subject to the following conditions:
  10. #
  11. # The above copyright notice and this permission notice shall be included in
  12. # all copies or substantial portions of the Software.
  13. #
  14. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. # THE SOFTWARE.
  21. #
  22. # Save the initial values of CC and CXX environment variables
  23. if (NOT CMAKE_CROSSCOMPILING)
  24. set (SAVED_CC $ENV{CC} CACHE INTERNAL "Initial value for CC")
  25. set (SAVED_CXX $ENV{CXX} CACHE INTERNAL "Initial value for CXX")
  26. endif ()
  27. # Limit the supported build configurations
  28. set (URHO3D_BUILD_CONFIGURATIONS Release RelWithDebInfo Debug)
  29. set (DOC_STRING "Specify CMake build configuration (single-configuration generator only), possible values are Release (default), RelWithDebInfo, and Debug")
  30. if (CMAKE_CONFIGURATION_TYPES)
  31. # For multi-configurations generator, such as VS and Xcode
  32. set (CMAKE_CONFIGURATION_TYPES ${URHO3D_BUILD_CONFIGURATIONS} CACHE STRING ${DOC_STRING} FORCE)
  33. unset (CMAKE_BUILD_TYPE)
  34. else ()
  35. # For single-configuration generator, such as Unix Makefile generator
  36. if (CMAKE_BUILD_TYPE STREQUAL "")
  37. # If not specified then default to Release
  38. set (CMAKE_BUILD_TYPE Release)
  39. endif ()
  40. set (CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING ${DOC_STRING} FORCE)
  41. endif ()
  42. # Define other useful variables not defined by CMake
  43. if (CMAKE_GENERATOR STREQUAL Xcode)
  44. set (XCODE TRUE)
  45. elseif (CMAKE_GENERATOR STREQUAL Ninja)
  46. set (NINJA TRUE)
  47. elseif (CMAKE_GENERATOR MATCHES Visual)
  48. set (VS TRUE)
  49. endif ()
  50. # Rightfully we could have performed this inside a CMake/iOS toolchain file but we don't have one nor need for one for now
  51. if (IOS)
  52. set (CMAKE_CROSSCOMPILING TRUE)
  53. set (CMAKE_XCODE_EFFECTIVE_PLATFORMS -iphoneos -iphonesimulator)
  54. set (CMAKE_OSX_SYSROOT iphoneos) # Set Base SDK to "Latest iOS"
  55. # This is a CMake hack in order to make standard CMake check modules that use try_compile() internally work on iOS platform
  56. # The injected "flags" are not compiler flags, they are actually CMake variables meant for another CMake subprocess that builds the source file being passed in the try_compile() command
  57. # CAVEAT: these injected "flags" must always be kept at the end of the string variable, i.e. when adding more compiler flags later on then those new flags must be prepended in front of these flags instead
  58. set (CMAKE_REQUIRED_FLAGS ";-DSmileyHack=byYaoWT;-DCMAKE_MACOSX_BUNDLE=1;-DCMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED=0;-DCMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY=")
  59. if (NOT IOS_SYSROOT)
  60. execute_process (COMMAND xcodebuild -version -sdk ${CMAKE_OSX_SYSROOT} Path OUTPUT_VARIABLE IOS_SYSROOT OUTPUT_STRIP_TRAILING_WHITESPACE) # Obtain iOS sysroot path
  61. set (IOS_SYSROOT ${IOS_SYSROOT} CACHE INTERNAL "Path to iOS system root")
  62. endif ()
  63. set (CMAKE_FIND_ROOT_PATH ${IOS_SYSROOT})
  64. set (IPHONEOS_DEPLOYMENT_TARGET "" CACHE STRING "Specify iOS deployment target (iOS platform only); default to latest installed iOS SDK if not specified, the minimum supported target is 3.0 due to constraint from SDL library")
  65. if (DEPLOYMENT_TARGET_SAVED AND NOT ${IPHONEOS_DEPLOYMENT_TARGET}: STREQUAL DEPLOYMENT_TARGET_SAVED)
  66. string (REPLACE : "" DEPLOYMENT_TARGET_SAVED ${DEPLOYMENT_TARGET_SAVED})
  67. set (IPHONEOS_DEPLOYMENT_TARGET "${DEPLOYMENT_TARGET_SAVED}" CACHE STRING "Specify iOS deployment target (iOS platform only); default to latest installed iOS SDK if not specified, the minimum supported target is 3.0 due to constraint from SDL library" FORCE)
  68. message (FATAL_ERROR "IPHONEOS_DEPLOYMENT_TARGET cannot be changed after the initial configuration/generation. "
  69. "Auto reverting to its initial value. If you wish to change it then the build tree would have to be regenerated from scratch.")
  70. endif ()
  71. set (CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET ${IPHONEOS_DEPLOYMENT_TARGET})
  72. set (DEPLOYMENT_TARGET_SAVED ${IPHONEOS_DEPLOYMENT_TARGET}: CACHE INTERNAL "Last known deployment target") # with sentinel so it does not appear empty even when the default target is used
  73. set (CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES)
  74. # Workaround what appears to be a bug in CMake/Xcode generator, ensure the CMAKE_OSX_DEPLOYMENT_TARGET is set to empty for iOS build
  75. set (CMAKE_OSX_DEPLOYMENT_TARGET)
  76. unset (CMAKE_OSX_DEPLOYMENT_TARGET CACHE)
  77. elseif (TVOS)
  78. set (CMAKE_CROSSCOMPILING TRUE)
  79. set (CMAKE_XCODE_EFFECTIVE_PLATFORMS -appletvos -appletvsimulator)
  80. set (CMAKE_OSX_SYSROOT appletvos) # Set Base SDK to "Latest tvOS"
  81. set (CMAKE_REQUIRED_FLAGS ";-DSmileyHack=byYaoWT;-DCMAKE_MACOSX_BUNDLE=1;-DCMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED=0;-DCMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY=")
  82. if (NOT TVOS_SYSROOT)
  83. execute_process (COMMAND xcodebuild -version -sdk ${CMAKE_OSX_SYSROOT} Path OUTPUT_VARIABLE TVOS_SYSROOT OUTPUT_STRIP_TRAILING_WHITESPACE) # Obtain tvOS sysroot path
  84. set (TVOS_SYSROOT ${TVOS_SYSROOT} CACHE INTERNAL "Path to tvOS system root")
  85. endif ()
  86. set (CMAKE_FIND_ROOT_PATH ${TVOS_SYSROOT})
  87. set (APPLETVOS_DEPLOYMENT_TARGET "" CACHE STRING "Specify tvOS deployment target (tvOS platform only); default to latest installed tvOS SDK if not specified")
  88. set (CMAKE_XCODE_ATTRIBUTE_APPLETVOS_DEPLOYMENT_TARGET ${APPLETVOS_DEPLOYMENT_TARGET})
  89. set (CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES)
  90. # Just in case it has similar bug for tvOS build
  91. set (CMAKE_OSX_DEPLOYMENT_TARGET)
  92. unset (CMAKE_OSX_DEPLOYMENT_TARGET CACHE)
  93. elseif (XCODE)
  94. set (CMAKE_OSX_SYSROOT macosx) # Set Base SDK to "Latest OS X"
  95. if (NOT CMAKE_OSX_DEPLOYMENT_TARGET)
  96. # If not set, set to current running build system OS version by default
  97. execute_process (COMMAND sw_vers -productVersion OUTPUT_VARIABLE CURRENT_OSX_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
  98. string (REGEX REPLACE ^\([^.]+\\.[^.]+\).* \\1 CMAKE_OSX_DEPLOYMENT_TARGET ${CURRENT_OSX_VERSION})
  99. set (CMAKE_OSX_DEPLOYMENT_TARGET ${CMAKE_OSX_DEPLOYMENT_TARGET} CACHE STRING "Specify macOS deployment target (macOS platform only); default to current running macOS if not specified, the minimum supported target is 10.5 due to constraint from SDL library")
  100. endif ()
  101. if (DEPLOYMENT_TARGET_SAVED AND NOT CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL DEPLOYMENT_TARGET_SAVED)
  102. set (CMAKE_OSX_DEPLOYMENT_TARGET ${DEPLOYMENT_TARGET_SAVED} CACHE STRING "Specify macOS deployment target (macOS platform only); default to current running macOS if not specified, the minimum supported target is 10.5 due to constraint from SDL library" FORCE)
  103. message (FATAL_ERROR "CMAKE_OSX_DEPLOYMENT_TARGET cannot be changed after the initial configuration/generation. "
  104. "Auto reverting to its initial value. If you wish to change it then the build tree would have to be regenerated from scratch.")
  105. endif ()
  106. set (DEPLOYMENT_TARGET_SAVED ${CMAKE_OSX_DEPLOYMENT_TARGET} CACHE INTERNAL "Last known deployment target")
  107. endif ()
  108. include (CheckHost)
  109. include (CheckCompilerToolchain)
  110. # Extra linker flags for linking against indirect dependencies (linking shared lib with dependencies)
  111. if (RPI)
  112. # Extra linker flags for Raspbian because it installs VideoCore libraries in the "/opt/vc/lib" directory (no harm in doing so for other distros)
  113. set (INDIRECT_DEPS_EXE_LINKER_FLAGS "${INDIRECT_DEPS_EXE_LINKER_FLAGS} -Wl,-rpath-link,\"${CMAKE_SYSROOT}/opt/vc/lib\"") # CMAKE_SYSROOT is empty when not cross-compiling
  114. elseif (APPLE AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0.0)
  115. set (INDIRECT_DEPS_EXE_LINKER_FLAGS "${INDIRECT_DEPS_EXE_LINKER_FLAGS} -Wl,-no_weak_imports")
  116. endif ()
  117. if (ARM AND CMAKE_SYSTEM_NAME STREQUAL Linux AND CMAKE_CROSSCOMPILING)
  118. # Cannot do this in the toolchain file because CMAKE_LIBRARY_ARCHITECTURE is not yet defined when CMake is processing toolchain file
  119. set (INDIRECT_DEPS_EXE_LINKER_FLAGS "${INDIRECT_DEPS_EXE_LINKER_FLAGS} -Wl,-rpath-link,\"${CMAKE_SYSROOT}/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}\":\"${CMAKE_SYSROOT}/lib/${CMAKE_LIBRARY_ARCHITECTURE}\"")
  120. endif ()
  121. set (CMAKE_REQUIRED_FLAGS "${INDIRECT_DEPS_EXE_LINKER_FLAGS} ${CMAKE_REQUIRED_FLAGS}")
  122. set (CMAKE_EXE_LINKER_FLAGS "${INDIRECT_DEPS_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}")
  123. # Define all supported build options
  124. include (CMakeDependentOption)
  125. cmake_dependent_option (IOS "Setup build for iOS platform" FALSE "XCODE" FALSE)
  126. cmake_dependent_option (TVOS "Setup build for tvOS platform" FALSE "XCODE" FALSE)
  127. cmake_dependent_option (URHO3D_64BIT "Enable 64-bit build, the default is set based on the native ABI of the chosen compiler toolchain" "${NATIVE_64BIT}" "NOT MSVC AND NOT ANDROID AND NOT (ARM AND NOT IOS) AND NOT WEB AND NOT POWERPC" "${NATIVE_64BIT}") # Intentionally only enable the option for iOS but not for tvOS as the latter is 64-bit only
  128. option (URHO3D_ANGELSCRIPT "Enable AngelScript scripting support" TRUE)
  129. option (URHO3D_IK "Enable inverse kinematics support" TRUE)
  130. option (URHO3D_LUA "Enable additional Lua scripting support" TRUE)
  131. option (URHO3D_NAVIGATION "Enable navigation support" TRUE)
  132. # Urho's Network subsystem depends on kNet library which uses C++ exceptions feature
  133. cmake_dependent_option (URHO3D_NETWORK "Enable networking support" TRUE "NOT WEB AND EXCEPTIONS" FALSE)
  134. option (URHO3D_PHYSICS "Enable physics support" TRUE)
  135. option (URHO3D_URHO2D "Enable 2D graphics and physics support" TRUE)
  136. option (URHO3D_WEBP "Enable WebP support" TRUE)
  137. if (ARM AND NOT ANDROID AND NOT RPI AND NOT APPLE)
  138. set (ARM_ABI_FLAGS "" CACHE STRING "Specify ABI compiler flags (ARM on Linux platform only); e.g. Orange-Pi Mini 2 could use '-mcpu=cortex-a7 -mfpu=neon-vfpv4'")
  139. endif ()
  140. if ((RPI AND "${RPI_ABI}" MATCHES NEON) OR (ARM AND (APPLE OR URHO3D_64BIT OR "${ARM_ABI_FLAGS}" MATCHES neon))) # Stringify in case RPI_ABI/ARM_ABI_FLAGS is not set explicitly
  141. # TODO: remove this logic when the compiler flags are set in each toolchain file, such that the CheckCompilerToolchain can perform the check automatically
  142. set (NEON 1)
  143. endif ()
  144. # For Raspbery Pi, find Broadcom VideoCore IV firmware
  145. if (RPI)
  146. # TODO: this logic is earmarked to be moved into SDL's CMakeLists.txt when refactoring the library dependency handling
  147. find_package (VideoCore REQUIRED)
  148. include_directories (SYSTEM ${VIDEOCORE_INCLUDE_DIRS})
  149. link_directories (${VIDEOCORE_LIBRARY_DIRS})
  150. endif ()
  151. if (CMAKE_PROJECT_NAME STREQUAL Urho3D)
  152. set (URHO3D_LIB_TYPE STATIC CACHE STRING "Specify Urho3D library type, possible values are STATIC (default), SHARED, and MODULE; the last value is available for Emscripten only")
  153. # Non-Windows platforms always use OpenGL, the URHO3D_OPENGL variable will always be forced to TRUE, i.e. it is not an option at all
  154. # Windows platform has URHO3D_OPENGL as an option, MSVC compiler default to FALSE (i.e. prefers Direct3D) while MinGW compiler default to TRUE
  155. if (MINGW)
  156. set (DEFAULT_OPENGL TRUE)
  157. endif ()
  158. cmake_dependent_option (URHO3D_OPENGL "Use OpenGL instead of Direct3D (Windows platform only)" "${DEFAULT_OPENGL}" WIN32 TRUE)
  159. # On Windows platform Direct3D11 can be optionally chosen
  160. # Using Direct3D11 on non-MSVC compiler may require copying and renaming Microsoft official libraries (.lib to .a), else link failures or non-functioning graphics may result
  161. cmake_dependent_option (URHO3D_D3D11 "Use Direct3D11 instead of Direct3D9 (Windows platform only); overrides URHO3D_OPENGL option" FALSE "WIN32" FALSE)
  162. if (MINGW AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.1)
  163. if (NOT DEFINED URHO3D_SSE) # Only give the warning once during initial configuration
  164. # Certain MinGW versions fail to compile SSE code. This is the initial guess for known "bad" version range, and can be tightened later
  165. message (WARNING "Disabling SSE by default due to MinGW version. It is recommended to upgrade to MinGW with GCC >= 4.9.1. "
  166. "You can also try to re-enable SSE with CMake option -DURHO3D_SSE=1, but this may result in compile errors.")
  167. set (HAVE_SSE2 FALSE)
  168. endif ()
  169. endif ()
  170. if (X86 OR WEB)
  171. # It is not possible to turn SSE off on 64-bit MSVC and it appears it is also not able to do so safely on 64-bit GCC
  172. cmake_dependent_option (URHO3D_SSE "Enable SSE/SSE2 instruction set (32-bit Web and Intel platforms only, including Android on Intel Atom); default to true on Intel and false on Web platform; the effective SSE level could be higher, see also URHO3D_DEPLOYMENT_TARGET and CMAKE_OSX_DEPLOYMENT_TARGET build options" "${HAVE_SSE2}" "NOT URHO3D_64BIT" TRUE)
  173. endif ()
  174. cmake_dependent_option (URHO3D_3DNOW "Enable 3DNow! instruction set (Linux platform only); should only be used for older CPU with (legacy) 3DNow! support" "${HAVE_3DNOW}" "X86 AND CMAKE_SYSTEM_NAME STREQUAL Linux AND NOT URHO3D_SSE" FALSE)
  175. cmake_dependent_option (URHO3D_MMX "Enable MMX instruction set (32-bit Linux platform only); the MMX is effectively enabled when 3DNow! or SSE is enabled; should only be used for older CPU with MMX support" "${HAVE_MMX}" "X86 AND CMAKE_SYSTEM_NAME STREQUAL Linux AND NOT URHO3D_64BIT AND NOT URHO3D_SSE AND NOT URHO3D_3DNOW" FALSE)
  176. # For completeness sake - this option is intentionally not documented as we do not officially support PowerPC (yet)
  177. cmake_dependent_option (URHO3D_ALTIVEC "Enable AltiVec instruction set (PowerPC only)" "${HAVE_ALTIVEC}" POWERPC FALSE)
  178. cmake_dependent_option (URHO3D_LUAJIT "Enable Lua scripting support using LuaJIT (check LuaJIT's CMakeLists.txt for more options)" FALSE "NOT WEB" FALSE)
  179. cmake_dependent_option (URHO3D_LUAJIT_AMALG "Enable LuaJIT amalgamated build (LuaJIT only)" FALSE URHO3D_LUAJIT FALSE)
  180. cmake_dependent_option (URHO3D_SAFE_LUA "Enable Lua C++ wrapper safety checks (Lua/LuaJIT only)" FALSE URHO3D_LUA FALSE)
  181. if (NOT CMAKE_BUILD_TYPE STREQUAL Release AND NOT CMAKE_CONFIGURATION_TYPES)
  182. set (DEFAULT_LUA_RAW TRUE)
  183. endif ()
  184. cmake_dependent_option (URHO3D_LUA_RAW_SCRIPT_LOADER "Prefer loading raw script files from the file system before falling back on Urho3D resource cache. Useful for debugging (e.g. breakpoints), but less performant (Lua/LuaJIT only)" "${DEFAULT_LUA_RAW}" URHO3D_LUA FALSE)
  185. option (URHO3D_SAMPLES "Build sample applications" TRUE)
  186. option (URHO3D_UPDATE_SOURCE_TREE "Enable commands to copy back some of the generated build artifacts from build tree to source tree to facilitate devs to push them as part of a commit (for library devs with push right only)")
  187. option (URHO3D_BINDINGS "Enable API binding generation support for script subystems")
  188. cmake_dependent_option (URHO3D_CLANG_TOOLS "Build Clang tools (native on host system only)" FALSE "NOT CMAKE_CROSSCOMPILING" FALSE)
  189. mark_as_advanced (URHO3D_UPDATE_SOURCE_TREE URHO3D_BINDINGS URHO3D_CLANG_TOOLS)
  190. cmake_dependent_option (URHO3D_TOOLS "Build tools (native, RPI, and ARM on Linux only)" TRUE "NOT IOS AND NOT TVOS AND NOT ANDROID AND NOT WEB" FALSE)
  191. cmake_dependent_option (URHO3D_EXTRAS "Build extras (native, RPI, and ARM on Linux only)" FALSE "NOT IOS AND NOT TVOS AND NOT ANDROID AND NOT WEB" FALSE)
  192. option (URHO3D_DOCS "Generate documentation as part of normal build")
  193. option (URHO3D_DOCS_QUIET "Generate documentation as part of normal build, suppress generation process from sending anything to stdout")
  194. option (URHO3D_PCH "Enable PCH support" TRUE)
  195. cmake_dependent_option (URHO3D_DATABASE_ODBC "Enable Database support with ODBC, requires vendor-specific ODBC driver" FALSE "NOT IOS AND NOT TVOS AND NOT ANDROID AND NOT WEB;NOT MSVC OR NOT MSVC_VERSION VERSION_LESS 1900" FALSE)
  196. option (URHO3D_DATABASE_SQLITE "Enable Database support with SQLite embedded")
  197. # Enable file watcher support for automatic resource reloads by default.
  198. option (URHO3D_FILEWATCHER "Enable filewatcher support" TRUE)
  199. option (URHO3D_TESTING "Enable testing support")
  200. # By default this option is off (i.e. we use the MSVC dynamic runtime), this can be switched on if using Urho3D as a STATIC library
  201. cmake_dependent_option (URHO3D_STATIC_RUNTIME "Use static C/C++ runtime libraries and eliminate the need for runtime DLLs installation (VS only)" FALSE "MSVC" FALSE)
  202. if (((URHO3D_LUA AND NOT URHO3D_LUAJIT) OR URHO3D_DATABASE_SQLITE) AND NOT ANDROID AND NOT IOS AND NOT TVOS AND NOT WEB AND NOT WIN32)
  203. # Find GNU Readline development library for Lua interpreter and SQLite's isql
  204. find_package (Readline)
  205. endif ()
  206. if (CPACK_SYSTEM_NAME STREQUAL Linux)
  207. cmake_dependent_option (URHO3D_USE_LIB64_RPM "Enable 64-bit RPM CPack generator using /usr/lib64 and disable all other generators (Debian-based host only)" FALSE "URHO3D_64BIT AND NOT HAS_LIB64" FALSE)
  208. cmake_dependent_option (URHO3D_USE_LIB_DEB "Enable 64-bit DEB CPack generator using /usr/lib and disable all other generators (Redhat-based host only)" FALSE "URHO3D_64BIT AND HAS_LIB64" FALSE)
  209. endif ()
  210. # Set to search in 'lib' or 'lib64' based on the chosen ABI
  211. if (NOT CMAKE_HOST_WIN32)
  212. set_property (GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS ${URHO3D_64BIT})
  213. endif ()
  214. else ()
  215. set (URHO3D_LIB_TYPE "" CACHE STRING "Specify Urho3D library type, possible values are STATIC (default), SHARED, and MODULE; the last value is available for Emscripten only")
  216. set (URHO3D_HOME "" CACHE PATH "Path to Urho3D build tree or SDK installation location (downstream project only)")
  217. if (URHO3D_PCH OR URHO3D_UPDATE_SOURCE_TREE OR URHO3D_TOOLS)
  218. # Just reference it to suppress "unused variable" CMake warning on downstream projects using this CMake module
  219. endif ()
  220. if (CMAKE_PROJECT_NAME MATCHES ^Urho3D-ExternalProject-)
  221. set (URHO3D_SSE ${HAVE_SSE2})
  222. else ()
  223. # All Urho3D downstream projects require Urho3D library, so find Urho3D library here now
  224. find_package (Urho3D REQUIRED)
  225. include_directories (${URHO3D_INCLUDE_DIRS})
  226. endif ()
  227. endif ()
  228. cmake_dependent_option (URHO3D_PACKAGING "Enable resources packaging support" FALSE "NOT WEB" TRUE)
  229. # Enable profiling by default. If disabled, autoprofileblocks become no-ops and the Profiler subsystem is not instantiated.
  230. option (URHO3D_PROFILING "Enable profiling support" TRUE)
  231. # Enable logging by default. If disabled, LOGXXXX macros become no-ops and the Log subsystem is not instantiated.
  232. option (URHO3D_LOGGING "Enable logging support" TRUE)
  233. # Enable threading by default, except for Emscripten because its thread support is yet experimental
  234. if (NOT WEB)
  235. set (THREADING_DEFAULT TRUE)
  236. endif ()
  237. option (URHO3D_THREADING "Enable thread support, on Web platform default to 0, on other platforms default to 1" ${THREADING_DEFAULT})
  238. if (URHO3D_TESTING)
  239. if (WEB)
  240. set (DEFAULT_TIMEOUT 10)
  241. if (EMSCRIPTEN)
  242. set (EMSCRIPTEN_EMRUN_BROWSER firefox CACHE STRING "Specify the particular browser to be spawned by emrun during testing (Emscripten only), use 'emrun --list_browsers' command to get the list of possible values")
  243. endif ()
  244. else ()
  245. set (DEFAULT_TIMEOUT 5)
  246. endif ()
  247. set (URHO3D_TEST_TIMEOUT ${DEFAULT_TIMEOUT} CACHE STRING "Number of seconds to test run the executables (when testing support is enabled only), default to 10 on Web platform and 5 on other platforms")
  248. else ()
  249. unset (URHO3D_TEST_TIMEOUT CACHE)
  250. if (EMSCRIPTEN_EMRUN_BROWSER) # Suppress unused variable warning at the same time
  251. unset (EMSCRIPTEN_EMRUN_BROWSER CACHE)
  252. endif ()
  253. endif ()
  254. # Structured exception handling and minidumps on MSVC only
  255. cmake_dependent_option (URHO3D_MINIDUMPS "Enable minidumps on crash (VS only)" TRUE "MSVC" FALSE)
  256. # By default Windows platform setups main executable as Windows application with WinMain() as entry point
  257. cmake_dependent_option (URHO3D_WIN32_CONSOLE "Use console main() instead of WinMain() as entry point when setting up Windows executable targets (Windows platform only)" FALSE "WIN32" FALSE)
  258. cmake_dependent_option (URHO3D_MACOSX_BUNDLE "Use MACOSX_BUNDLE when setting up macOS executable targets (Xcode/macOS platform only)" FALSE "XCODE AND NOT ARM" FALSE)
  259. if (CMAKE_CROSSCOMPILING AND NOT ANDROID AND NOT APPLE)
  260. set (URHO3D_SCP_TO_TARGET "" CACHE STRING "Use scp to transfer executables to target system (RPI and generic ARM cross-compiling build only), SSH digital key must be setup first for this to work, typical value has a pattern of usr@tgt:remote-loc")
  261. else ()
  262. unset (URHO3D_SCP_TO_TARGET CACHE)
  263. endif ()
  264. if (ANDROID)
  265. set (ANDROID TRUE CACHE INTERNAL "Setup build for Android platform")
  266. cmake_dependent_option (ANDROID_NDK_GDB "Enable ndk-gdb for debugging (Android platform only)" FALSE "CMAKE_BUILD_TYPE STREQUAL Debug" FALSE)
  267. else ()
  268. unset (ANDROID_NDK_GDB CACHE)
  269. endif ()
  270. if (MINGW AND CMAKE_CROSSCOMPILING)
  271. set (MINGW_PREFIX "" CACHE STRING "Prefix path to MinGW cross-compiler tools (MinGW cross-compiling build only)")
  272. set (MINGW_SYSROOT "" CACHE PATH "Path to MinGW system root (MinGW only); should only be used when the system root could not be auto-detected")
  273. # When cross-compiling then we are most probably in Unix-alike host environment which should not have problem to handle long include dirs
  274. # This change is required to keep ccache happy because it does not like the CMake generated include response file
  275. foreach (lang C CXX)
  276. foreach (cat OBJECTS INCLUDES)
  277. unset (CMAKE_${lang}_USE_RESPONSE_FILE_FOR_${cat})
  278. endforeach ()
  279. endforeach ()
  280. endif ()
  281. if (RPI)
  282. if (NOT RPI_SUPPORTED_ABIS)
  283. set (RPI_SUPPORTED_ABIS armeabi-v6)
  284. if (CMAKE_CROSSCOMPILING)
  285. # We have no way to know for sure so just give all the available options to user
  286. list (APPEND RPI_SUPPORTED_ABIS armeabi-v7a "armeabi-v7a with NEON" "armeabi-v7a with VFPV4")
  287. else ()
  288. # If not cross-compiling then we should be on the host system (device) itself, so below command is safe to be executed
  289. execute_process (COMMAND uname -m OUTPUT_VARIABLE HOST_MACHINE ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
  290. if (HOST_MACHINE MATCHES ^armv7)
  291. list (APPEND RPI_SUPPORTED_ABIS armeabi-v7a "armeabi-v7a with NEON" "armeabi-v7a with VFPV4")
  292. if (NOT RPI_ABI)
  293. set (RPI_ABI armeabi-v7a) # Set default to this specific target device
  294. endif ()
  295. endif ()
  296. endif ()
  297. set (RPI_SUPPORTED_ABIS ${RPI_SUPPORTED_ABIS} CACHE INTERNAL "Supported target ABIs for RPI build")
  298. endif ()
  299. if (CMAKE_CROSSCOMPILING)
  300. set (RPI_PREFIX "" CACHE STRING "Prefix path to Raspberry Pi cross-compiler tools (RPI cross-compiling build only)")
  301. set (RPI_SYSROOT "" CACHE PATH "Path to Raspberry Pi system root (RPI cross-compiling build only)")
  302. endif ()
  303. if (RPI_ABI)
  304. list (FIND RPI_SUPPORTED_ABIS ${RPI_ABI} RPI_ABI_FOUND_INDEX)
  305. if (RPI_ABI_FOUND_INDEX EQUAL -1)
  306. string (REPLACE ";" "\", \"" PRINTABLE_RPI_SUPPORTED_ABIS "${RPI_SUPPORTED_ABIS}") # Stringify for string replace to work
  307. if (NOT CMAKE_CROSSCOMPILING)
  308. set (MSG_STR " by this Raspberry Pi device")
  309. endif ()
  310. message (FATAL_ERROR "Specified RPI_ABI = \"${RPI_ABI}\" is not supported${MSG_STR}. Supported values are: \"${PRINTABLE_RPI_SUPPORTED_ABIS}\".")
  311. endif ()
  312. else ()
  313. set (RPI_ABI armeabi-v6)
  314. endif ()
  315. set (RPI_ABI ${RPI_ABI} CACHE STRING "Specify target ABI (RPI platform only), possible values are armeabi-v6 (default for RPI 1), armeabi-v7a (default for RPI 2), armeabi-v7a with NEON, and armeabi-v7a with VFPV4" FORCE)
  316. endif ()
  317. if (EMSCRIPTEN) # CMAKE_CROSSCOMPILING is always true for Emscripten
  318. set (MODULE MODULE)
  319. set (EMSCRIPTEN_ROOT_PATH "" CACHE PATH "Root path to Emscripten cross-compiler tools (Emscripten only)")
  320. set (EMSCRIPTEN_SYSROOT "" CACHE PATH "Path to Emscripten system root (Emscripten only)")
  321. cmake_dependent_option (EMSCRIPTEN_WASM "Enable Binaryen support to generate output to WASM (WebAssembly) format (Emscripten only)" FALSE "NOT EMSCRIPTEN_EMCC_VERSION VERSION_LESS 1.37.3" FALSE)
  322. # Currently Emscripten does not support memory growth with MODULE library type
  323. if (URHO3D_LIB_TYPE STREQUAL MODULE)
  324. set (DEFAULT_MEMORY_GROWTH FALSE)
  325. else ()
  326. set (DEFAULT_MEMORY_GROWTH TRUE)
  327. endif ()
  328. cmake_dependent_option (EMSCRIPTEN_ALLOW_MEMORY_GROWTH "Enable memory growing based on application demand when targeting asm.js, it is not set by default due to performance penalty (Emscripten with STATIC or SHARED library type only)" FALSE "NOT EMSCRIPTEN_WASM AND NOT URHO3D_LIB_TYPE STREQUAL MODULE" ${DEFAULT_MEMORY_GROWTH}) # Allow memory growth by default when targeting WebAssembly since there is no performance penalty as in asm.js mode
  329. math (EXPR EMSCRIPTEN_TOTAL_MEMORY "128 * 1024 * 1024")
  330. set (EMSCRIPTEN_TOTAL_MEMORY ${EMSCRIPTEN_TOTAL_MEMORY} CACHE STRING "Specify the total size of memory to be used (Emscripten only); default to 128 MB, must be in multiple of 64 KB when targeting WebAssembly and in multiple of 16 MB when targeting asm.js")
  331. cmake_dependent_option (EMSCRIPTEN_SHARE_DATA "Enable sharing data file support (Emscripten only)" FALSE "NOT URHO3D_LIB_TYPE STREQUAL MODULE" TRUE)
  332. endif ()
  333. # Constrain the build option values in cmake-gui, if applicable
  334. set_property (CACHE URHO3D_LIB_TYPE PROPERTY STRINGS STATIC SHARED ${MODULE})
  335. if (NOT CMAKE_CONFIGURATION_TYPES)
  336. set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${URHO3D_BUILD_CONFIGURATIONS})
  337. endif ()
  338. if (RPI)
  339. set_property (CACHE RPI_ABI PROPERTY STRINGS ${RPI_SUPPORTED_ABIS})
  340. endif ()
  341. # Handle mutually exclusive options and implied options
  342. if (URHO3D_D3D11)
  343. set (URHO3D_OPENGL 0)
  344. unset (URHO3D_OPENGL CACHE)
  345. endif ()
  346. if (URHO3D_DATABASE_ODBC)
  347. set (URHO3D_DATABASE_SQLITE 0)
  348. unset (URHO3D_DATABASE_SQLITE CACHE)
  349. endif ()
  350. if (URHO3D_DATABASE_SQLITE OR URHO3D_DATABASE_ODBC)
  351. set (URHO3D_DATABASE 1)
  352. endif ()
  353. if (URHO3D_LUAJIT)
  354. set (JIT JIT)
  355. set (URHO3D_LUA 1)
  356. endif ()
  357. # Union all the sysroot variables into one so it can be referred to generically later
  358. set (SYSROOT ${CMAKE_SYSROOT} ${MINGW_SYSROOT} ${IOS_SYSROOT} ${TVOS_SYSROOT} CACHE INTERNAL "Path to system root of the cross-compiling target") # SYSROOT is empty for native build
  359. # Clang tools building
  360. if (URHO3D_CLANG_TOOLS OR URHO3D_BINDINGS)
  361. # Ensure LLVM/Clang is installed
  362. find_program (LLVM_CONFIG NAMES llvm-config llvm-config-64 llvm-config-32 HINTS $ENV{LLVM_CLANG_ROOT}/bin DOC "LLVM config tool" NO_CMAKE_FIND_ROOT_PATH)
  363. if (NOT LLVM_CONFIG)
  364. message (FATAL_ERROR "Could not find LLVM/Clang installation")
  365. endif ()
  366. endif ()
  367. if (URHO3D_CLANG_TOOLS)
  368. # Require C++11 standard and no precompiled-header
  369. set (URHO3D_PCH 0)
  370. set (URHO3D_LIB_TYPE SHARED)
  371. # Set build options that would maximise the AST of Urho3D library
  372. foreach (OPT
  373. URHO3D_ANGELSCRIPT
  374. URHO3D_DATABASE_SQLITE
  375. URHO3D_FILEWATCHER
  376. URHO3D_IK
  377. URHO3D_LOGGING
  378. URHO3D_LUA
  379. URHO3D_NAVIGATION
  380. URHO3D_NETWORK
  381. URHO3D_PHYSICS
  382. URHO3D_PROFILING
  383. URHO3D_URHO2D)
  384. set (${OPT} 1)
  385. endforeach ()
  386. foreach (OPT URHO3D_TESTING URHO3D_LUAJIT URHO3D_DATABASE_ODBC)
  387. set (${OPT} 0)
  388. endforeach ()
  389. endif ()
  390. # Coverity scan does not support PCH
  391. if ($ENV{COVERITY_SCAN_BRANCH})
  392. set (URHO3D_PCH 0)
  393. endif ()
  394. # Enable testing
  395. if (URHO3D_TESTING)
  396. enable_testing ()
  397. endif ()
  398. # Default library type is STATIC
  399. if (URHO3D_LIB_TYPE)
  400. string (TOUPPER ${URHO3D_LIB_TYPE} URHO3D_LIB_TYPE)
  401. endif ()
  402. if (NOT URHO3D_LIB_TYPE STREQUAL SHARED AND NOT URHO3D_LIB_TYPE STREQUAL MODULE)
  403. set (URHO3D_LIB_TYPE STATIC)
  404. if (MSVC)
  405. # This define will be baked into the export header for MSVC compiler
  406. set (URHO3D_STATIC_DEFINE 1)
  407. else ()
  408. # Only define it on the fly when necessary (both SHARED and STATIC libs can coexist) for other compiler toolchains
  409. add_definitions (-DURHO3D_STATIC_DEFINE)
  410. endif ()
  411. endif ()
  412. if (URHO3D_DATABASE_ODBC)
  413. find_package (ODBC REQUIRED)
  414. endif ()
  415. # Define preprocessor macros (for building the Urho3D library) based on the configured build options
  416. foreach (OPT
  417. URHO3D_ANGELSCRIPT
  418. URHO3D_DATABASE
  419. URHO3D_FILEWATCHER
  420. URHO3D_IK
  421. URHO3D_LOGGING
  422. URHO3D_LUA
  423. URHO3D_MINIDUMPS
  424. URHO3D_NAVIGATION
  425. URHO3D_NETWORK
  426. URHO3D_PHYSICS
  427. URHO3D_PROFILING
  428. URHO3D_THREADING
  429. URHO3D_URHO2D
  430. URHO3D_WEBP
  431. URHO3D_WIN32_CONSOLE)
  432. if (${OPT})
  433. add_definitions (-D${OPT})
  434. endif ()
  435. endforeach ()
  436. # TODO: The logic below is earmarked to be moved into SDL's CMakeLists.txt when refactoring the library dependency handling, until then ensure the DirectX package is not being searched again in external projects such as when building LuaJIT library
  437. if (WIN32 AND NOT CMAKE_PROJECT_NAME MATCHES ^Urho3D-ExternalProject-)
  438. set (DIRECTX_REQUIRED_COMPONENTS)
  439. set (DIRECTX_OPTIONAL_COMPONENTS DInput DSound XAudio2 XInput)
  440. if (NOT URHO3D_OPENGL)
  441. if (URHO3D_D3D11)
  442. list (APPEND DIRECTX_REQUIRED_COMPONENTS D3D11)
  443. else ()
  444. list (APPEND DIRECTX_REQUIRED_COMPONENTS D3D)
  445. endif ()
  446. endif ()
  447. find_package (DirectX REQUIRED ${DIRECTX_REQUIRED_COMPONENTS} OPTIONAL_COMPONENTS ${DIRECTX_OPTIONAL_COMPONENTS})
  448. if (DIRECTX_FOUND)
  449. include_directories (SYSTEM ${DIRECTX_INCLUDE_DIRS}) # These variables may be empty when WinSDK or MinGW is being used
  450. link_directories (${DIRECTX_LIBRARY_DIRS})
  451. endif ()
  452. endif ()
  453. # Platform and compiler specific options
  454. if (CMAKE_CXX_COMPILER_ID MATCHES GNU)
  455. # Use gnu++11/gnu++0x instead of c++11/c++0x as the latter does not work as expected when cross compiling
  456. if (VERIFIED_SUPPORTED_STANDARD)
  457. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=${VERIFIED_SUPPORTED_STANDARD}")
  458. else ()
  459. foreach (STANDARD gnu++11 gnu++0x) # Fallback to gnu++0x on older GCC version
  460. execute_process (COMMAND ${CMAKE_COMMAND} -E echo COMMAND ${CMAKE_CXX_COMPILER} -std=${STANDARD} -E - RESULT_VARIABLE GCC_EXIT_CODE OUTPUT_QUIET ERROR_QUIET)
  461. if (GCC_EXIT_CODE EQUAL 0)
  462. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=${STANDARD}")
  463. set (VERIFIED_SUPPORTED_STANDARD ${STANDARD} CACHE INTERNAL "GNU extension of C++11 standard that is verified to be supported by the chosen compiler")
  464. break ()
  465. endif ()
  466. endforeach ()
  467. if (NOT GCC_EXIT_CODE EQUAL 0)
  468. message (FATAL_ERROR "Your GCC version ${CMAKE_CXX_COMPILER_VERSION} is too old to enable C++11 standard")
  469. endif ()
  470. endif ()
  471. elseif (CMAKE_CXX_COMPILER_ID MATCHES Clang)
  472. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  473. elseif (MSVC80)
  474. message (FATAL_ERROR "Your MSVC version is too told to enable C++11 standard")
  475. endif ()
  476. if (APPLE)
  477. if (IOS)
  478. # iOS-specific setup
  479. add_definitions (-DIOS)
  480. if (URHO3D_64BIT)
  481. if (DEFINED ENV{XCODE_64BIT_ONLY}) # This environment variable is set automatically when ccache is just being cleared in Travis CI VM
  482. set (CMAKE_OSX_ARCHITECTURES "arm64 x86_64") # This is a hack to temporarily only build 64-bit archs to reduce overall build time for one build
  483. else ()
  484. set (CMAKE_OSX_ARCHITECTURES $(ARCHS_STANDARD))
  485. endif ()
  486. else ()
  487. # This is a legacy option and should not be used as we are phasing out 32-bit only mode
  488. set (CMAKE_OSX_ARCHITECTURES $(ARCHS_STANDARD_32_BIT))
  489. endif ()
  490. elseif (TVOS)
  491. # tvOS-specific setup
  492. add_definitions (-DTVOS)
  493. set (CMAKE_OSX_ARCHITECTURES $(ARCHS_STANDARD))
  494. else ()
  495. if (XCODE)
  496. # macOS-specific setup
  497. if (URHO3D_64BIT)
  498. if (URHO3D_UNIVERSAL)
  499. # This is a legacy option and should not be used as we are phasing out macOS universal binary mode
  500. set (CMAKE_OSX_ARCHITECTURES $(ARCHS_STANDARD_32_64_BIT))
  501. else ()
  502. set (CMAKE_OSX_ARCHITECTURES $(ARCHS_STANDARD))
  503. endif ()
  504. else ()
  505. # This is a legacy option and should not be used as we are phasing out 32-bit only mode
  506. set (CMAKE_OSX_ARCHITECTURES $(ARCHS_STANDARD_32_BIT))
  507. endif ()
  508. endif ()
  509. endif ()
  510. # Common macOS, iOS, and tvOS bundle setup
  511. if (URHO3D_MACOSX_BUNDLE OR (APPLE AND ARM))
  512. # Only set the bundle properties to its default when they are not explicitly specified by user
  513. if (NOT MACOSX_BUNDLE_GUI_IDENTIFIER)
  514. set (MACOSX_BUNDLE_GUI_IDENTIFIER com.github.urho3d.\${PRODUCT_NAME:rfc1034identifier:lower})
  515. endif ()
  516. if (NOT MACOSX_BUNDLE_BUNDLE_NAME)
  517. set (MACOSX_BUNDLE_BUNDLE_NAME \${PRODUCT_NAME})
  518. endif ()
  519. endif ()
  520. endif ()
  521. if (MSVC)
  522. # VS-specific setup
  523. add_definitions (-D_CRT_SECURE_NO_WARNINGS)
  524. if (URHO3D_STATIC_RUNTIME)
  525. set (RELEASE_RUNTIME /MT)
  526. set (DEBUG_RUNTIME /MTd)
  527. endif ()
  528. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP")
  529. set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${DEBUG_RUNTIME}")
  530. set (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELEASE} ${RELEASE_RUNTIME} /fp:fast /Zi /GS-")
  531. set (CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELWITHDEBINFO})
  532. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
  533. set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${DEBUG_RUNTIME}")
  534. set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE} ${RELEASE_RUNTIME} /fp:fast /Zi /GS- /D _SECURE_SCL=0")
  535. set (CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
  536. # In Visual Studio, SSE2 flag is redundant if already compiling as 64bit; it is already the default for VS2012 (onward) on 32bit
  537. # Instead, we must turn SSE/SSE2 off explicitly if user really intends to turn it off
  538. if (URHO3D_SSE)
  539. if (NOT URHO3D_64BIT AND MSVC_VERSION LESS 1700)
  540. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:SSE2")
  541. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:SSE2")
  542. endif ()
  543. else ()
  544. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /arch:IA32")
  545. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:IA32")
  546. endif ()
  547. set (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /OPT:REF /OPT:ICF /DEBUG")
  548. set (CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /OPT:REF /OPT:ICF")
  549. else ()
  550. # GCC/Clang-specific setup
  551. set (CMAKE_CXX_VISIBILITY_PRESET hidden)
  552. set (CMAKE_VISIBILITY_INLINES_HIDDEN true)
  553. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-offsetof")
  554. if (NOT ANDROID) # Most of the flags are already setup in Android toolchain file
  555. if (ARM AND CMAKE_SYSTEM_NAME STREQUAL Linux)
  556. # Common compiler flags for aarch64-linux-gnu and arm-linux-gnueabihf, we do not support ARM on Windows for now
  557. set (ARM_CFLAGS "${ARM_CFLAGS} -fsigned-char -pipe")
  558. if (NOT URHO3D_64BIT)
  559. # We only support armhf distros, so turn on hard-float by default
  560. set (ARM_CFLAGS "${ARM_CFLAGS} -mfloat-abi=hard -Wno-psabi")
  561. endif ()
  562. # The configuration is done here instead of in CMake toolchain file because we also support native build which does not use toolchain file at all
  563. if (RPI)
  564. # RPI-specific setup
  565. add_definitions (-DRPI)
  566. if (RPI_ABI MATCHES ^armeabi-v7a)
  567. set (ARM_CFLAGS "${ARM_CFLAGS} -mcpu=cortex-a7")
  568. if (RPI_ABI MATCHES NEON)
  569. set (ARM_CFLAGS "${ARM_CFLAGS} -mfpu=neon-vfpv4")
  570. elseif (RPI_ABI MATCHES VFPV4)
  571. set (ARM_CFLAGS "${ARM_CFLAGS} -mfpu=vfpv4")
  572. else ()
  573. set (ARM_CFLAGS "${ARM_CFLAGS} -mfpu=vfpv4-d16")
  574. endif ()
  575. else ()
  576. set (ARM_CFLAGS "${ARM_CFLAGS} -mcpu=arm1176jzf-s -mfpu=vfp")
  577. endif ()
  578. else ()
  579. # Generic ARM-specific setup
  580. add_definitions (-DGENERIC_ARM)
  581. if (URHO3D_64BIT)
  582. # aarch64 has only one valid arch so far
  583. set (ARM_CFLAGS "${ARM_CFLAGS} -march=armv8-a")
  584. elseif (URHO3D_ANGELSCRIPT)
  585. # Angelscript seems to fail to compile using Thumb states, so force to use ARM states by default
  586. set (ARM_CFLAGS "${ARM_CFLAGS} -marm")
  587. endif ()
  588. if (ARM_ABI_FLAGS)
  589. # Instead of guessing all the possible ABIs, user would have to specify the ABI compiler flags explicitly via ARM_ABI_FLAGS build option
  590. set (ARM_CFLAGS "${ARM_CFLAGS} ${ARM_ABI_FLAGS}")
  591. endif ()
  592. endif ()
  593. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARM_CFLAGS}")
  594. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARM_CFLAGS}")
  595. else ()
  596. if (URHO3D_SSE AND NOT XCODE AND NOT WEB)
  597. # This may influence the effective SSE level when URHO3D_SSE is on as well
  598. set (URHO3D_DEPLOYMENT_TARGET native CACHE STRING "Specify the minimum CPU type on which the target binaries are to be deployed (non-ARM platform only), see GCC/Clang's -march option for possible values; Use 'generic' for targeting a wide range of generic processors")
  599. if (NOT URHO3D_DEPLOYMENT_TARGET STREQUAL generic)
  600. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=${URHO3D_DEPLOYMENT_TARGET}")
  601. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=${URHO3D_DEPLOYMENT_TARGET}")
  602. endif ()
  603. endif ()
  604. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffast-math")
  605. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffast-math")
  606. # We don't add these flags directly here for Xcode because we support Mach-O universal binary build
  607. # The compiler flags will be added later conditionally when the effective arch is i386 during build time (using XCODE_ATTRIBUTE target property)
  608. if (NOT XCODE)
  609. if (NOT URHO3D_64BIT)
  610. # Not the compiler native ABI, this could only happen on multilib-capable compilers
  611. if (NATIVE_64BIT)
  612. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
  613. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
  614. endif ()
  615. # The effective SSE level could be higher, see also URHO3D_DEPLOYMENT_TARGET and CMAKE_OSX_DEPLOYMENT_TARGET build options
  616. # The -mfpmath=sse is not set in global scope but it may be set in local scope when building LuaJIT sub-library for x86 arch
  617. if (URHO3D_SSE)
  618. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse -msse2")
  619. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse -msse2")
  620. endif ()
  621. endif ()
  622. if (NOT URHO3D_SSE)
  623. if (URHO3D_64BIT OR CMAKE_CXX_COMPILER_ID MATCHES Clang)
  624. # Clang enables SSE support for i386 ABI by default, so use the '-mno-sse' compiler flag to nullify that and make it consistent with GCC
  625. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mno-sse")
  626. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mno-sse")
  627. endif ()
  628. if (URHO3D_MMX)
  629. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmmx")
  630. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmmx")
  631. endif ()
  632. if (URHO3D_3DNOW)
  633. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m3dnow")
  634. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m3dnow")
  635. endif ()
  636. endif ()
  637. # For completeness sake only as we do not support PowerPC (yet)
  638. if (URHO3D_ALTIVEC)
  639. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maltivec")
  640. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maltivec")
  641. endif ()
  642. endif ()
  643. endif ()
  644. if (WEB)
  645. if (EMSCRIPTEN)
  646. # Emscripten-specific setup
  647. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-warn-absolute-paths -Wno-unknown-warning-option")
  648. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-warn-absolute-paths -Wno-unknown-warning-option")
  649. if (URHO3D_THREADING)
  650. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s USE_PTHREADS=1")
  651. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s USE_PTHREADS=1")
  652. endif ()
  653. # Prior to version 1.31.3 emcc does not consistently add the cpp standard and remove Emscripten-specific compiler flags
  654. # before passing on the work to the underlying LLVM/Clang compiler, this has resulted in preprocessing error when enabling the PCH and ccache
  655. # (See https://github.com/kripken/emscripten/issues/3365 for more detail)
  656. if (EMSCRIPTEN_EMCC_VERSION VERSION_LESS 1.31.3)
  657. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++03")
  658. endif ()
  659. set (CMAKE_C_FLAGS_RELEASE "-Oz -DNDEBUG")
  660. set (CMAKE_CXX_FLAGS_RELEASE "-Oz -DNDEBUG")
  661. # Remove variables to make the -O3 regalloc easier, embed data in asm.js to reduce number of moving part
  662. set (CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -O3 -s AGGRESSIVE_VARIABLE_ELIMINATION=1 --memory-init-file 0")
  663. set (CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} -O3 -s AGGRESSIVE_VARIABLE_ELIMINATION=1 --memory-init-file 0")
  664. # Preserve LLVM debug information, show line number debug comments, and generate source maps; always disable exception handling codegen
  665. set (CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -g4 -s DISABLE_EXCEPTION_CATCHING=1")
  666. set (CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG} -g4 -s DISABLE_EXCEPTION_CATCHING=1")
  667. endif ()
  668. elseif (MINGW)
  669. # MinGW-specific setup
  670. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static -static-libgcc -fno-keep-inline-dllexport")
  671. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static -static-libgcc -static-libstdc++ -fno-keep-inline-dllexport")
  672. if (NOT URHO3D_64BIT)
  673. set (CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
  674. set (CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
  675. # Prevent auto-vectorize optimization when using -O2, unless stack realign is being enforced globally
  676. if (URHO3D_SSE)
  677. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mstackrealign")
  678. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mstackrealign")
  679. else ()
  680. set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fno-tree-slp-vectorize -fno-tree-vectorize")
  681. set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-tree-slp-vectorize -fno-tree-vectorize")
  682. endif ()
  683. endif ()
  684. else ()
  685. # Not Android and not Emscripten and not MinGW derivative
  686. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread") # This will emit '-DREENTRANT' to compiler and '-lpthread' to linker on Linux and Mac OSX platform
  687. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") # However, it may emit other equivalent compiler define and/or linker flag on other *nix platforms
  688. endif ()
  689. set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG -D_DEBUG")
  690. set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -D_DEBUG")
  691. endif ()
  692. if (CMAKE_CXX_COMPILER_ID MATCHES Clang)
  693. # Clang-specific
  694. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Qunused-arguments")
  695. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments")
  696. if (NINJA OR "$ENV{USE_CCACHE}") # Stringify to guard against undefined environment variable
  697. # When ccache support is on, these flags keep the color diagnostics pipe through ccache output and suppress Clang warning due ccache internal preprocessing step
  698. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcolor-diagnostics")
  699. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcolor-diagnostics")
  700. endif ()
  701. else ()
  702. # GCC-specific
  703. if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9.1)
  704. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdiagnostics-color=auto")
  705. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=auto")
  706. endif ()
  707. endif ()
  708. endif ()
  709. # LuaJIT specific - extra linker flags for linking against LuaJIT (adapted from LuaJIT's original Makefile)
  710. if (URHO3D_LUAJIT)
  711. if (URHO3D_64BIT AND APPLE AND NOT ARM)
  712. # 64-bit macOS: it simply won't work without these flags; if you are reading this comment then you may want to know the following also
  713. # it's recommended to rebase all (self-compiled) shared libraries which are loaded at runtime on OSX/x64 (e.g. C extension modules for Lua), see: man rebase
  714. set (LUAJIT_EXE_LINKER_FLAGS_APPLE "-pagezero_size 10000 -image_base 100000000")
  715. set (LUAJIT_SHARED_LINKER_FLAGS_APPLE "-image_base 7fff04c4a000")
  716. if (NOT XCODE)
  717. set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LUAJIT_EXE_LINKER_FLAGS_APPLE}")
  718. set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LUAJIT_SHARED_LINKER_FLAGS_APPLE}")
  719. endif ()
  720. elseif (URHO3D_LIB_TYPE STREQUAL STATIC AND NOT WIN32 AND NOT APPLE) # The original condition also checks: AND NOT SunOS AND NOT PS3
  721. # We assume user may want to load C modules compiled for plain Lua with require(), so we have to ensure all the public symbols are exported when linking with Urho3D (and therefore LuaJIT) statically
  722. # Note: this implies that loading such modules on Windows platform may only work with SHARED library type
  723. set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-E")
  724. endif ()
  725. endif ()
  726. # Trim the leading white space in the compiler/linker flags, if any
  727. foreach (TYPE C CXX EXE_LINKER SHARED_LINKER)
  728. string (REGEX REPLACE "^ +" "" CMAKE_${TYPE}_FLAGS "${CMAKE_${TYPE}_FLAGS}")
  729. endforeach ()
  730. include (CMakeParseArguments)
  731. # Macro for adjusting target output name by dropping _suffix from the target name
  732. macro (adjust_target_name)
  733. if (TARGET_NAME MATCHES _.*$)
  734. string (REGEX REPLACE _.*$ "" OUTPUT_NAME ${TARGET_NAME})
  735. set_target_properties (${TARGET_NAME} PROPERTIES OUTPUT_NAME ${OUTPUT_NAME})
  736. endif ()
  737. endmacro ()
  738. # Macro for checking the SOURCE_FILES variable is properly initialized
  739. macro (check_source_files)
  740. if (NOT SOURCE_FILES)
  741. if (NOT ${ARGN} STREQUAL "")
  742. message (FATAL_ERROR ${ARGN})
  743. else ()
  744. message (FATAL_ERROR "Could not configure and generate the project file because no source files have been defined yet. "
  745. "You can define the source files explicitly by setting the SOURCE_FILES variable in your CMakeLists.txt; or "
  746. "by calling the define_source_files() macro which would by default glob all the C++ source files found in the same scope of "
  747. "CMakeLists.txt where the macro is being called and the macro would set the SOURCE_FILES variable automatically. "
  748. "If your source files are not located in the same directory as the CMakeLists.txt or your source files are "
  749. "more than just C++ language then you probably have to pass in extra arguments when calling the macro in order to make it works. "
  750. "See the define_source_files() macro definition in the CMake/Modules/UrhoCommon.cmake for more detail.")
  751. endif ()
  752. endif ()
  753. endmacro ()
  754. # Macro for setting symbolic link on platform that supports it
  755. macro (create_symlink SOURCE DESTINATION)
  756. # Make absolute paths so they work more reliably on cmake-gui
  757. if (IS_ABSOLUTE ${SOURCE})
  758. set (ABS_SOURCE ${SOURCE})
  759. else ()
  760. set (ABS_SOURCE ${CMAKE_SOURCE_DIR}/${SOURCE})
  761. endif ()
  762. if (IS_ABSOLUTE ${DESTINATION})
  763. set (ABS_DESTINATION ${DESTINATION})
  764. else ()
  765. set (ABS_DESTINATION ${CMAKE_BINARY_DIR}/${DESTINATION})
  766. endif ()
  767. if (CMAKE_HOST_WIN32)
  768. if (IS_DIRECTORY ${ABS_SOURCE})
  769. set (SLASH_D /D)
  770. else ()
  771. unset (SLASH_D)
  772. endif ()
  773. if (HAS_MKLINK)
  774. if (NOT EXISTS ${ABS_DESTINATION})
  775. # Have to use string-REPLACE as file-TO_NATIVE_PATH does not work as expected with MinGW on "backward slash" host system
  776. string (REPLACE / \\ BACKWARD_ABS_DESTINATION ${ABS_DESTINATION})
  777. string (REPLACE / \\ BACKWARD_ABS_SOURCE ${ABS_SOURCE})
  778. execute_process (COMMAND cmd /C mklink ${SLASH_D} ${BACKWARD_ABS_DESTINATION} ${BACKWARD_ABS_SOURCE} OUTPUT_QUIET ERROR_QUIET)
  779. endif ()
  780. elseif (${ARGN} STREQUAL FALLBACK_TO_COPY)
  781. if (SLASH_D)
  782. set (COMMAND COMMAND ${CMAKE_COMMAND} -E copy_directory ${ABS_SOURCE} ${ABS_DESTINATION})
  783. else ()
  784. set (COMMAND COMMAND ${CMAKE_COMMAND} -E copy_if_different ${ABS_SOURCE} ${ABS_DESTINATION})
  785. endif ()
  786. # Fallback to copy only one time
  787. execute_process (${COMMAND})
  788. if (TARGET ${TARGET_NAME})
  789. # Fallback to copy every time the target is built
  790. add_custom_command (TARGET ${TARGET_NAME} POST_BUILD ${COMMAND})
  791. endif ()
  792. else ()
  793. message (WARNING "Unable to create symbolic link on this host system, you may need to manually copy file/dir from \"${SOURCE}\" to \"${DESTINATION}\"")
  794. endif ()
  795. else ()
  796. execute_process (COMMAND ${CMAKE_COMMAND} -E create_symlink ${ABS_SOURCE} ${ABS_DESTINATION})
  797. endif ()
  798. endmacro ()
  799. # Macro for adding additional make clean files
  800. macro (add_make_clean_files)
  801. get_directory_property (ADDITIONAL_MAKE_CLEAN_FILES ADDITIONAL_MAKE_CLEAN_FILES)
  802. set_directory_properties (PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${ADDITIONAL_MAKE_CLEAN_FILES};${ARGN}")
  803. endmacro ()
  804. # *** THIS IS A DEPRECATED MACRO ***
  805. # Macro for defining external library dependencies
  806. # The purpose of this macro is emulate CMake to set the external library dependencies transitively
  807. # It works for both targets setup within Urho3D project and downstream projects that uses Urho3D as external static/shared library
  808. # *** THIS IS A DEPRECATED MACRO ***
  809. macro (define_dependency_libs TARGET)
  810. # ThirdParty/SDL external dependency
  811. if (${TARGET} MATCHES SDL|Urho3D)
  812. if (WIN32)
  813. list (APPEND LIBS user32 gdi32 winmm imm32 ole32 oleaut32 version uuid)
  814. elseif (APPLE)
  815. list (APPEND LIBS iconv)
  816. elseif (ANDROID)
  817. list (APPEND LIBS dl log android)
  818. else ()
  819. # Linux
  820. if (NOT WEB)
  821. list (APPEND LIBS dl m rt)
  822. endif ()
  823. if (RPI)
  824. list (APPEND ABSOLUTE_PATH_LIBS ${VIDEOCORE_LIBRARIES})
  825. endif ()
  826. endif ()
  827. endif ()
  828. # ThirdParty/kNet & ThirdParty/Civetweb external dependency
  829. if (${TARGET} MATCHES Civetweb|kNet|Urho3D)
  830. if (WIN32)
  831. list (APPEND LIBS ws2_32)
  832. endif ()
  833. endif ()
  834. # Urho3D/LuaJIT external dependency
  835. if (URHO3D_LUAJIT AND ${TARGET} MATCHES LuaJIT|Urho3D)
  836. if (NOT WIN32 AND NOT WEB)
  837. list (APPEND LIBS dl m)
  838. endif ()
  839. endif ()
  840. # Urho3D external dependency
  841. if (${TARGET} STREQUAL Urho3D)
  842. # Core
  843. if (WIN32)
  844. list (APPEND LIBS winmm)
  845. if (URHO3D_MINIDUMPS)
  846. list (APPEND LIBS dbghelp)
  847. endif ()
  848. elseif (APPLE)
  849. if (ARM)
  850. list (APPEND LIBS "-framework AudioToolbox" "-framework AVFoundation" "-framework CoreAudio" "-framework CoreGraphics" "-framework CoreMotion" "-framework Foundation" "-framework GameController" "-framework OpenGLES" "-framework QuartzCore" "-framework UIKit")
  851. else ()
  852. list (APPEND LIBS "-framework AudioToolbox" "-framework Carbon" "-framework Cocoa" "-framework CoreFoundation" "-framework SystemConfiguration" "-framework CoreAudio" "-framework CoreServices" "-framework CoreVideo" "-framework ForceFeedback" "-framework IOKit" "-framework OpenGL")
  853. endif ()
  854. endif ()
  855. # Graphics
  856. if (URHO3D_OPENGL)
  857. if (APPLE)
  858. # Do nothing
  859. elseif (WIN32)
  860. list (APPEND LIBS opengl32)
  861. elseif (ANDROID OR ARM)
  862. list (APPEND LIBS GLESv1_CM GLESv2)
  863. else ()
  864. list (APPEND LIBS GL)
  865. endif ()
  866. elseif (DIRECT3D_LIBRARIES)
  867. list (APPEND LIBS ${DIRECT3D_LIBRARIES})
  868. endif ()
  869. # Database
  870. if (URHO3D_DATABASE_ODBC)
  871. list (APPEND LIBS ${ODBC_LIBRARIES})
  872. endif ()
  873. # This variable value can either be 'Urho3D' target or an absolute path to an actual static/shared Urho3D library or empty (if we are building the library itself)
  874. # The former would cause CMake not only to link against the Urho3D library but also to add a dependency to Urho3D target
  875. if (URHO3D_LIBRARIES)
  876. if (WIN32 AND URHO3D_LIBRARIES_DBG AND URHO3D_LIBRARIES_REL AND TARGET ${TARGET_NAME})
  877. # Special handling when both debug and release libraries are found
  878. target_link_libraries (${TARGET_NAME} debug ${URHO3D_LIBRARIES_DBG} optimized ${URHO3D_LIBRARIES_REL})
  879. else ()
  880. if (TARGET ${TARGET}_universal)
  881. add_dependencies (${TARGET_NAME} ${TARGET}_universal)
  882. endif ()
  883. if (URHO3D_LIB_TYPE STREQUAL MODULE)
  884. if (TARGET ${TARGET})
  885. add_dependencies (${TARGET_NAME} ${TARGET})
  886. endif ()
  887. else ()
  888. list (APPEND ABSOLUTE_PATH_LIBS ${URHO3D_LIBRARIES})
  889. endif ()
  890. endif ()
  891. endif ()
  892. endif ()
  893. endmacro ()
  894. # Macro for defining source files with optional arguments as follows:
  895. # GLOB_CPP_PATTERNS <list> - Use the provided globbing patterns for CPP_FILES instead of the default *.cpp
  896. # GLOB_H_PATTERNS <list> - Use the provided globbing patterns for H_FILES instead of the default *.h
  897. # EXCLUDE_PATTERNS <list> - Use the provided regex patterns for excluding the unwanted matched source files
  898. # EXTRA_CPP_FILES <list> - Include the provided list of files into CPP_FILES result
  899. # EXTRA_H_FILES <list> - Include the provided list of files into H_FILES result
  900. # PCH <list> - Enable precompiled header support on the defined source files using the specified header file, the list is "<path/to/header> [C++|C]"
  901. # RECURSE - Option to glob recursively
  902. # GROUP - Option to group source files based on its relative path to the corresponding parent directory
  903. macro (define_source_files)
  904. # Source files are defined by globbing source files in current source directory and also by including the extra source files if provided
  905. cmake_parse_arguments (ARG "RECURSE;GROUP" "" "PCH;EXTRA_CPP_FILES;EXTRA_H_FILES;GLOB_CPP_PATTERNS;GLOB_H_PATTERNS;EXCLUDE_PATTERNS" ${ARGN})
  906. if (NOT ARG_GLOB_CPP_PATTERNS)
  907. set (ARG_GLOB_CPP_PATTERNS *.cpp) # Default glob pattern
  908. endif ()
  909. if (NOT ARG_GLOB_H_PATTERNS)
  910. set (ARG_GLOB_H_PATTERNS *.h)
  911. endif ()
  912. if (ARG_RECURSE)
  913. set (ARG_RECURSE _RECURSE)
  914. else ()
  915. unset (ARG_RECURSE)
  916. endif ()
  917. file (GLOB${ARG_RECURSE} CPP_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${ARG_GLOB_CPP_PATTERNS})
  918. file (GLOB${ARG_RECURSE} H_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${ARG_GLOB_H_PATTERNS})
  919. if (ARG_EXCLUDE_PATTERNS)
  920. set (CPP_FILES_WITH_SENTINEL ";${CPP_FILES};") # Stringify the lists
  921. set (H_FILES_WITH_SENTINEL ";${H_FILES};")
  922. foreach (PATTERN ${ARG_EXCLUDE_PATTERNS})
  923. foreach (LOOP RANGE 1)
  924. string (REGEX REPLACE ";${PATTERN};" ";;" CPP_FILES_WITH_SENTINEL "${CPP_FILES_WITH_SENTINEL}")
  925. string (REGEX REPLACE ";${PATTERN};" ";;" H_FILES_WITH_SENTINEL "${H_FILES_WITH_SENTINEL}")
  926. endforeach ()
  927. endforeach ()
  928. set (CPP_FILES ${CPP_FILES_WITH_SENTINEL}) # Convert strings back to lists, extra sentinels are harmless
  929. set (H_FILES ${H_FILES_WITH_SENTINEL})
  930. endif ()
  931. list (APPEND CPP_FILES ${ARG_EXTRA_CPP_FILES})
  932. list (APPEND H_FILES ${ARG_EXTRA_H_FILES})
  933. set (SOURCE_FILES ${CPP_FILES} ${H_FILES})
  934. # Optionally enable PCH
  935. if (ARG_PCH)
  936. enable_pch (${ARG_PCH})
  937. endif ()
  938. # Optionally group the sources based on their physical subdirectories
  939. if (ARG_GROUP)
  940. foreach (CPP_FILE ${CPP_FILES})
  941. get_filename_component (PATH ${CPP_FILE} PATH)
  942. if (PATH)
  943. string (REPLACE / \\ PATH ${PATH})
  944. source_group ("Source Files\\${PATH}" FILES ${CPP_FILE})
  945. endif ()
  946. endforeach ()
  947. foreach (H_FILE ${H_FILES})
  948. get_filename_component (PATH ${H_FILE} PATH)
  949. if (PATH)
  950. string (REPLACE / \\ PATH ${PATH})
  951. source_group ("Header Files\\${PATH}" FILES ${H_FILE})
  952. endif ()
  953. endforeach ()
  954. endif ()
  955. endmacro ()
  956. # Macro for defining resource directories with optional arguments as follows:
  957. # GLOB_PATTERNS <list> - Use the provided globbing patterns for resource directories, default to "${CMAKE_SOURCE_DIR}/bin/*Data"
  958. # EXCLUDE_PATTERNS <list> - Use the provided regex patterns for excluding the unwanted matched directories
  959. # EXTRA_DIRS <list> - Include the provided list of directories into globbing result
  960. # HTML_SHELL <value> - An absolute path to the HTML shell file (only applicable for Web platform)
  961. macro (define_resource_dirs)
  962. check_source_files ("Could not call define_resource_dirs() macro before define_source_files() macro.")
  963. cmake_parse_arguments (ARG "" "HTML_SHELL" "GLOB_PATTERNS;EXCLUDE_PATTERNS;EXTRA_DIRS" ${ARGN})
  964. if (WEB AND ARG_HTML_SHELL)
  965. add_html_shell (${ARG_HTML_SHELL})
  966. endif ()
  967. # If not explicitly specified then use the Urho3D project structure convention
  968. if (NOT ARG_GLOB_PATTERNS)
  969. set (ARG_GLOB_PATTERNS ${CMAKE_SOURCE_DIR}/bin/*Data)
  970. endif ()
  971. file (GLOB GLOB_RESULTS ${ARG_GLOB_PATTERNS})
  972. unset (GLOB_DIRS)
  973. foreach (DIR ${GLOB_RESULTS})
  974. if (IS_DIRECTORY ${DIR})
  975. list (APPEND GLOB_DIRS ${DIR})
  976. endif ()
  977. endforeach ()
  978. if (ARG_EXCLUDE_PATTERNS)
  979. set (GLOB_DIRS_WITH_SENTINEL ";${GLOB_DIRS};") # Stringify the lists
  980. foreach (PATTERN ${ARG_EXCLUDE_PATTERNS})
  981. foreach (LOOP RANGE 1)
  982. string (REGEX REPLACE ";${PATTERN};" ";;" GLOB_DIRS_WITH_SENTINEL "${GLOB_DIRS_WITH_SENTINEL}")
  983. endforeach ()
  984. endforeach ()
  985. set (GLOB_DIRS ${GLOB_DIRS_WITH_SENTINEL}) # Convert strings back to lists, extra sentinels are harmless
  986. endif ()
  987. list (APPEND RESOURCE_DIRS ${GLOB_DIRS} ${ARG_EXTRA_DIRS})
  988. source_group ("Resource Dirs" FILES ${RESOURCE_DIRS})
  989. # Populate all the variables required by resource packaging, if the build option is enabled
  990. if (URHO3D_PACKAGING AND RESOURCE_DIRS)
  991. foreach (DIR ${RESOURCE_DIRS})
  992. get_filename_component (NAME ${DIR} NAME)
  993. if (ANDROID)
  994. set (RESOURCE_${DIR}_PATHNAME ${CMAKE_BINARY_DIR}/assets/${NAME}.pak)
  995. else ()
  996. set (RESOURCE_${DIR}_PATHNAME ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${NAME}.pak)
  997. endif ()
  998. list (APPEND RESOURCE_PAKS ${RESOURCE_${DIR}_PATHNAME})
  999. if (EMSCRIPTEN AND NOT EMSCRIPTEN_SHARE_DATA)
  1000. # Set the custom EMCC_OPTION property to preload the *.pak individually
  1001. set_source_files_properties (${RESOURCE_${DIR}_PATHNAME} PROPERTIES EMCC_OPTION preload-file EMCC_FILE_ALIAS "${NAME}.pak")
  1002. endif ()
  1003. endforeach ()
  1004. set_property (SOURCE ${RESOURCE_PAKS} PROPERTY GENERATED TRUE)
  1005. if (WEB)
  1006. if (EMSCRIPTEN)
  1007. # Set the custom EMCC_OPTION property to peload the generated shared data file
  1008. if (EMSCRIPTEN_SHARE_DATA)
  1009. set (SHARED_RESOURCE_JS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_PROJECT_NAME}.js)
  1010. list (APPEND SOURCE_FILES ${SHARED_RESOURCE_JS} ${SHARED_RESOURCE_JS}.data)
  1011. # DEST_BUNDLE_DIR may be empty when macro caller does not wish to install anything
  1012. if (DEST_BUNDLE_DIR)
  1013. install (FILES ${SHARED_RESOURCE_JS} ${SHARED_RESOURCE_JS}.data DESTINATION ${DEST_BUNDLE_DIR})
  1014. endif ()
  1015. # Define a custom command for generating a shared data file
  1016. if (RESOURCE_PAKS)
  1017. # When sharing a single data file, all main targets are assumed to use a same set of resource paks
  1018. foreach (FILE ${RESOURCE_PAKS})
  1019. get_filename_component (NAME ${FILE} NAME)
  1020. list (APPEND PAK_NAMES ${NAME})
  1021. endforeach ()
  1022. if (CMAKE_BUILD_TYPE STREQUAL Debug AND EMSCRIPTEN_EMCC_VERSION VERSION_GREATER 1.32.2)
  1023. set (SEPARATE_METADATA --separate-metadata)
  1024. endif ()
  1025. add_custom_command (OUTPUT ${SHARED_RESOURCE_JS} ${SHARED_RESOURCE_JS}.data
  1026. COMMAND ${EMPACKAGER} ${SHARED_RESOURCE_JS}.data --preload ${PAK_NAMES} --js-output=${SHARED_RESOURCE_JS} --use-preload-cache ${SEPARATE_METADATA}
  1027. DEPENDS RESOURCE_CHECK ${RESOURCE_PAKS}
  1028. WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
  1029. COMMENT "Generating shared data file")
  1030. endif ()
  1031. endif ()
  1032. endif ()
  1033. endif ()
  1034. endif ()
  1035. if (XCODE)
  1036. if (NOT RESOURCE_FILES)
  1037. # Default app bundle icon
  1038. set (RESOURCE_FILES ${CMAKE_SOURCE_DIR}/bin/Data/Textures/UrhoIcon.icns)
  1039. if (ARM)
  1040. # Default app icon on the iOS/tvOS home screen
  1041. list (APPEND RESOURCE_FILES ${CMAKE_SOURCE_DIR}/bin/Data/Textures/UrhoIcon.png)
  1042. endif ()
  1043. endif ()
  1044. # Group them together under 'Resources' in Xcode IDE
  1045. source_group (Resources FILES ${RESOURCE_PAKS} ${RESOURCE_FILES}) # RESOURCE_PAKS could be empty if packaging is not requested
  1046. # But only use either paks or dirs
  1047. if (RESOURCE_PAKS)
  1048. set_source_files_properties (${RESOURCE_PAKS} ${RESOURCE_FILES} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
  1049. else ()
  1050. set_source_files_properties (${RESOURCE_DIRS} ${RESOURCE_FILES} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
  1051. endif ()
  1052. endif ()
  1053. list (APPEND SOURCE_FILES ${RESOURCE_DIRS} ${RESOURCE_PAKS} ${RESOURCE_FILES})
  1054. endmacro()
  1055. # Macro fo adding a HTML shell-file when targeting Web platform
  1056. macro (add_html_shell)
  1057. check_source_files ("Could not call add_html_shell() macro before define_source_files() macro.")
  1058. if (EMSCRIPTEN)
  1059. if (NOT ${ARGN} STREQUAL "")
  1060. set (HTML_SHELL ${ARGN})
  1061. else ()
  1062. # Create Urho3D custom HTML shell that also embeds our own project logo
  1063. if (NOT EXISTS ${CMAKE_BINARY_DIR}/Source/shell.html)
  1064. file (READ ${EMSCRIPTEN_ROOT_PATH}/src/shell.html HTML_SHELL)
  1065. string (REPLACE "<!doctype html>" "#!/usr/bin/env ${EMSCRIPTEN_EMRUN_BROWSER}\n<!-- This is a generated file. DO NOT EDIT!-->\n\n<!doctype html>" HTML_SHELL "${HTML_SHELL}") # Stringify to preserve semicolons
  1066. string (REPLACE "<body>" "<body>\n<script>document.body.innerHTML=document.body.innerHTML.replace(/^#!.*\\n/, '');</script>\n<a href=\"https://urho3d.github.io\" title=\"Urho3D Homepage\"><img src=\"https://urho3d.github.io/assets/images/logo.png\" alt=\"link to https://urho3d.github.io\" height=\"80\" width=\"160\" /></a>\n" HTML_SHELL "${HTML_SHELL}")
  1067. file (WRITE ${CMAKE_BINARY_DIR}/Source/shell.html "${HTML_SHELL}")
  1068. endif ()
  1069. set (HTML_SHELL ${CMAKE_BINARY_DIR}/Source/shell.html)
  1070. endif ()
  1071. list (APPEND SOURCE_FILES ${HTML_SHELL})
  1072. set_source_files_properties (${HTML_SHELL} PROPERTIES EMCC_OPTION shell-file)
  1073. endif ()
  1074. endmacro ()
  1075. include (GenerateExportHeader)
  1076. # Macro for precompiling header (On MSVC, the dummy C++ or C implementation file for precompiling the header file would be generated if not already exists)
  1077. # This macro should be called before the CMake target has been added
  1078. # Typically, user should indirectly call this macro by using the 'PCH' option when calling define_source_files() macro
  1079. macro (enable_pch HEADER_PATHNAME)
  1080. # No op when PCH support is not enabled
  1081. if (URHO3D_PCH)
  1082. # Get the optional LANG parameter to indicate whether the header should be treated as C or C++ header, default to C++
  1083. if ("${ARGN}" STREQUAL C) # Stringify as the LANG paramater could be empty
  1084. set (EXT c)
  1085. set (LANG C)
  1086. set (LANG_H c-header)
  1087. else ()
  1088. # This is the default
  1089. set (EXT cpp)
  1090. set (LANG CXX)
  1091. set (LANG_H c++-header)
  1092. endif ()
  1093. # Relative path is resolved using CMAKE_CURRENT_SOURCE_DIR
  1094. if (IS_ABSOLUTE ${HEADER_PATHNAME})
  1095. set (ABS_HEADER_PATHNAME ${HEADER_PATHNAME})
  1096. else ()
  1097. set (ABS_HEADER_PATHNAME ${CMAKE_CURRENT_SOURCE_DIR}/${HEADER_PATHNAME})
  1098. endif ()
  1099. # Determine the precompiled header output filename
  1100. get_filename_component (HEADER_FILENAME ${HEADER_PATHNAME} NAME)
  1101. if (CMAKE_COMPILER_IS_GNUCXX)
  1102. # GNU g++
  1103. set (PCH_FILENAME ${HEADER_FILENAME}.gch)
  1104. else ()
  1105. # Clang or MSVC
  1106. set (PCH_FILENAME ${HEADER_FILENAME}.pch)
  1107. endif ()
  1108. if (MSVC)
  1109. get_filename_component (NAME_WE ${HEADER_FILENAME} NAME_WE)
  1110. if (TARGET ${TARGET_NAME})
  1111. if (VS)
  1112. # VS is multi-config, the exact path is only known during actual build time based on effective build config
  1113. set (PCH_PATHNAME "$(IntDir)${PCH_FILENAME}")
  1114. else ()
  1115. set (PCH_PATHNAME ${CMAKE_CURRENT_BINARY_DIR}/${PCH_FILENAME})
  1116. endif ()
  1117. foreach (FILE ${SOURCE_FILES})
  1118. if (FILE MATCHES \\.${EXT}$)
  1119. if (FILE MATCHES ${NAME_WE}\\.${EXT}$)
  1120. # Precompiling header file
  1121. set_property (SOURCE ${FILE} APPEND_STRING PROPERTY COMPILE_FLAGS " /Fp${PCH_PATHNAME} /Yc${HEADER_FILENAME}") # Need a leading space for appending
  1122. else ()
  1123. # Using precompiled header file
  1124. set_property (SOURCE ${FILE} APPEND_STRING PROPERTY COMPILE_FLAGS " /Fp${PCH_PATHNAME} /Yu${HEADER_FILENAME} /FI${HEADER_FILENAME}")
  1125. endif ()
  1126. endif ()
  1127. endforeach ()
  1128. unset (${TARGET_NAME}_HEADER_PATHNAME)
  1129. else ()
  1130. # The target has not been created yet, so set an internal variable to come back here again later
  1131. set (${TARGET_NAME}_HEADER_PATHNAME ${ARGV})
  1132. # But proceed to add the dummy C++ or C implementation file if necessary
  1133. set (${LANG}_FILENAME ${NAME_WE}.${EXT})
  1134. get_filename_component (PATH ${HEADER_PATHNAME} PATH)
  1135. if (PATH)
  1136. set (PATH ${PATH}/)
  1137. endif ()
  1138. list (FIND SOURCE_FILES ${PATH}${${LANG}_FILENAME} ${LANG}_FILENAME_FOUND)
  1139. if (${LANG}_FILENAME_FOUND STREQUAL -1)
  1140. if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${${LANG}_FILENAME})
  1141. # Only generate it once so that its timestamp is not touched unnecessarily
  1142. file (WRITE ${CMAKE_CURRENT_BINARY_DIR}/${${LANG}_FILENAME} "// This is a generated file. DO NOT EDIT!\n\n#include \"${HEADER_FILENAME}\"")
  1143. endif ()
  1144. list (INSERT SOURCE_FILES 0 ${${LANG}_FILENAME})
  1145. endif ()
  1146. endif ()
  1147. elseif (XCODE)
  1148. if (TARGET ${TARGET_NAME})
  1149. # Precompiling and using precompiled header file
  1150. set_target_properties (${TARGET_NAME} PROPERTIES XCODE_ATTRIBUTE_GCC_PRECOMPILE_PREFIX_HEADER YES XCODE_ATTRIBUTE_GCC_PREFIX_HEADER ${ABS_HEADER_PATHNAME})
  1151. unset (${TARGET_NAME}_HEADER_PATHNAME)
  1152. else ()
  1153. # The target has not been created yet, so set an internal variable to come back here again later
  1154. set (${TARGET_NAME}_HEADER_PATHNAME ${ARGV})
  1155. endif ()
  1156. else ()
  1157. # GCC or Clang
  1158. if (TARGET ${TARGET_NAME})
  1159. # Precompiling header file
  1160. get_directory_property (COMPILE_DEFINITIONS COMPILE_DEFINITIONS)
  1161. get_directory_property (INCLUDE_DIRECTORIES INCLUDE_DIRECTORIES)
  1162. get_target_property (TYPE ${TARGET_NAME} TYPE)
  1163. if (TYPE MATCHES SHARED|MODULE)
  1164. list (APPEND COMPILE_DEFINITIONS ${TARGET_NAME}_EXPORTS)
  1165. if (LANG STREQUAL CXX)
  1166. _test_compiler_hidden_visibility ()
  1167. endif ()
  1168. endif ()
  1169. # Use PIC flags as necessary, except when compiling using MinGW which already uses PIC flags for all codes
  1170. if (NOT MINGW)
  1171. get_target_property (PIC ${TARGET_NAME} POSITION_INDEPENDENT_CODE)
  1172. if (PIC)
  1173. set (PIC_FLAGS -fPIC)
  1174. endif ()
  1175. endif ()
  1176. string (REPLACE ";" " -D" COMPILE_DEFINITIONS "-D${COMPILE_DEFINITIONS}")
  1177. string (REPLACE "\"" "\\\"" COMPILE_DEFINITIONS ${COMPILE_DEFINITIONS})
  1178. string (REPLACE ";" "\" -I\"" INCLUDE_DIRECTORIES "-I\"${INCLUDE_DIRECTORIES}\"")
  1179. if (CMAKE_SYSROOT)
  1180. set (SYSROOT_FLAGS "--sysroot=\"${CMAKE_SYSROOT}\"")
  1181. endif ()
  1182. # Make sure the precompiled headers are not stale by creating custom rules to re-compile the header as necessary
  1183. file (MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${PCH_FILENAME})
  1184. set (ABS_PATH_PCH ${CMAKE_CURRENT_BINARY_DIR}/${HEADER_FILENAME})
  1185. foreach (CONFIG ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE}) # These two vars are mutually exclusive
  1186. # Generate *.rsp containing configuration specific compiler flags
  1187. string (TOUPPER ${CONFIG} UPPERCASE_CONFIG)
  1188. file (WRITE ${ABS_PATH_PCH}.${CONFIG}.pch.rsp.new "${COMPILE_DEFINITIONS} ${SYSROOT_FLAGS} ${CLANG_${LANG}_FLAGS} ${CMAKE_${LANG}_FLAGS} ${CMAKE_${LANG}_FLAGS_${UPPERCASE_CONFIG}} ${COMPILER_HIDDEN_VISIBILITY_FLAGS} ${COMPILER_HIDDEN_INLINE_VISIBILITY_FLAGS} ${PIC_FLAGS} ${INCLUDE_DIRECTORIES} -c -x ${LANG_H}")
  1189. execute_process (COMMAND ${CMAKE_COMMAND} -E copy_if_different ${ABS_PATH_PCH}.${CONFIG}.pch.rsp.new ${ABS_PATH_PCH}.${CONFIG}.pch.rsp)
  1190. file (REMOVE ${ABS_PATH_PCH}.${CONFIG}.pch.rsp.new)
  1191. if (NOT ${TARGET_NAME}_PCH_DEPS)
  1192. if (NOT CMAKE_CURRENT_SOURCE_DIR EQUAL CMAKE_CURRENT_BINARY_DIR)
  1193. # Create a dummy initial PCH file in the Out-of-source build tree to keep CLion happy
  1194. execute_process (COMMAND ${CMAKE_COMMAND} -E touch ${ABS_PATH_PCH})
  1195. endif ()
  1196. # Determine the dependency list
  1197. execute_process (COMMAND ${CMAKE_${LANG}_COMPILER} @${ABS_PATH_PCH}.${CONFIG}.pch.rsp -MTdeps -MM -MF ${ABS_PATH_PCH}.d ${ABS_HEADER_PATHNAME} RESULT_VARIABLE ${LANG}_COMPILER_EXIT_CODE)
  1198. if (NOT ${LANG}_COMPILER_EXIT_CODE EQUAL 0)
  1199. message (FATAL_ERROR "Could not generate dependency list for PCH. There is something wrong with your compiler toolchain. "
  1200. "Ensure its bin path is in the PATH environment variable or ensure CMake can find CC/CXX in your build environment.")
  1201. endif ()
  1202. file (STRINGS ${ABS_PATH_PCH}.d ${TARGET_NAME}_PCH_DEPS)
  1203. string (REGEX REPLACE "^deps: *| *\\; *" ";" ${TARGET_NAME}_PCH_DEPS ${${TARGET_NAME}_PCH_DEPS})
  1204. string (REGEX REPLACE "\\\\ " "\ " ${TARGET_NAME}_PCH_DEPS "${${TARGET_NAME}_PCH_DEPS}") # Need to stringify the second time to preserve the semicolons
  1205. endif ()
  1206. # Create the rule that depends on the included headers
  1207. add_custom_command (OUTPUT ${HEADER_FILENAME}.${CONFIG}.pch.trigger
  1208. COMMAND ${CMAKE_${LANG}_COMPILER} @${ABS_PATH_PCH}.${CONFIG}.pch.rsp -o ${PCH_FILENAME}/${PCH_FILENAME}.${CONFIG} ${ABS_HEADER_PATHNAME}
  1209. COMMAND ${CMAKE_COMMAND} -E touch ${HEADER_FILENAME}.${CONFIG}.pch.trigger
  1210. DEPENDS ${ABS_PATH_PCH}.${CONFIG}.pch.rsp ${${TARGET_NAME}_PCH_DEPS}
  1211. COMMENT "Precompiling header file '${HEADER_FILENAME}' for ${CONFIG} configuration")
  1212. add_make_clean_files (${PCH_FILENAME}/${PCH_FILENAME}.${CONFIG})
  1213. endforeach ()
  1214. # Using precompiled header file
  1215. set (CMAKE_${LANG}_FLAGS "${CMAKE_${LANG}_FLAGS} -include \"${ABS_PATH_PCH}\"")
  1216. unset (${TARGET_NAME}_HEADER_PATHNAME)
  1217. else ()
  1218. # The target has not been created yet, so set an internal variable to come back here again later
  1219. set (${TARGET_NAME}_HEADER_PATHNAME ${ARGV})
  1220. # But proceed to add the dummy source file(s) to trigger the custom command output rule
  1221. if (CMAKE_CONFIGURATION_TYPES)
  1222. # Multi-config, trigger all rules and let the compiler to choose which precompiled header is suitable to use
  1223. foreach (CONFIG ${CMAKE_CONFIGURATION_TYPES})
  1224. list (APPEND TRIGGERS ${HEADER_FILENAME}.${CONFIG}.pch.trigger)
  1225. endforeach ()
  1226. else ()
  1227. # Single-config, just trigger the corresponding rule matching the current build configuration
  1228. set (TRIGGERS ${HEADER_FILENAME}.${CMAKE_BUILD_TYPE}.pch.trigger)
  1229. endif ()
  1230. list (APPEND SOURCE_FILES ${TRIGGERS})
  1231. endif ()
  1232. endif ()
  1233. endif ()
  1234. endmacro ()
  1235. # Macro for finding file in Urho3D build tree or Urho3D SDK
  1236. macro (find_Urho3D_file VAR NAME)
  1237. # Pass the arguments to the actual find command
  1238. cmake_parse_arguments (ARG "" "DOC;MSG_MODE" "HINTS;PATHS;PATH_SUFFIXES" ${ARGN})
  1239. find_file (${VAR} ${NAME} HINTS ${ARG_HINTS} PATHS ${ARG_PATHS} PATH_SUFFIXES ${ARG_PATH_SUFFIXES} DOC ${ARG_DOC} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
  1240. mark_as_advanced (${VAR}) # Hide it from cmake-gui in non-advanced mode
  1241. if (NOT ${VAR} AND ARG_MSG_MODE)
  1242. message (${ARG_MSG_MODE}
  1243. "Could not find ${VAR} file in the Urho3D build tree or Urho3D SDK. "
  1244. "Please reconfigure and rebuild your Urho3D build tree or reinstall the SDK for the correct target platform.")
  1245. endif ()
  1246. endmacro ()
  1247. # Macro for finding tool in Urho3D build tree or Urho3D SDK
  1248. macro (find_Urho3D_tool VAR NAME)
  1249. # Pass the arguments to the actual find command
  1250. cmake_parse_arguments (ARG "" "DOC;MSG_MODE" "HINTS;PATHS;PATH_SUFFIXES" ${ARGN})
  1251. find_program (${VAR} ${NAME} HINTS ${ARG_HINTS} PATHS ${ARG_PATHS} PATH_SUFFIXES ${ARG_PATH_SUFFIXES} DOC ${ARG_DOC} NO_DEFAULT_PATH)
  1252. mark_as_advanced (${VAR}) # Hide it from cmake-gui in non-advanced mode
  1253. if (NOT ${VAR})
  1254. set (${VAR} ${CMAKE_BINARY_DIR}/bin/tool/${NAME})
  1255. if (ARG_MSG_MODE AND NOT CMAKE_PROJECT_NAME STREQUAL Urho3D)
  1256. message (${ARG_MSG_MODE}
  1257. "Could not find ${VAR} tool in the Urho3D build tree or Urho3D SDK. Your project may not build successfully without this tool. "
  1258. "You may have to first rebuild the Urho3D in its build tree or reinstall Urho3D SDK to get this tool built or installed properly. "
  1259. "Alternatively, copy the ${VAR} executable manually into bin/tool subdirectory in your own project build tree.")
  1260. endif ()
  1261. endif ()
  1262. endmacro ()
  1263. # Macro for setting up header files installation for the SDK and the build tree (only support subset of install command arguments)
  1264. # FILES <list> - File list to be installed
  1265. # DIRECTORY <list> - Directory list to be installed
  1266. # FILES_MATCHING - Option to perform file pattern matching on DIRECTORY list
  1267. # USE_FILE_SYMLINK - Option to use file symlinks on the matched files found in the DIRECTORY list
  1268. # BUILD_TREE_ONLY - Option to install the header files into the build tree only
  1269. # PATTERN <list> - Pattern list to be used in file pattern matching option
  1270. # BASE <value> - An absolute base path to be prepended to the destination path when installing to build tree, default to build tree
  1271. # DESTINATION <value> - A relative destination path to be installed to
  1272. # ACCUMULATE <value> - Accumulate the header files into the specified CMake variable, implies USE_FILE_SYMLINK when input list is a directory
  1273. macro (install_header_files)
  1274. # Need to check if the destination variable is defined first because this macro could be called by downstream project that does not wish to install anything
  1275. if (DEST_INCLUDE_DIR)
  1276. # Parse the arguments for the underlying install command for the SDK
  1277. cmake_parse_arguments (ARG "FILES_MATCHING;USE_FILE_SYMLINK;BUILD_TREE_ONLY" "BASE;DESTINATION;ACCUMULATE" "FILES;DIRECTORY;PATTERN" ${ARGN})
  1278. unset (INSTALL_MATCHING)
  1279. if (ARG_FILES)
  1280. set (INSTALL_TYPE FILES)
  1281. set (INSTALL_SOURCES ${ARG_FILES})
  1282. elseif (ARG_DIRECTORY)
  1283. set (INSTALL_TYPE DIRECTORY)
  1284. set (INSTALL_SOURCES ${ARG_DIRECTORY})
  1285. if (ARG_FILES_MATCHING)
  1286. set (INSTALL_MATCHING FILES_MATCHING)
  1287. # Our macro supports PATTERN <list> but CMake's install command does not, so convert the list to: PATTERN <value1> PATTERN <value2> ...
  1288. foreach (PATTERN ${ARG_PATTERN})
  1289. list (APPEND INSTALL_MATCHING PATTERN ${PATTERN})
  1290. endforeach ()
  1291. endif ()
  1292. else ()
  1293. message (FATAL_ERROR "Couldn't setup install command because the install type is not specified.")
  1294. endif ()
  1295. if (NOT ARG_DESTINATION)
  1296. message (FATAL_ERROR "Couldn't setup install command because the install destination is not specified.")
  1297. endif ()
  1298. if (NOT ARG_BUILD_TREE_ONLY AND NOT CMAKE_PROJECT_NAME MATCHES ^Urho3D-ExternalProject-)
  1299. install (${INSTALL_TYPE} ${INSTALL_SOURCES} DESTINATION ${ARG_DESTINATION} ${INSTALL_MATCHING})
  1300. endif ()
  1301. # Reparse the arguments for the create_symlink macro to "install" the header files in the build tree
  1302. if (NOT ARG_BASE)
  1303. set (ARG_BASE ${CMAKE_BINARY_DIR}) # Use build tree as base path
  1304. endif ()
  1305. foreach (INSTALL_SOURCE ${INSTALL_SOURCES})
  1306. if (NOT IS_ABSOLUTE ${INSTALL_SOURCE})
  1307. set (INSTALL_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/${INSTALL_SOURCE})
  1308. endif ()
  1309. if (INSTALL_SOURCE MATCHES /$)
  1310. # Source is a directory
  1311. if (ARG_USE_FILE_SYMLINK OR ARG_ACCUMULATE OR BASH_ON_WINDOWS)
  1312. # Use file symlink for each individual files in the source directory
  1313. if (IS_SYMLINK ${ARG_DESTINATION} AND NOT CMAKE_HOST_WIN32)
  1314. execute_process (COMMAND ${CMAKE_COMMAND} -E remove ${ARG_DESTINATION})
  1315. endif ()
  1316. set (GLOBBING_EXPRESSION RELATIVE ${INSTALL_SOURCE})
  1317. if (ARG_FILES_MATCHING)
  1318. foreach (PATTERN ${ARG_PATTERN})
  1319. list (APPEND GLOBBING_EXPRESSION ${INSTALL_SOURCE}${PATTERN})
  1320. endforeach ()
  1321. else ()
  1322. list (APPEND GLOBBING_EXPRESSION ${INSTALL_SOURCE}*)
  1323. endif ()
  1324. file (GLOB_RECURSE NAMES ${GLOBBING_EXPRESSION})
  1325. foreach (NAME ${NAMES})
  1326. get_filename_component (PATH ${ARG_DESTINATION}/${NAME} PATH)
  1327. # Recreate the source directory structure in the destination path
  1328. if (NOT EXISTS ${ARG_BASE}/${PATH})
  1329. file (MAKE_DIRECTORY ${ARG_BASE}/${PATH})
  1330. endif ()
  1331. create_symlink (${INSTALL_SOURCE}${NAME} ${ARG_DESTINATION}/${NAME} FALLBACK_TO_COPY)
  1332. if (ARG_ACCUMULATE)
  1333. list (APPEND ${ARG_ACCUMULATE} ${ARG_DESTINATION}/${NAME})
  1334. endif ()
  1335. endforeach ()
  1336. else ()
  1337. # Use a single symlink pointing to the source directory
  1338. if (NOT IS_SYMLINK ${ARG_DESTINATION} AND NOT CMAKE_HOST_WIN32)
  1339. execute_process (COMMAND ${CMAKE_COMMAND} -E remove_directory ${ARG_DESTINATION})
  1340. endif ()
  1341. create_symlink (${INSTALL_SOURCE} ${ARG_DESTINATION} FALLBACK_TO_COPY)
  1342. endif ()
  1343. else ()
  1344. # Source is a file (it could also be actually a directory to be treated as a "file", i.e. for creating symlink pointing to the directory)
  1345. get_filename_component (NAME ${INSTALL_SOURCE} NAME)
  1346. create_symlink (${INSTALL_SOURCE} ${ARG_DESTINATION}/${NAME} FALLBACK_TO_COPY)
  1347. if (ARG_ACCUMULATE)
  1348. list (APPEND ${ARG_ACCUMULATE} ${ARG_DESTINATION}/${NAME})
  1349. endif ()
  1350. endif ()
  1351. endforeach ()
  1352. endif ()
  1353. endmacro ()
  1354. # Macro for setting common output directories
  1355. macro (set_output_directories OUTPUT_PATH)
  1356. cmake_parse_arguments (ARG LOCAL "" "" ${ARGN})
  1357. if (ARG_LOCAL)
  1358. unset (SCOPE)
  1359. unset (OUTPUT_DIRECTORY_PROPERTIES)
  1360. else ()
  1361. set (SCOPE CMAKE_)
  1362. endif ()
  1363. foreach (TYPE ${ARG_UNPARSED_ARGUMENTS})
  1364. set (${SCOPE}${TYPE}_OUTPUT_DIRECTORY ${OUTPUT_PATH})
  1365. list (APPEND OUTPUT_DIRECTORY_PROPERTIES ${TYPE}_OUTPUT_DIRECTORY ${${TYPE}_OUTPUT_DIRECTORY})
  1366. foreach (CONFIG ${CMAKE_CONFIGURATION_TYPES})
  1367. string (TOUPPER ${CONFIG} CONFIG)
  1368. set (${SCOPE}${TYPE}_OUTPUT_DIRECTORY_${CONFIG} ${OUTPUT_PATH})
  1369. list (APPEND OUTPUT_DIRECTORY_PROPERTIES ${TYPE}_OUTPUT_DIRECTORY_${CONFIG} ${${TYPE}_OUTPUT_DIRECTORY_${CONFIG}})
  1370. endforeach ()
  1371. if (TYPE STREQUAL RUNTIME AND NOT ${OUTPUT_PATH} STREQUAL .)
  1372. file (RELATIVE_PATH REL_OUTPUT_PATH ${CMAKE_BINARY_DIR} ${OUTPUT_PATH})
  1373. set (DEST_RUNTIME_DIR ${REL_OUTPUT_PATH})
  1374. endif ()
  1375. endforeach ()
  1376. if (ARG_LOCAL)
  1377. list (APPEND TARGET_PROPERTIES ${OUTPUT_DIRECTORY_PROPERTIES})
  1378. endif ()
  1379. endmacro ()
  1380. # Macro for setting up an executable target
  1381. # Macro arguments:
  1382. # PRIVATE - setup executable target without installing it
  1383. # TOOL - setup a tool executable target
  1384. # NODEPS - setup executable target without defining Urho3D dependency libraries
  1385. # WIN32/MACOSX_BUNDLE/EXCLUDE_FROM_ALL - see CMake help on add_executable() command
  1386. # CMake variables:
  1387. # SOURCE_FILES - list of source files
  1388. # INCLUDE_DIRS - list of directories for include search path
  1389. # LIBS - list of dependent libraries that are built internally in the project
  1390. # ABSOLUTE_PATH_LIBS - list of dependent libraries that are external to the project
  1391. # LINK_DEPENDS - list of additional files on which a target binary depends for linking (Makefile-based generator only)
  1392. # LINK_FLAGS - list of additional link flags
  1393. # TARGET_PROPERTIES - list of target properties
  1394. macro (setup_executable)
  1395. cmake_parse_arguments (ARG "PRIVATE;TOOL;NODEPS" "" "" ${ARGN})
  1396. check_source_files ()
  1397. add_executable (${TARGET_NAME} ${ARG_UNPARSED_ARGUMENTS} ${SOURCE_FILES})
  1398. set (RUNTIME_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
  1399. if (ARG_PRIVATE)
  1400. set_output_directories (. LOCAL RUNTIME PDB)
  1401. set (RUNTIME_DIR .)
  1402. endif ()
  1403. if (ARG_TOOL)
  1404. list (APPEND TARGET_PROPERTIES XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH YES)
  1405. if (NOT ARG_PRIVATE AND NOT DEST_RUNTIME_DIR MATCHES tool)
  1406. set_output_directories (${CMAKE_BINARY_DIR}/bin/tool LOCAL RUNTIME PDB)
  1407. set (RUNTIME_DIR ${CMAKE_BINARY_DIR}/bin/tool)
  1408. endif ()
  1409. endif ()
  1410. if (NOT ARG_NODEPS)
  1411. define_dependency_libs (Urho3D)
  1412. endif ()
  1413. if (XCODE AND LUAJIT_EXE_LINKER_FLAGS_APPLE)
  1414. # Xcode universal build linker flags when targeting 64-bit OSX with LuaJIT enabled
  1415. list (APPEND TARGET_PROPERTIES XCODE_ATTRIBUTE_OTHER_LDFLAGS[arch=x86_64] "${LUAJIT_EXE_LINKER_FLAGS_APPLE} $(OTHER_LDFLAGS)")
  1416. endif ()
  1417. _setup_target ()
  1418. if (URHO3D_SCP_TO_TARGET)
  1419. add_custom_command (TARGET ${TARGET_NAME} POST_BUILD COMMAND scp $<TARGET_FILE:${TARGET_NAME}> ${URHO3D_SCP_TO_TARGET} || exit 0
  1420. COMMENT "Scp-ing ${TARGET_NAME} executable to target system")
  1421. endif ()
  1422. if (WIN32 AND NOT ARG_NODEPS AND URHO3D_LIB_TYPE STREQUAL SHARED)
  1423. # Make a copy of the Urho3D DLL to the runtime directory in the build tree
  1424. if (TARGET Urho3D)
  1425. add_custom_command (TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:Urho3D> ${RUNTIME_DIR})
  1426. add_make_clean_files (${RUNTIME_DIR}/$<TARGET_FILE_NAME:Urho3D>)
  1427. else ()
  1428. foreach (DLL ${URHO3D_DLL})
  1429. add_custom_command (TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DLL} ${RUNTIME_DIR})
  1430. add_make_clean_files (${RUNTIME_DIR}/${DLL})
  1431. endforeach ()
  1432. endif ()
  1433. endif ()
  1434. if (DIRECT3D_DLL AND NOT ARG_NODEPS)
  1435. # Make a copy of the D3D DLL to the runtime directory in the build tree
  1436. add_custom_command (TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DIRECT3D_DLL} ${RUNTIME_DIR})
  1437. add_make_clean_files (${RUNTIME_DIR}/${DIRECT3D_DLL})
  1438. endif ()
  1439. # Need to check if the destination variable is defined first because this macro could be called by downstream project that does not wish to install anything
  1440. if (NOT ARG_PRIVATE)
  1441. if (WEB AND DEST_BUNDLE_DIR)
  1442. set (EXTS data html.map js wasm)
  1443. if (SELF_EXECUTABLE_SHELL)
  1444. # Install it as program so it gets the correct file permission
  1445. install (PROGRAMS $<TARGET_FILE:${TARGET_NAME}> DESTINATION ${DEST_BUNDLE_DIR})
  1446. else ()
  1447. list (APPEND EXTS html)
  1448. endif ()
  1449. set (LOCATION $<TARGET_FILE_DIR:${TARGET_NAME}>)
  1450. unset (FILES)
  1451. foreach (EXT ${EXTS})
  1452. list (APPEND FILES ${LOCATION}/${TARGET_NAME}.${EXT})
  1453. endforeach ()
  1454. install (FILES ${FILES} DESTINATION ${DEST_BUNDLE_DIR} OPTIONAL)
  1455. elseif (DEST_RUNTIME_DIR AND (DEST_BUNDLE_DIR OR NOT (IOS OR TVOS)))
  1456. install (TARGETS ${TARGET_NAME} RUNTIME DESTINATION ${DEST_RUNTIME_DIR} BUNDLE DESTINATION ${DEST_BUNDLE_DIR})
  1457. if (WIN32 AND NOT ARG_NODEPS AND URHO3D_LIB_TYPE STREQUAL SHARED AND NOT URHO3D_DLL_INSTALLED)
  1458. if (TARGET Urho3D)
  1459. install (FILES $<TARGET_FILE:Urho3D> DESTINATION ${DEST_RUNTIME_DIR})
  1460. else ()
  1461. install (FILES ${URHO3D_DLL} DESTINATION ${DEST_RUNTIME_DIR})
  1462. endif ()
  1463. set (URHO3D_DLL_INSTALLED TRUE)
  1464. endif ()
  1465. if (DIRECT3D_DLL AND NOT DIRECT3D_DLL_INSTALLED)
  1466. # Make a copy of the D3D DLL to the runtime directory in the installed location
  1467. install (FILES ${DIRECT3D_DLL} DESTINATION ${DEST_RUNTIME_DIR})
  1468. set (DIRECT3D_DLL_INSTALLED TRUE)
  1469. endif ()
  1470. endif ()
  1471. endif ()
  1472. endmacro ()
  1473. # Macro for setting up a library target
  1474. # Macro arguments:
  1475. # NODEPS - setup library target without defining Urho3D dependency libraries (applicable for downstream projects)
  1476. # STATIC/SHARED/MODULE/EXCLUDE_FROM_ALL - see CMake help on add_library() command
  1477. # CMake variables:
  1478. # SOURCE_FILES - list of source files
  1479. # INCLUDE_DIRS - list of directories for include search path
  1480. # LIBS - list of dependent libraries that are built internally in the project
  1481. # ABSOLUTE_PATH_LIBS - list of dependent libraries that are external to the project
  1482. # LINK_DEPENDS - list of additional files on which a target binary depends for linking (Makefile-based generator only)
  1483. # LINK_FLAGS - list of additional link flags
  1484. # TARGET_PROPERTIES - list of target properties
  1485. macro (setup_library)
  1486. cmake_parse_arguments (ARG NODEPS "" "" ${ARGN})
  1487. check_source_files ()
  1488. add_library (${TARGET_NAME} ${ARG_UNPARSED_ARGUMENTS} ${SOURCE_FILES})
  1489. get_target_property (LIB_TYPE ${TARGET_NAME} TYPE)
  1490. if (NOT ARG_NODEPS AND NOT PROJECT_NAME STREQUAL Urho3D)
  1491. define_dependency_libs (Urho3D)
  1492. endif ()
  1493. if (XCODE AND LUAJIT_SHARED_LINKER_FLAGS_APPLE AND LIB_TYPE STREQUAL SHARED_LIBRARY)
  1494. list (APPEND TARGET_PROPERTIES XCODE_ATTRIBUTE_OTHER_LDFLAGS[arch=x86_64] "${LUAJIT_SHARED_LINKER_FLAGS_APPLE} $(OTHER_LDFLAGS)") # Xcode universal build linker flags when targeting 64-bit OSX with LuaJIT enabled
  1495. endif ()
  1496. _setup_target ()
  1497. if (PROJECT_NAME STREQUAL Urho3D)
  1498. # Accumulate all the dependent static libraries that are used in building the Urho3D library itself
  1499. if (NOT ${TARGET_NAME} STREQUAL Urho3D AND LIB_TYPE STREQUAL STATIC_LIBRARY)
  1500. set (STATIC_LIBRARY_TARGETS ${STATIC_LIBRARY_TARGETS} ${TARGET_NAME} PARENT_SCOPE)
  1501. # When performing Xcode CI build suppress all the warnings for 3rd party libraries because there are just too many of them
  1502. if (XCODE AND DEFINED ENV{CI})
  1503. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w")
  1504. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w")
  1505. endif ()
  1506. endif ()
  1507. elseif (URHO3D_SCP_TO_TARGET)
  1508. add_custom_command (TARGET ${TARGET_NAME} POST_BUILD COMMAND scp $<TARGET_FILE:${TARGET_NAME}> ${URHO3D_SCP_TO_TARGET} || exit 0
  1509. COMMENT "Scp-ing ${TARGET_NAME} library to target system")
  1510. endif ()
  1511. endmacro ()
  1512. # Macro for setting up an executable target with resources to copy/package/bundle/preload
  1513. # Macro arguments:
  1514. # NODEPS - setup executable target without defining Urho3D dependency libraries
  1515. # NOBUNDLE - do not use MACOSX_BUNDLE even when URHO3D_MACOSX_BUNDLE build option is enabled
  1516. # WIN32/MACOSX_BUNDLE/EXCLUDE_FROM_ALL - see CMake help on add_executable() command
  1517. # CMake variables:
  1518. # RESOURCE_DIRS - list of resource directories (will be packaged into *.pak when URHO3D_PACKAGING build option is set)
  1519. # RESOURCE_FILES - list of additional resource files (will not be packaged into *.pak in any case)
  1520. # SOURCE_FILES - list of source files
  1521. # INCLUDE_DIRS - list of directories for include search path
  1522. # LIBS - list of dependent libraries that are built internally in the project
  1523. # ABSOLUTE_PATH_LIBS - list of dependent libraries that are external to the project
  1524. # LINK_DEPENDS - list of additional files on which a target binary depends for linking (Makefile-based generator only)
  1525. # LINK_FLAGS - list of additional link flags
  1526. # TARGET_PROPERTIES - list of target properties
  1527. macro (setup_main_executable)
  1528. cmake_parse_arguments (ARG "NOBUNDLE;MACOSX_BUNDLE;WIN32" "" "" ${ARGN})
  1529. if (NOT RESOURCE_DIRS)
  1530. define_resource_dirs ()
  1531. endif ()
  1532. if (ANDROID)
  1533. # Add SDL native init function, SDL_Main() entry point must be defined by one of the source files in ${SOURCE_FILES}
  1534. find_Urho3D_file (ANDROID_MAIN_C_PATH SDL_android_main.c
  1535. HINTS ${URHO3D_HOME}/include/Urho3D/ThirdParty/SDL/android ${CMAKE_SOURCE_DIR}/Source/ThirdParty/SDL/src/main/android
  1536. DOC "Path to SDL_android_main.c" MSG_MODE FATAL_ERROR)
  1537. list (APPEND SOURCE_FILES ${ANDROID_MAIN_C_PATH})
  1538. # Setup shared library output path
  1539. set_output_directories (${CMAKE_BINARY_DIR}/libs/${ANDROID_NDK_ABI_NAME} LIBRARY)
  1540. # Setup target as main shared library
  1541. setup_library (SHARED)
  1542. if (DEST_LIBRARY_DIR)
  1543. install (TARGETS ${TARGET_NAME} LIBRARY DESTINATION ${DEST_LIBRARY_DIR} ARCHIVE DESTINATION ${DEST_LIBRARY_DIR})
  1544. endif ()
  1545. # Copy other dependent shared libraries to Android library output path
  1546. if (ANDROID_STL MATCHES shared)
  1547. # Android toolchain may already copy a shared C++ STL runtime to library output path,
  1548. # still we configure another post build command to copy the runtime and its clean up here for consistency sake
  1549. add_custom_command (TARGET ${TARGET_NAME} POST_BUILD
  1550. COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${STL_LIBRARY_DIR}/lib${ANDROID_STL}.so ${CMAKE_BINARY_DIR}/libs/${ANDROID_NDK_ABI_NAME}/lib${ANDROID_STL}.so)
  1551. add_make_clean_files (${CMAKE_BINARY_DIR}/libs/${ANDROID_NDK_ABI_NAME}/lib${ANDROID_STL}.so)
  1552. endif ()
  1553. foreach (FILE ${ABSOLUTE_PATH_LIBS})
  1554. get_filename_component (EXT ${FILE} EXT)
  1555. if (EXT STREQUAL .so)
  1556. get_filename_component (NAME ${FILE} NAME)
  1557. add_custom_command (TARGET ${TARGET_NAME} POST_BUILD
  1558. COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${FILE} ${CMAKE_BINARY_DIR}/libs/${ANDROID_NDK_ABI_NAME}
  1559. COMMENT "Copying ${NAME} to library output directory")
  1560. add_make_clean_files (${CMAKE_BINARY_DIR}/libs/${ANDROID_NDK_ABI_NAME}/${NAME})
  1561. endif ()
  1562. endforeach ()
  1563. if (ANDROID_NDK_GDB)
  1564. # Copy the library while it still has debug symbols for ndk-gdb
  1565. add_custom_command (TARGET ${TARGET_NAME} POST_BUILD
  1566. COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:${TARGET_NAME}> ${NDK_GDB_SOLIB_PATH}
  1567. COMMENT "Copying lib${TARGET_NAME}.so with debug symbols to ${NDK_GDB_SOLIB_PATH} directory")
  1568. add_make_clean_files (${NDK_GDB_SOLIB_PATH}/$<TARGET_FILE_NAME:${TARGET_NAME}>)
  1569. endif ()
  1570. # When performing packaging, include the final apk file
  1571. if (CMAKE_PROJECT_NAME STREQUAL Urho3D AND NOT APK_INCLUDED)
  1572. install (FILES ${LIBRARY_OUTPUT_PATH_ROOT}/bin/Urho3D-debug.apk DESTINATION ${DEST_RUNTIME_DIR} OPTIONAL)
  1573. set (APK_INCLUDED 1)
  1574. endif ()
  1575. else ()
  1576. # Setup target as executable
  1577. if (WIN32)
  1578. if (NOT URHO3D_WIN32_CONSOLE OR ARG_WIN32)
  1579. set (EXE_TYPE WIN32)
  1580. endif ()
  1581. list (APPEND TARGET_PROPERTIES DEBUG_POSTFIX _d)
  1582. elseif (IOS)
  1583. set (EXE_TYPE MACOSX_BUNDLE)
  1584. list (APPEND TARGET_PROPERTIES XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY 1,2 MACOSX_BUNDLE_INFO_PLIST iOSBundleInfo.plist.template)
  1585. elseif (TVOS)
  1586. set (EXE_TYPE MACOSX_BUNDLE)
  1587. list (APPEND TARGET_PROPERTIES XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY 3 MACOSX_BUNDLE_INFO_PLIST tvOSBundleInfo.plist.template)
  1588. elseif (APPLE)
  1589. if ((URHO3D_MACOSX_BUNDLE OR ARG_MACOSX_BUNDLE) AND NOT ARG_NOBUNDLE)
  1590. set (EXE_TYPE MACOSX_BUNDLE)
  1591. list (APPEND TARGET_PROPERTIES MACOSX_BUNDLE_INFO_PLIST MacOSXBundleInfo.plist.template)
  1592. endif ()
  1593. elseif (WEB)
  1594. if (EMSCRIPTEN)
  1595. # Output to HTML when a HTML shell-file is being added in source files list
  1596. foreach (FILE ${SOURCE_FILES})
  1597. get_property (EMCC_OPTION SOURCE ${FILE} PROPERTY EMCC_OPTION)
  1598. if (EMCC_OPTION STREQUAL shell-file)
  1599. list (APPEND TARGET_PROPERTIES SUFFIX .html)
  1600. # Check if the shell-file is self-executable
  1601. file (READ ${FILE} SHEBANG LIMIT 3) # Workaround CMake's funny way of file I/O operation
  1602. string (COMPARE EQUAL ${SHEBANG} "#!\n" SELF_EXECUTABLE_SHELL)
  1603. set (HAS_SHELL_FILE 1)
  1604. break ()
  1605. endif ()
  1606. endforeach ()
  1607. if (URHO3D_TESTING)
  1608. # Auto adding the HTML shell-file during testing with emrun, if it has not been added yet
  1609. if (NOT EMCC_OPTION STREQUAL shell-file)
  1610. add_html_shell ()
  1611. list (APPEND TARGET_PROPERTIES SUFFIX .html)
  1612. set (SELF_EXECUTABLE_SHELL 1)
  1613. set (HAS_SHELL_FILE 1)
  1614. endif ()
  1615. endif ()
  1616. endif ()
  1617. endif ()
  1618. setup_executable (${EXE_TYPE} ${ARG_UNPARSED_ARGUMENTS})
  1619. if (HAS_SHELL_FILE)
  1620. get_target_property (LOCATION ${TARGET_NAME} LOCATION)
  1621. get_filename_component (NAME_WE ${LOCATION} NAME_WE)
  1622. add_make_clean_files ($<TARGET_FILE_DIR:${TARGET_NAME}>/${NAME_WE}.js $<TARGET_FILE_DIR:${TARGET_NAME}>/${NAME_WE}.wasm)
  1623. endif ()
  1624. endif ()
  1625. # Setup custom resource checker target
  1626. if ((EXE_TYPE STREQUAL MACOSX_BUNDLE OR URHO3D_PACKAGING) AND RESOURCE_DIRS)
  1627. if (URHO3D_PACKAGING)
  1628. # Urho3D project builds the PackageTool as required; downstream project uses PackageTool found in the Urho3D build tree or Urho3D SDK
  1629. find_Urho3d_tool (PACKAGE_TOOL PackageTool
  1630. HINTS ${CMAKE_BINARY_DIR}/bin/tool ${URHO3D_HOME}/bin/tool
  1631. DOC "Path to PackageTool" MSG_MODE WARNING)
  1632. if (CMAKE_PROJECT_NAME STREQUAL Urho3D)
  1633. set (PACKAGING_DEP DEPENDS PackageTool)
  1634. endif ()
  1635. set (PACKAGING_COMMENT " and packaging")
  1636. endif ()
  1637. # Share a same custom target that checks for a same resource dirs list
  1638. foreach (DIR ${RESOURCE_DIRS})
  1639. string (MD5 MD5 ${DIR})
  1640. set (MD5ALL ${MD5ALL}${MD5})
  1641. if (CMAKE_HOST_WIN32)
  1642. # On Windows host, always assumes there are changes so resource dirs would be repackaged in each build, however, still make sure the *.pak timestamp is not altered unnecessarily
  1643. if (URHO3D_PACKAGING)
  1644. set (PACKAGING_COMMAND && echo Packaging ${DIR}... && ${PACKAGE_TOOL} ${DIR} ${RESOURCE_${DIR}_PATHNAME}.new -c -q && ${CMAKE_COMMAND} -E copy_if_different ${RESOURCE_${DIR}_PATHNAME}.new ${RESOURCE_${DIR}_PATHNAME} && ${CMAKE_COMMAND} -E remove ${RESOURCE_${DIR}_PATHNAME}.new)
  1645. endif ()
  1646. list (APPEND COMMANDS COMMAND ${CMAKE_COMMAND} -E touch ${DIR} ${PACKAGING_COMMAND})
  1647. else ()
  1648. # On Unix-like hosts, detect the changes in the resource directory recursively so they are only repackaged and/or rebundled (Xcode only) as necessary
  1649. if (URHO3D_PACKAGING)
  1650. set (PACKAGING_COMMAND && echo Packaging ${DIR}... && ${PACKAGE_TOOL} ${DIR} ${RESOURCE_${DIR}_PATHNAME} -c -q)
  1651. set (OUTPUT_COMMAND test -e ${RESOURCE_${DIR}_PATHNAME} || \( true ${PACKAGING_COMMAND} \))
  1652. else ()
  1653. set (OUTPUT_COMMAND true) # Nothing to output
  1654. endif ()
  1655. list (APPEND COMMANDS COMMAND echo Checking ${DIR}... && bash -c \"\(\( `find ${DIR} -newer ${DIR} |wc -l` \)\)\" && touch -cm ${DIR} ${PACKAGING_COMMAND} || ${OUTPUT_COMMAND})
  1656. endif ()
  1657. add_make_clean_files (${RESOURCE_${DIR}_PATHNAME})
  1658. endforeach ()
  1659. string (MD5 MD5ALL ${MD5ALL})
  1660. # Ensure the resource check is done before building the main executable target
  1661. if (NOT RESOURCE_CHECK_${MD5ALL})
  1662. set (RESOURCE_CHECK RESOURCE_CHECK)
  1663. while (TARGET ${RESOURCE_CHECK})
  1664. string (RANDOM RANDOM)
  1665. set (RESOURCE_CHECK RESOURCE_CHECK_${RANDOM})
  1666. endwhile ()
  1667. set (RESOURCE_CHECK_${MD5ALL} ${RESOURCE_CHECK} CACHE INTERNAL "Resource check hash map")
  1668. endif ()
  1669. if (NOT TARGET ${RESOURCE_CHECK_${MD5ALL}})
  1670. add_custom_target (${RESOURCE_CHECK_${MD5ALL}} ALL ${COMMANDS} ${PACKAGING_DEP} COMMENT "Checking${PACKAGING_COMMENT} resource directories")
  1671. endif ()
  1672. add_dependencies (${TARGET_NAME} ${RESOURCE_CHECK_${MD5ALL}})
  1673. endif ()
  1674. # Only need to install the resource directories once in case they are referenced by multiple targets
  1675. if (RESOURCE_DIRS AND DEST_SHARE_DIR)
  1676. foreach (DIR ${RESOURCE_DIRS})
  1677. list (FIND INSTALLED_RESOURCE_DIRS ${DIR} FOUND_INDEX)
  1678. if (FOUND_INDEX EQUAL -1)
  1679. install (DIRECTORY ${DIR} DESTINATION ${DEST_SHARE_DIR}/Resources)
  1680. list (APPEND INSTALLED_RESOURCE_DIRS ${DIR})
  1681. endif ()
  1682. # This cache variable is used to keep track of whether a resource directory has been instructed to be installed by CMake or not
  1683. set (INSTALLED_RESOURCE_DIRS ${INSTALLED_RESOURCE_DIRS} CACHE INTERNAL "Installed resource dirs")
  1684. endforeach ()
  1685. endif ()
  1686. # Define a custom command for stripping the main target executable (or shared library for Android) for Release build configuration
  1687. # Exclude multi-config generators, plus MSVC explicitly since it could also be used through NMake which is not multi-config,
  1688. # but MSVC does not have a strip command
  1689. if (CMAKE_BUILD_TYPE STREQUAL Release AND NOT WEB AND NOT MSVC)
  1690. add_custom_command (TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_STRIP} $<TARGET_FILE:${TARGET_NAME}>)
  1691. endif ()
  1692. endmacro ()
  1693. # This cache variable is used to keep track of whether a resource directory has been instructed to be installed by CMake or not
  1694. unset (INSTALLED_RESOURCE_DIRS CACHE)
  1695. # Macro for setting up dependency lib for compilation and linking of a target (to be used internally)
  1696. macro (_setup_target)
  1697. # Include directories
  1698. include_directories (${INCLUDE_DIRS})
  1699. # Link libraries
  1700. define_dependency_libs (${TARGET_NAME})
  1701. target_link_libraries (${TARGET_NAME} ${ABSOLUTE_PATH_LIBS} ${LIBS})
  1702. # Enable PCH if requested
  1703. if (${TARGET_NAME}_HEADER_PATHNAME)
  1704. enable_pch (${${TARGET_NAME}_HEADER_PATHNAME})
  1705. endif ()
  1706. # Extra compiler flags for Xcode which are dynamically changed based on active arch in order to support Mach-O universal binary targets
  1707. # We don't add the ABI flag for Xcode because it automatically passes '-arch i386' compiler flag when targeting 32 bit which does the same thing as '-m32'
  1708. if (XCODE)
  1709. # Speed up build when in Debug configuration by building active arch only
  1710. list (FIND TARGET_PROPERTIES XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH ATTRIBUTE_ALREADY_SET)
  1711. if (ATTRIBUTE_ALREADY_SET EQUAL -1)
  1712. list (APPEND TARGET_PROPERTIES XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH $<$<CONFIG:Debug>:YES>)
  1713. endif ()
  1714. if (NOT URHO3D_SSE)
  1715. # Nullify the Clang default so that it is consistent with GCC
  1716. list (APPEND TARGET_PROPERTIES XCODE_ATTRIBUTE_OTHER_CFLAGS[arch=i386] "-mno-sse $(OTHER_CFLAGS)")
  1717. list (APPEND TARGET_PROPERTIES XCODE_ATTRIBUTE_OTHER_CPLUSPLUSFLAGS[arch=i386] "-mno-sse $(OTHER_CPLUSPLUSFLAGS)")
  1718. endif ()
  1719. endif ()
  1720. # Extra linker flags for Emscripten
  1721. if (EMSCRIPTEN)
  1722. # These flags are set only once either in the main module or main executable
  1723. if ((URHO3D_LIB_TYPE STREQUAL MODULE AND ${TARGET_NAME} STREQUAL Urho3D) OR (NOT URHO3D_LIB_TYPE STREQUAL MODULE AND NOT LIB_TYPE))
  1724. list (APPEND LINK_FLAGS "-s TOTAL_MEMORY=${EMSCRIPTEN_TOTAL_MEMORY}")
  1725. if (EMSCRIPTEN_ALLOW_MEMORY_GROWTH)
  1726. list (APPEND LINK_FLAGS "-s ALLOW_MEMORY_GROWTH=1")
  1727. endif ()
  1728. if (EMSCRIPTEN_SHARE_DATA) # MODULE lib type always have this variable enabled
  1729. list (APPEND LINK_FLAGS "--pre-js \"${CMAKE_BINARY_DIR}/Source/pak-loader.js\"")
  1730. endif ()
  1731. if (URHO3D_TESTING)
  1732. list (APPEND LINK_FLAGS --emrun)
  1733. else ()
  1734. # If not using EMRUN then we need to include the emrun_prejs.js manually in order to process the request parameters as app's arguments correctly
  1735. list (APPEND LINK_FLAGS "--pre-js \"${EMSCRIPTEN_ROOT_PATH}/src/emrun_prejs.js\"")
  1736. endif ()
  1737. endif ()
  1738. # These flags are here instead of in the CMAKE_(EXE|MODULE)_LINKER_FLAGS so that they do not interfere with the auto-detection logic during initial configuration
  1739. if (NOT LIB_TYPE OR LIB_TYPE STREQUAL MODULE)
  1740. list (APPEND LINK_FLAGS "-s NO_EXIT_RUNTIME=1 -s ERROR_ON_UNDEFINED_SYMBOLS=1")
  1741. if (EMSCRIPTEN_WASM)
  1742. list (APPEND LINK_FLAGS "-s WASM=1")
  1743. endif ()
  1744. endif ()
  1745. # Pass EMCC-specifc setting to differentiate between main and side modules
  1746. if (URHO3D_LIB_TYPE STREQUAL MODULE)
  1747. if (${TARGET_NAME} STREQUAL Urho3D)
  1748. # Main module has standard libs statically linked
  1749. list (APPEND LINK_FLAGS "-s MAIN_MODULE=1")
  1750. elseif ((NOT ARG_NODEPS AND NOT LIB_TYPE) OR LIB_TYPE STREQUAL MODULE)
  1751. if (LIB_TYPE)
  1752. set (SIDE_MODULES ${SIDE_MODULES} ${TARGET_NAME} PARENT_SCOPE)
  1753. endif ()
  1754. # Also consider the executable target as another side module but only this scope
  1755. list (APPEND LINK_FLAGS "-s SIDE_MODULE=1")
  1756. list (APPEND SIDE_MODULES ${TARGET_NAME})
  1757. # Define custom commands for post processing the output file to first load the main module before the side module(s)
  1758. add_custom_command (TARGET ${TARGET_NAME} POST_BUILD
  1759. COMMAND ${CMAKE_COMMAND} -E copy_if_different $<$<STREQUAL:${URHO3D_LIBRARIES},Urho3D>:$<TARGET_FILE:Urho3D>>$<$<NOT:$<STREQUAL:${URHO3D_LIBRARIES},Urho3D>>:${URHO3D_LIBRARIES}> $<TARGET_FILE_DIR:${TARGET_NAME}>
  1760. COMMAND ${CMAKE_COMMAND} -E $<$<NOT:$<CONFIG:Debug>>:echo> copy_if_different $<$<STREQUAL:${URHO3D_LIBRARIES},Urho3D>:$<TARGET_FILE:Urho3D>.map>$<$<NOT:$<STREQUAL:${URHO3D_LIBRARIES},Urho3D>>:${URHO3D_LIBRARIES}.map> $<TARGET_FILE_DIR:${TARGET_NAME}> $<$<NOT:$<CONFIG:Debug>>:$<ANGLE-R>${NULL_DEVICE}>
  1761. COMMAND ${CMAKE_COMMAND} -DTARGET_NAME=${TARGET_NAME} -DTARGET_FILE=$<TARGET_FILE:${TARGET_NAME}> -DTARGET_DIR=$<TARGET_FILE_DIR:${TARGET_NAME}> -DHAS_SHELL_FILE=${HAS_SHELL_FILE} -DSIDE_MODULES="${SIDE_MODULES}" -P ${CMAKE_SOURCE_DIR}/CMake/Modules/PostProcessForWebModule.cmake)
  1762. add_make_clean_files ($<TARGET_FILE_DIR:${TARGET_NAME}>/libUrho3D.js $<TARGET_FILE_DIR:${TARGET_NAME}>/libUrho3D.js.map)
  1763. endif ()
  1764. endif ()
  1765. # Pass additional source files to linker with the supported flags, such as: js-library, pre-js, post-js, embed-file, preload-file, shell-file
  1766. foreach (FILE ${SOURCE_FILES})
  1767. get_property (EMCC_OPTION SOURCE ${FILE} PROPERTY EMCC_OPTION)
  1768. if (EMCC_OPTION)
  1769. unset (EMCC_FILE_ALIAS)
  1770. unset (EMCC_EXCLUDE_FILE)
  1771. unset (USE_PRELOAD_CACHE)
  1772. if (EMCC_OPTION STREQUAL embed-file OR EMCC_OPTION STREQUAL preload-file)
  1773. get_property (EMCC_FILE_ALIAS SOURCE ${FILE} PROPERTY EMCC_FILE_ALIAS)
  1774. if (EMCC_FILE_ALIAS)
  1775. set (EMCC_FILE_ALIAS "@\"${EMCC_FILE_ALIAS}\"")
  1776. endif ()
  1777. get_property (EMCC_EXCLUDE_FILE SOURCE ${FILE} PROPERTY EMCC_EXCLUDE_FILE)
  1778. if (EMCC_EXCLUDE_FILE)
  1779. set (EMCC_EXCLUDE_FILE " --exclude-file \"${EMCC_EXCLUDE_FILE}\"")
  1780. else ()
  1781. list (APPEND LINK_DEPENDS ${FILE})
  1782. endif ()
  1783. if (EMCC_OPTION STREQUAL preload-file)
  1784. set (USE_PRELOAD_CACHE " --use-preload-cache")
  1785. endif ()
  1786. endif ()
  1787. list (APPEND LINK_FLAGS "--${EMCC_OPTION} \"${FILE}\"${EMCC_FILE_ALIAS}${EMCC_EXCLUDE_FILE}${USE_PRELOAD_CACHE}")
  1788. endif ()
  1789. endforeach ()
  1790. # If it is a self-executable shell-file then change the file permission of the output file accordingly
  1791. if (SELF_EXECUTABLE_SHELL AND NOT CMAKE_HOST_WIN32)
  1792. add_custom_command (TARGET ${TARGET_NAME} POST_BUILD COMMAND chmod +x $<TARGET_FILE:${TARGET_NAME}>)
  1793. endif ()
  1794. endif ()
  1795. # Set additional linker dependencies (only work for Makefile-based generator according to CMake documentation)
  1796. if (LINK_DEPENDS)
  1797. string (REPLACE ";" "\;" LINK_DEPENDS "${LINK_DEPENDS}") # Stringify for string replacement
  1798. list (APPEND TARGET_PROPERTIES LINK_DEPENDS "${LINK_DEPENDS}") # Stringify with semicolons already escaped
  1799. unset (LINK_DEPENDS)
  1800. endif ()
  1801. # Set additional linker flags
  1802. if (LINK_FLAGS)
  1803. string (REPLACE ";" " " LINK_FLAGS "${LINK_FLAGS}")
  1804. list (APPEND TARGET_PROPERTIES LINK_FLAGS ${LINK_FLAGS})
  1805. unset (LINK_FLAGS)
  1806. endif ()
  1807. if (TARGET_PROPERTIES)
  1808. set_target_properties (${TARGET_NAME} PROPERTIES ${TARGET_PROPERTIES})
  1809. unset (TARGET_PROPERTIES)
  1810. endif ()
  1811. # Create symbolic links in the build tree
  1812. if (ANDROID)
  1813. foreach (I AndroidManifest.xml build.xml custom_rules.xml project.properties src res assets jni)
  1814. if (EXISTS ${CMAKE_SOURCE_DIR}/Android/${I} AND NOT EXISTS ${CMAKE_BINARY_DIR}/${I}) # No-ops when 'Android' is used as build tree
  1815. create_symlink (${CMAKE_SOURCE_DIR}/Android/${I} ${CMAKE_BINARY_DIR}/${I} FALLBACK_TO_COPY)
  1816. endif ()
  1817. endforeach ()
  1818. set (ASSET_ROOT assets)
  1819. else ()
  1820. set (ASSET_ROOT bin)
  1821. endif ()
  1822. if (NOT URHO3D_PACKAGING)
  1823. # Ensure the asset root directory exist before creating the symlinks
  1824. file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/${ASSET_ROOT})
  1825. foreach (I ${RESOURCE_DIRS})
  1826. get_filename_component (NAME ${I} NAME)
  1827. if (NOT EXISTS ${CMAKE_BINARY_DIR}/${ASSET_ROOT}/${NAME} AND EXISTS ${I})
  1828. create_symlink (${I} ${CMAKE_BINARY_DIR}/${ASSET_ROOT}/${NAME} FALLBACK_TO_COPY)
  1829. endif ()
  1830. endforeach ()
  1831. endif ()
  1832. # Workaround CMake/Xcode generator bug where it always appends '/build' path element to SYMROOT attribute and as such the items in Products are always rendered as red in the Xcode as if they are not yet built
  1833. if (NOT DEFINED ENV{TRAVIS})
  1834. if (XCODE AND NOT CMAKE_PROJECT_NAME MATCHES ^Urho3D-ExternalProject-)
  1835. file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/build)
  1836. get_target_property (LOCATION ${TARGET_NAME} LOCATION)
  1837. string (REGEX REPLACE "^.*\\$\\(CONFIGURATION\\)" $(CONFIGURATION) SYMLINK ${LOCATION})
  1838. get_filename_component (DIRECTORY ${SYMLINK} PATH)
  1839. add_custom_command (TARGET ${TARGET_NAME} POST_BUILD
  1840. COMMAND mkdir -p ${DIRECTORY} && ln -sf $<TARGET_FILE:${TARGET_NAME}> ${DIRECTORY}/$<TARGET_FILE_NAME:${TARGET_NAME}>
  1841. WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/build)
  1842. endif ()
  1843. endif ()
  1844. endmacro()
  1845. # Macro for setting up a test case
  1846. macro (setup_test)
  1847. if (URHO3D_TESTING)
  1848. cmake_parse_arguments (ARG "" NAME OPTIONS ${ARGN})
  1849. if (NOT ARG_NAME)
  1850. set (ARG_NAME ${TARGET_NAME})
  1851. endif ()
  1852. list (APPEND ARG_OPTIONS -timeout ${URHO3D_TEST_TIMEOUT})
  1853. if (WEB)
  1854. if (EMSCRIPTEN)
  1855. math (EXPR EMRUN_TIMEOUT "2 * ${URHO3D_TEST_TIMEOUT}")
  1856. add_test (NAME ${ARG_NAME} COMMAND ${EMRUN} --browser ${EMSCRIPTEN_EMRUN_BROWSER} --timeout ${EMRUN_TIMEOUT} --kill_exit ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TARGET_NAME}.html ${ARG_OPTIONS})
  1857. endif ()
  1858. else ()
  1859. add_test (NAME ${ARG_NAME} COMMAND ${TARGET_NAME} ${ARG_OPTIONS})
  1860. endif ()
  1861. endif ()
  1862. endmacro ()
  1863. # Set common binary output directory if not already set (note that this module can be included in an external project which may already have DEST_RUNTIME_DIR preset)
  1864. if (NOT DEST_RUNTIME_DIR)
  1865. set_output_directories (${CMAKE_BINARY_DIR}/bin RUNTIME PDB)
  1866. endif ()
  1867. if (ANDROID)
  1868. # TODO: Verify if this setup still works with Android NDK 13 and above
  1869. # Enable Android ndk-gdb, if the build option is enabled
  1870. if (ANDROID_NDK_GDB)
  1871. set (NDK_GDB_SOLIB_PATH ${CMAKE_BINARY_DIR}/obj/local/${ANDROID_NDK_ABI_NAME}/)
  1872. file (MAKE_DIRECTORY ${NDK_GDB_SOLIB_PATH})
  1873. set (NDK_GDB_JNI ${CMAKE_BINARY_DIR}/jni)
  1874. set (NDK_GDB_MK "# This is a generated file. DO NOT EDIT!\n\nAPP_ABI := ${ANDROID_NDK_ABI_NAME}\n")
  1875. foreach (MK Android.mk Application.mk)
  1876. if (NOT EXISTS ${NDK_GDB_JNI}/${MK})
  1877. file (WRITE ${NDK_GDB_JNI}/${MK} ${NDK_GDB_MK})
  1878. endif ()
  1879. endforeach ()
  1880. get_directory_property (INCLUDE_DIRECTORIES DIRECTORY ${PROJECT_SOURCE_DIR} INCLUDE_DIRECTORIES)
  1881. string (REPLACE ";" " " INCLUDE_DIRECTORIES "${INCLUDE_DIRECTORIES}") # Note: need to always "stringify" a variable in list context for replace to work correctly
  1882. set (NDK_GDB_SETUP "# This is a generated file. DO NOT EDIT!\n\nset solib-search-path ${NDK_GDB_SOLIB_PATH}\ndirectory ${INCLUDE_DIRECTORIES}\n")
  1883. file (WRITE ${CMAKE_BINARY_DIR}/libs/${ANDROID_NDK_ABI_NAME}/gdb.setup ${NDK_GDB_SETUP})
  1884. file (COPY ${ANDROID_NDK}/prebuilt/android-${ANDROID_ARCH_NAME}/gdbserver/gdbserver DESTINATION ${CMAKE_BINARY_DIR}/libs/${ANDROID_NDK_ABI_NAME})
  1885. else ()
  1886. file (REMOVE ${CMAKE_BINARY_DIR}/libs/${ANDROID_NDK_ABI_NAME}/gdbserver)
  1887. endif ()
  1888. elseif (WEB)
  1889. if (EMSCRIPTEN_SHARE_DATA AND NOT EXISTS ${CMAKE_BINARY_DIR}/Source/pak-loader.js)
  1890. file (WRITE ${CMAKE_BINARY_DIR}/Source/pak-loader.js "var Module;if(typeof Module==='undefined')Module=eval('(function(){try{return Module||{}}catch(e){return{}}})()');var s=document.createElement('script');s.src='${CMAKE_PROJECT_NAME}.js';document.body.appendChild(s);Module['preRun'].push(function(){Module['addRunDependency']('${CMAKE_PROJECT_NAME}.js.loader')});s.onload=function(){Module['removeRunDependency']('${CMAKE_PROJECT_NAME}.js.loader')};")
  1891. endif ()
  1892. endif ()
  1893. # Warn user if PATH environment variable has not been correctly set for using ccache
  1894. if (NOT CMAKE_HOST_WIN32 AND "$ENV{USE_CCACHE}")
  1895. if (APPLE)
  1896. set (WHEREIS brew info ccache)
  1897. else ()
  1898. set (WHEREIS whereis -b ccache)
  1899. endif ()
  1900. execute_process (COMMAND ${WHEREIS} COMMAND grep -o \\S*lib\\S* RESULT_VARIABLE EXIT_CODE OUTPUT_VARIABLE CCACHE_SYMLINK ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
  1901. if (EXIT_CODE EQUAL 0 AND NOT $ENV{PATH} MATCHES "${CCACHE_SYMLINK}") # Need to stringify because CCACHE_SYMLINK variable could be empty when the command failed
  1902. message (WARNING "The lib directory containing the ccache symlinks (${CCACHE_SYMLINK}) has not been added in the PATH environment variable. "
  1903. "This is required to enable ccache support for native compiler toolchain. CMake has been configured to use the actual compiler toolchain instead of ccache. "
  1904. "In order to rectify this, the build tree must be regenerated after the PATH environment variable has been adjusted accordingly.")
  1905. endif ()
  1906. endif ()
  1907. # Post-CMake fixes
  1908. if (IOS)
  1909. # TODO: can be removed when CMake minimum required has reached 3.4
  1910. if (CMAKE_VERSION VERSION_LESS 3.4)
  1911. # Due to a bug in the CMake/Xcode generator (fixed in 3.4) that prevents iOS targets (library and bundle) to be installed correctly
  1912. # (see http://public.kitware.com/Bug/bug_relationship_graph.php?bug_id=12506&graph=dependency),
  1913. # below temporary fix is required to work around the bug
  1914. list (APPEND POST_CMAKE_FIXES COMMAND sed -i '' 's/\$$\(EFFECTIVE_PLATFORM_NAME\)//g' ${CMAKE_BINARY_DIR}/CMakeScripts/install_postBuildPhase.make* || exit 0)
  1915. endif ()
  1916. elseif (TVOS)
  1917. # Almost the same bug as iOS one above but not quite, most probably because CMake does not support AppleTV platform yet
  1918. list (APPEND POST_CMAKE_FIXES COMMAND sed -i '' 's/\)\$$\(EFFECTIVE_PLATFORM_NAME\)/\) -DEFFECTIVE_PLATFORM_NAME=$$\(EFFECTIVE_PLATFORM_NAME\)/g' ${CMAKE_BINARY_DIR}/CMakeScripts/install_postBuildPhase.make* || exit 0)
  1919. add_custom_target (APPLETV_POST_CMAKE_FIX COMMAND sed -i '' -E 's,\(Debug|RelWithDebInfo|Release\)/,$$\(CONFIGURATION\)$$\(EFFECTIVE_PLATFORM_NAME\)/,g' ${CMAKE_BINARY_DIR}/Source/Urho3D/CMakeScripts/Urho3D_cmakeRulesBuildPhase.make* || exit 0)
  1920. endif ()
  1921. if (POST_CMAKE_FIXES)
  1922. add_custom_target (POST_CMAKE_FIXES ALL ${POST_CMAKE_FIXES} COMMENT "Applying post-cmake fixes")
  1923. endif ()