UrhoCommon.cmake 110 KB

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