UrhoCommon.cmake 113 KB

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