2
0

cotire.cmake 165 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054
  1. # - cotire (compile time reducer)
  2. #
  3. # See the cotire manual for usage hints.
  4. #
  5. #=============================================================================
  6. # Copyright 2012-2017 Sascha Kratky
  7. #
  8. # Permission is hereby granted, free of charge, to any person
  9. # obtaining a copy of this software and associated documentation
  10. # files (the "Software"), to deal in the Software without
  11. # restriction, including without limitation the rights to use,
  12. # copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. # copies of the Software, and to permit persons to whom the
  14. # Software is furnished to do so, subject to the following
  15. # conditions:
  16. #
  17. # The above copyright notice and this permission notice shall be
  18. # included in all copies or substantial portions of the Software.
  19. #
  20. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  22. # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  24. # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  25. # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  26. # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  27. # OTHER DEALINGS IN THE SOFTWARE.
  28. #=============================================================================
  29. if(__COTIRE_INCLUDED)
  30. return()
  31. endif()
  32. set(__COTIRE_INCLUDED TRUE)
  33. # call cmake_minimum_required, but prevent modification of the CMake policy stack in include mode
  34. # cmake_minimum_required also sets the policy version as a side effect, which we have to avoid
  35. if (NOT CMAKE_SCRIPT_MODE_FILE)
  36. cmake_policy(PUSH)
  37. endif()
  38. cmake_minimum_required(VERSION 2.8.12)
  39. if (NOT CMAKE_SCRIPT_MODE_FILE)
  40. cmake_policy(POP)
  41. endif()
  42. set (COTIRE_CMAKE_MODULE_FILE "${CMAKE_CURRENT_LIST_FILE}")
  43. set (COTIRE_CMAKE_MODULE_VERSION "1.7.10")
  44. # activate select policies
  45. if (POLICY CMP0025)
  46. # Compiler id for Apple Clang is now AppleClang
  47. cmake_policy(SET CMP0025 NEW)
  48. endif()
  49. if (POLICY CMP0026)
  50. # disallow use of the LOCATION target property
  51. cmake_policy(SET CMP0026 NEW)
  52. endif()
  53. if (POLICY CMP0038)
  54. # targets may not link directly to themselves
  55. cmake_policy(SET CMP0038 NEW)
  56. endif()
  57. if (POLICY CMP0039)
  58. # utility targets may not have link dependencies
  59. cmake_policy(SET CMP0039 NEW)
  60. endif()
  61. if (POLICY CMP0040)
  62. # target in the TARGET signature of add_custom_command() must exist
  63. cmake_policy(SET CMP0040 NEW)
  64. endif()
  65. if (POLICY CMP0045)
  66. # error on non-existent target in get_target_property
  67. cmake_policy(SET CMP0045 NEW)
  68. endif()
  69. if (POLICY CMP0046)
  70. # error on non-existent dependency in add_dependencies
  71. cmake_policy(SET CMP0046 NEW)
  72. endif()
  73. if (POLICY CMP0049)
  74. # do not expand variables in target source entries
  75. cmake_policy(SET CMP0049 NEW)
  76. endif()
  77. if (POLICY CMP0050)
  78. # disallow add_custom_command SOURCE signatures
  79. cmake_policy(SET CMP0050 NEW)
  80. endif()
  81. if (POLICY CMP0051)
  82. # include TARGET_OBJECTS expressions in a target's SOURCES property
  83. cmake_policy(SET CMP0051 NEW)
  84. endif()
  85. if (POLICY CMP0053)
  86. # simplify variable reference and escape sequence evaluation
  87. cmake_policy(SET CMP0053 NEW)
  88. endif()
  89. if (POLICY CMP0054)
  90. # only interpret if() arguments as variables or keywords when unquoted
  91. cmake_policy(SET CMP0054 NEW)
  92. endif()
  93. if (POLICY CMP0055)
  94. # strict checking for break() command
  95. cmake_policy(SET CMP0055 NEW)
  96. endif()
  97. include(CMakeParseArguments)
  98. include(ProcessorCount)
  99. function (cotire_get_configuration_types _configsVar)
  100. set (_configs "")
  101. if (CMAKE_CONFIGURATION_TYPES)
  102. list (APPEND _configs ${CMAKE_CONFIGURATION_TYPES})
  103. endif()
  104. if (CMAKE_BUILD_TYPE)
  105. list (APPEND _configs "${CMAKE_BUILD_TYPE}")
  106. endif()
  107. if (_configs)
  108. list (REMOVE_DUPLICATES _configs)
  109. set (${_configsVar} ${_configs} PARENT_SCOPE)
  110. else()
  111. set (${_configsVar} "None" PARENT_SCOPE)
  112. endif()
  113. endfunction()
  114. function (cotire_get_source_file_extension _sourceFile _extVar)
  115. # get_filename_component returns extension from first occurrence of . in file name
  116. # this function computes the extension from last occurrence of . in file name
  117. string (FIND "${_sourceFile}" "." _index REVERSE)
  118. if (_index GREATER -1)
  119. math (EXPR _index "${_index} + 1")
  120. string (SUBSTRING "${_sourceFile}" ${_index} -1 _sourceExt)
  121. else()
  122. set (_sourceExt "")
  123. endif()
  124. set (${_extVar} "${_sourceExt}" PARENT_SCOPE)
  125. endfunction()
  126. macro (cotire_check_is_path_relative_to _path _isRelativeVar)
  127. set (${_isRelativeVar} FALSE)
  128. if (IS_ABSOLUTE "${_path}")
  129. foreach (_dir ${ARGN})
  130. file (RELATIVE_PATH _relPath "${_dir}" "${_path}")
  131. if (NOT _relPath OR (NOT IS_ABSOLUTE "${_relPath}" AND NOT "${_relPath}" MATCHES "^\\.\\."))
  132. set (${_isRelativeVar} TRUE)
  133. break()
  134. endif()
  135. endforeach()
  136. endif()
  137. endmacro()
  138. function (cotire_filter_language_source_files _language _target _sourceFilesVar _excludedSourceFilesVar _cotiredSourceFilesVar)
  139. if (CMAKE_${_language}_SOURCE_FILE_EXTENSIONS)
  140. set (_languageExtensions "${CMAKE_${_language}_SOURCE_FILE_EXTENSIONS}")
  141. else()
  142. set (_languageExtensions "")
  143. endif()
  144. if (CMAKE_${_language}_IGNORE_EXTENSIONS)
  145. set (_ignoreExtensions "${CMAKE_${_language}_IGNORE_EXTENSIONS}")
  146. else()
  147. set (_ignoreExtensions "")
  148. endif()
  149. if (COTIRE_UNITY_SOURCE_EXCLUDE_EXTENSIONS)
  150. set (_excludeExtensions "${COTIRE_UNITY_SOURCE_EXCLUDE_EXTENSIONS}")
  151. else()
  152. set (_excludeExtensions "")
  153. endif()
  154. if (COTIRE_DEBUG AND _languageExtensions)
  155. message (STATUS "${_language} source file extensions: ${_languageExtensions}")
  156. endif()
  157. if (COTIRE_DEBUG AND _ignoreExtensions)
  158. message (STATUS "${_language} ignore extensions: ${_ignoreExtensions}")
  159. endif()
  160. if (COTIRE_DEBUG AND _excludeExtensions)
  161. message (STATUS "${_language} exclude extensions: ${_excludeExtensions}")
  162. endif()
  163. if (CMAKE_VERSION VERSION_LESS "3.1.0")
  164. set (_allSourceFiles ${ARGN})
  165. else()
  166. # as of CMake 3.1 target sources may contain generator expressions
  167. # since we cannot obtain required property information about source files added
  168. # through generator expressions at configure time, we filter them out
  169. string (GENEX_STRIP "${ARGN}" _allSourceFiles)
  170. endif()
  171. set (_filteredSourceFiles "")
  172. set (_excludedSourceFiles "")
  173. foreach (_sourceFile ${_allSourceFiles})
  174. get_source_file_property(_sourceIsHeaderOnly "${_sourceFile}" HEADER_FILE_ONLY)
  175. get_source_file_property(_sourceIsExternal "${_sourceFile}" EXTERNAL_OBJECT)
  176. get_source_file_property(_sourceIsSymbolic "${_sourceFile}" SYMBOLIC)
  177. if (NOT _sourceIsHeaderOnly AND NOT _sourceIsExternal AND NOT _sourceIsSymbolic)
  178. cotire_get_source_file_extension("${_sourceFile}" _sourceExt)
  179. if (_sourceExt)
  180. list (FIND _ignoreExtensions "${_sourceExt}" _ignoreIndex)
  181. if (_ignoreIndex LESS 0)
  182. list (FIND _excludeExtensions "${_sourceExt}" _excludeIndex)
  183. if (_excludeIndex GREATER -1)
  184. list (APPEND _excludedSourceFiles "${_sourceFile}")
  185. else()
  186. list (FIND _languageExtensions "${_sourceExt}" _sourceIndex)
  187. if (_sourceIndex GREATER -1)
  188. # consider source file unless it is excluded explicitly
  189. get_source_file_property(_sourceIsExcluded "${_sourceFile}" COTIRE_EXCLUDED)
  190. if (_sourceIsExcluded)
  191. list (APPEND _excludedSourceFiles "${_sourceFile}")
  192. else()
  193. list (APPEND _filteredSourceFiles "${_sourceFile}")
  194. endif()
  195. else()
  196. get_source_file_property(_sourceLanguage "${_sourceFile}" LANGUAGE)
  197. if ("${_sourceLanguage}" STREQUAL "${_language}")
  198. # add to excluded sources, if file is not ignored and has correct language without having the correct extension
  199. list (APPEND _excludedSourceFiles "${_sourceFile}")
  200. endif()
  201. endif()
  202. endif()
  203. endif()
  204. endif()
  205. endif()
  206. endforeach()
  207. # separate filtered source files from already cotired ones
  208. # the COTIRE_TARGET property of a source file may be set while a target is being processed by cotire
  209. set (_sourceFiles "")
  210. set (_cotiredSourceFiles "")
  211. foreach (_sourceFile ${_filteredSourceFiles})
  212. get_source_file_property(_sourceIsCotired "${_sourceFile}" COTIRE_TARGET)
  213. if (_sourceIsCotired)
  214. list (APPEND _cotiredSourceFiles "${_sourceFile}")
  215. else()
  216. get_source_file_property(_sourceCompileFlags "${_sourceFile}" COMPILE_FLAGS)
  217. if (_sourceCompileFlags)
  218. # add to excluded sources, if file has custom compile flags
  219. list (APPEND _excludedSourceFiles "${_sourceFile}")
  220. else()
  221. list (APPEND _sourceFiles "${_sourceFile}")
  222. endif()
  223. endif()
  224. endforeach()
  225. if (COTIRE_DEBUG)
  226. if (_sourceFiles)
  227. message (STATUS "Filtered ${_target} ${_language} sources: ${_sourceFiles}")
  228. endif()
  229. if (_excludedSourceFiles)
  230. message (STATUS "Excluded ${_target} ${_language} sources: ${_excludedSourceFiles}")
  231. endif()
  232. if (_cotiredSourceFiles)
  233. message (STATUS "Cotired ${_target} ${_language} sources: ${_cotiredSourceFiles}")
  234. endif()
  235. endif()
  236. set (${_sourceFilesVar} ${_sourceFiles} PARENT_SCOPE)
  237. set (${_excludedSourceFilesVar} ${_excludedSourceFiles} PARENT_SCOPE)
  238. set (${_cotiredSourceFilesVar} ${_cotiredSourceFiles} PARENT_SCOPE)
  239. endfunction()
  240. function (cotire_get_objects_with_property_on _filteredObjectsVar _property _type)
  241. set (_filteredObjects "")
  242. foreach (_object ${ARGN})
  243. get_property(_isSet ${_type} "${_object}" PROPERTY ${_property} SET)
  244. if (_isSet)
  245. get_property(_propertyValue ${_type} "${_object}" PROPERTY ${_property})
  246. if (_propertyValue)
  247. list (APPEND _filteredObjects "${_object}")
  248. endif()
  249. endif()
  250. endforeach()
  251. set (${_filteredObjectsVar} ${_filteredObjects} PARENT_SCOPE)
  252. endfunction()
  253. function (cotire_get_objects_with_property_off _filteredObjectsVar _property _type)
  254. set (_filteredObjects "")
  255. foreach (_object ${ARGN})
  256. get_property(_isSet ${_type} "${_object}" PROPERTY ${_property} SET)
  257. if (_isSet)
  258. get_property(_propertyValue ${_type} "${_object}" PROPERTY ${_property})
  259. if (NOT _propertyValue)
  260. list (APPEND _filteredObjects "${_object}")
  261. endif()
  262. endif()
  263. endforeach()
  264. set (${_filteredObjectsVar} ${_filteredObjects} PARENT_SCOPE)
  265. endfunction()
  266. function (cotire_get_source_file_property_values _valuesVar _property)
  267. set (_values "")
  268. foreach (_sourceFile ${ARGN})
  269. get_source_file_property(_propertyValue "${_sourceFile}" ${_property})
  270. if (_propertyValue)
  271. list (APPEND _values "${_propertyValue}")
  272. endif()
  273. endforeach()
  274. set (${_valuesVar} ${_values} PARENT_SCOPE)
  275. endfunction()
  276. function (cotire_resolve_config_properties _configurations _propertiesVar)
  277. set (_properties "")
  278. foreach (_property ${ARGN})
  279. if ("${_property}" MATCHES "<CONFIG>")
  280. foreach (_config ${_configurations})
  281. string (TOUPPER "${_config}" _upperConfig)
  282. string (REPLACE "<CONFIG>" "${_upperConfig}" _configProperty "${_property}")
  283. list (APPEND _properties ${_configProperty})
  284. endforeach()
  285. else()
  286. list (APPEND _properties ${_property})
  287. endif()
  288. endforeach()
  289. set (${_propertiesVar} ${_properties} PARENT_SCOPE)
  290. endfunction()
  291. function (cotire_copy_set_properties _configurations _type _source _target)
  292. cotire_resolve_config_properties("${_configurations}" _properties ${ARGN})
  293. foreach (_property ${_properties})
  294. get_property(_isSet ${_type} ${_source} PROPERTY ${_property} SET)
  295. if (_isSet)
  296. get_property(_propertyValue ${_type} ${_source} PROPERTY ${_property})
  297. set_property(${_type} ${_target} PROPERTY ${_property} "${_propertyValue}")
  298. endif()
  299. endforeach()
  300. endfunction()
  301. function (cotire_get_target_usage_requirements _target _config _targetRequirementsVar)
  302. set (_targetRequirements "")
  303. get_target_property(_librariesToProcess ${_target} LINK_LIBRARIES)
  304. while (_librariesToProcess)
  305. # remove from head
  306. list (GET _librariesToProcess 0 _library)
  307. list (REMOVE_AT _librariesToProcess 0)
  308. if (_library MATCHES "^\\$<\\$<CONFIG:${_config}>:([A-Za-z0-9_:-]+)>$")
  309. set (_library "${CMAKE_MATCH_1}")
  310. elseif (_config STREQUAL "None" AND _library MATCHES "^\\$<\\$<CONFIG:>:([A-Za-z0-9_:-]+)>$")
  311. set (_library "${CMAKE_MATCH_1}")
  312. endif()
  313. if (TARGET ${_library})
  314. list (FIND _targetRequirements ${_library} _index)
  315. if (_index LESS 0)
  316. list (APPEND _targetRequirements ${_library})
  317. # BFS traversal of transitive libraries
  318. get_target_property(_libraries ${_library} INTERFACE_LINK_LIBRARIES)
  319. if (_libraries)
  320. list (APPEND _librariesToProcess ${_libraries})
  321. list (REMOVE_DUPLICATES _librariesToProcess)
  322. endif()
  323. endif()
  324. endif()
  325. endwhile()
  326. set (${_targetRequirementsVar} ${_targetRequirements} PARENT_SCOPE)
  327. endfunction()
  328. function (cotire_filter_compile_flags _language _flagFilter _matchedOptionsVar _unmatchedOptionsVar)
  329. if (WIN32 AND CMAKE_${_language}_COMPILER_ID MATCHES "MSVC|Intel")
  330. set (_flagPrefix "[/-]")
  331. else()
  332. set (_flagPrefix "--?")
  333. endif()
  334. set (_optionFlag "")
  335. set (_matchedOptions "")
  336. set (_unmatchedOptions "")
  337. foreach (_compileFlag ${ARGN})
  338. if (_compileFlag)
  339. if (_optionFlag AND NOT "${_compileFlag}" MATCHES "^${_flagPrefix}")
  340. # option with separate argument
  341. list (APPEND _matchedOptions "${_compileFlag}")
  342. set (_optionFlag "")
  343. elseif ("${_compileFlag}" MATCHES "^(${_flagPrefix})(${_flagFilter})$")
  344. # remember option
  345. set (_optionFlag "${CMAKE_MATCH_2}")
  346. elseif ("${_compileFlag}" MATCHES "^(${_flagPrefix})(${_flagFilter})(.+)$")
  347. # option with joined argument
  348. list (APPEND _matchedOptions "${CMAKE_MATCH_3}")
  349. set (_optionFlag "")
  350. else()
  351. # flush remembered option
  352. if (_optionFlag)
  353. list (APPEND _matchedOptions "${_optionFlag}")
  354. set (_optionFlag "")
  355. endif()
  356. # add to unfiltered options
  357. list (APPEND _unmatchedOptions "${_compileFlag}")
  358. endif()
  359. endif()
  360. endforeach()
  361. if (_optionFlag)
  362. list (APPEND _matchedOptions "${_optionFlag}")
  363. endif()
  364. if (COTIRE_DEBUG AND _matchedOptions)
  365. message (STATUS "Filter ${_flagFilter} matched: ${_matchedOptions}")
  366. endif()
  367. if (COTIRE_DEBUG AND _unmatchedOptions)
  368. message (STATUS "Filter ${_flagFilter} unmatched: ${_unmatchedOptions}")
  369. endif()
  370. set (${_matchedOptionsVar} ${_matchedOptions} PARENT_SCOPE)
  371. set (${_unmatchedOptionsVar} ${_unmatchedOptions} PARENT_SCOPE)
  372. endfunction()
  373. function (cotire_is_target_supported _target _isSupportedVar)
  374. if (NOT TARGET "${_target}")
  375. set (${_isSupportedVar} FALSE PARENT_SCOPE)
  376. return()
  377. endif()
  378. get_target_property(_imported ${_target} IMPORTED)
  379. if (_imported)
  380. set (${_isSupportedVar} FALSE PARENT_SCOPE)
  381. return()
  382. endif()
  383. get_target_property(_targetType ${_target} TYPE)
  384. if (NOT _targetType MATCHES "EXECUTABLE|(STATIC|SHARED|MODULE|OBJECT)_LIBRARY")
  385. set (${_isSupportedVar} FALSE PARENT_SCOPE)
  386. return()
  387. endif()
  388. set (${_isSupportedVar} TRUE PARENT_SCOPE)
  389. endfunction()
  390. function (cotire_get_target_compile_flags _config _language _target _flagsVar)
  391. string (TOUPPER "${_config}" _upperConfig)
  392. # collect options from CMake language variables
  393. set (_compileFlags "")
  394. if (CMAKE_${_language}_FLAGS)
  395. set (_compileFlags "${_compileFlags} ${CMAKE_${_language}_FLAGS}")
  396. endif()
  397. if (CMAKE_${_language}_FLAGS_${_upperConfig})
  398. set (_compileFlags "${_compileFlags} ${CMAKE_${_language}_FLAGS_${_upperConfig}}")
  399. endif()
  400. if (_target)
  401. # add target compile flags
  402. get_target_property(_targetflags ${_target} COMPILE_FLAGS)
  403. if (_targetflags)
  404. set (_compileFlags "${_compileFlags} ${_targetflags}")
  405. endif()
  406. endif()
  407. if (UNIX)
  408. separate_arguments(_compileFlags UNIX_COMMAND "${_compileFlags}")
  409. elseif(WIN32)
  410. separate_arguments(_compileFlags WINDOWS_COMMAND "${_compileFlags}")
  411. else()
  412. separate_arguments(_compileFlags)
  413. endif()
  414. # target compile options
  415. if (_target)
  416. get_target_property(_targetOptions ${_target} COMPILE_OPTIONS)
  417. if (_targetOptions)
  418. list (APPEND _compileFlags ${_targetOptions})
  419. endif()
  420. endif()
  421. # interface compile options from linked library targets
  422. if (_target)
  423. set (_linkedTargets "")
  424. cotire_get_target_usage_requirements(${_target} ${_config} _linkedTargets)
  425. foreach (_linkedTarget ${_linkedTargets})
  426. get_target_property(_targetOptions ${_linkedTarget} INTERFACE_COMPILE_OPTIONS)
  427. if (_targetOptions)
  428. list (APPEND _compileFlags ${_targetOptions})
  429. endif()
  430. endforeach()
  431. endif()
  432. # handle language standard properties
  433. if (CMAKE_${_language}_STANDARD_DEFAULT)
  434. # used compiler supports language standard levels
  435. if (_target)
  436. get_target_property(_targetLanguageStandard ${_target} ${_language}_STANDARD)
  437. if (_targetLanguageStandard)
  438. set (_type "EXTENSION")
  439. get_property(_isSet TARGET ${_target} PROPERTY ${_language}_EXTENSIONS SET)
  440. if (_isSet)
  441. get_target_property(_targetUseLanguageExtensions ${_target} ${_language}_EXTENSIONS)
  442. if (NOT _targetUseLanguageExtensions)
  443. set (_type "STANDARD")
  444. endif()
  445. endif()
  446. if (CMAKE_${_language}${_targetLanguageStandard}_${_type}_COMPILE_OPTION)
  447. list (APPEND _compileFlags "${CMAKE_${_language}${_targetLanguageStandard}_${_type}_COMPILE_OPTION}")
  448. endif()
  449. endif()
  450. endif()
  451. endif()
  452. # handle the POSITION_INDEPENDENT_CODE target property
  453. if (_target)
  454. get_target_property(_targetPIC ${_target} POSITION_INDEPENDENT_CODE)
  455. if (_targetPIC)
  456. get_target_property(_targetType ${_target} TYPE)
  457. if (_targetType STREQUAL "EXECUTABLE" AND CMAKE_${_language}_COMPILE_OPTIONS_PIE)
  458. list (APPEND _compileFlags "${CMAKE_${_language}_COMPILE_OPTIONS_PIE}")
  459. elseif (CMAKE_${_language}_COMPILE_OPTIONS_PIC)
  460. list (APPEND _compileFlags "${CMAKE_${_language}_COMPILE_OPTIONS_PIC}")
  461. endif()
  462. endif()
  463. endif()
  464. # handle visibility target properties
  465. if (_target)
  466. get_target_property(_targetVisibility ${_target} ${_language}_VISIBILITY_PRESET)
  467. if (_targetVisibility AND CMAKE_${_language}_COMPILE_OPTIONS_VISIBILITY)
  468. list (APPEND _compileFlags "${CMAKE_${_language}_COMPILE_OPTIONS_VISIBILITY}${_targetVisibility}")
  469. endif()
  470. get_target_property(_targetVisibilityInlines ${_target} VISIBILITY_INLINES_HIDDEN)
  471. if (_targetVisibilityInlines AND CMAKE_${_language}_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN)
  472. list (APPEND _compileFlags "${CMAKE_${_language}_COMPILE_OPTIONS_VISIBILITY_INLINES_HIDDEN}")
  473. endif()
  474. endif()
  475. # platform specific flags
  476. if (APPLE)
  477. get_target_property(_architectures ${_target} OSX_ARCHITECTURES_${_upperConfig})
  478. if (NOT _architectures)
  479. get_target_property(_architectures ${_target} OSX_ARCHITECTURES)
  480. endif()
  481. if (_architectures)
  482. foreach (_arch ${_architectures})
  483. list (APPEND _compileFlags "-arch" "${_arch}")
  484. endforeach()
  485. endif()
  486. if (CMAKE_OSX_SYSROOT)
  487. if (CMAKE_${_language}_SYSROOT_FLAG)
  488. list (APPEND _compileFlags "${CMAKE_${_language}_SYSROOT_FLAG}" "${CMAKE_OSX_SYSROOT}")
  489. else()
  490. list (APPEND _compileFlags "-isysroot" "${CMAKE_OSX_SYSROOT}")
  491. endif()
  492. endif()
  493. if (CMAKE_OSX_DEPLOYMENT_TARGET)
  494. if (CMAKE_${_language}_OSX_DEPLOYMENT_TARGET_FLAG)
  495. list (APPEND _compileFlags "${CMAKE_${_language}_OSX_DEPLOYMENT_TARGET_FLAG}${CMAKE_OSX_DEPLOYMENT_TARGET}")
  496. else()
  497. list (APPEND _compileFlags "-mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
  498. endif()
  499. endif()
  500. endif()
  501. if (COTIRE_DEBUG AND _compileFlags)
  502. message (STATUS "Target ${_target} compile flags: ${_compileFlags}")
  503. endif()
  504. set (${_flagsVar} ${_compileFlags} PARENT_SCOPE)
  505. endfunction()
  506. function (cotire_get_target_include_directories _config _language _target _includeDirsVar _systemIncludeDirsVar)
  507. set (_includeDirs "")
  508. set (_systemIncludeDirs "")
  509. # default include dirs
  510. if (CMAKE_INCLUDE_CURRENT_DIR)
  511. list (APPEND _includeDirs "${CMAKE_CURRENT_BINARY_DIR}")
  512. list (APPEND _includeDirs "${CMAKE_CURRENT_SOURCE_DIR}")
  513. endif()
  514. set (_targetFlags "")
  515. cotire_get_target_compile_flags("${_config}" "${_language}" "${_target}" _targetFlags)
  516. # parse additional include directories from target compile flags
  517. if (CMAKE_INCLUDE_FLAG_${_language})
  518. string (STRIP "${CMAKE_INCLUDE_FLAG_${_language}}" _includeFlag)
  519. string (REGEX REPLACE "^[-/]+" "" _includeFlag "${_includeFlag}")
  520. if (_includeFlag)
  521. set (_dirs "")
  522. cotire_filter_compile_flags("${_language}" "${_includeFlag}" _dirs _ignore ${_targetFlags})
  523. if (_dirs)
  524. list (APPEND _includeDirs ${_dirs})
  525. endif()
  526. endif()
  527. endif()
  528. # parse additional system include directories from target compile flags
  529. if (CMAKE_INCLUDE_SYSTEM_FLAG_${_language})
  530. string (STRIP "${CMAKE_INCLUDE_SYSTEM_FLAG_${_language}}" _includeFlag)
  531. string (REGEX REPLACE "^[-/]+" "" _includeFlag "${_includeFlag}")
  532. if (_includeFlag)
  533. set (_dirs "")
  534. cotire_filter_compile_flags("${_language}" "${_includeFlag}" _dirs _ignore ${_targetFlags})
  535. if (_dirs)
  536. list (APPEND _systemIncludeDirs ${_dirs})
  537. endif()
  538. endif()
  539. endif()
  540. # target include directories
  541. get_directory_property(_dirs DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" INCLUDE_DIRECTORIES)
  542. if (_target)
  543. get_target_property(_targetDirs ${_target} INCLUDE_DIRECTORIES)
  544. if (_targetDirs)
  545. list (APPEND _dirs ${_targetDirs})
  546. endif()
  547. get_target_property(_targetDirs ${_target} INTERFACE_SYSTEM_INCLUDE_DIRECTORIES)
  548. if (_targetDirs)
  549. list (APPEND _systemIncludeDirs ${_targetDirs})
  550. endif()
  551. endif()
  552. # interface include directories from linked library targets
  553. if (_target)
  554. set (_linkedTargets "")
  555. cotire_get_target_usage_requirements(${_target} ${_config} _linkedTargets)
  556. foreach (_linkedTarget ${_linkedTargets})
  557. get_target_property(_linkedTargetType ${_linkedTarget} TYPE)
  558. if (CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE AND NOT CMAKE_VERSION VERSION_LESS "3.4.0" AND
  559. _linkedTargetType MATCHES "(STATIC|SHARED|MODULE|OBJECT)_LIBRARY")
  560. # CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE refers to CMAKE_CURRENT_BINARY_DIR and CMAKE_CURRENT_SOURCE_DIR
  561. # at the time, when the target was created. These correspond to the target properties BINARY_DIR and SOURCE_DIR
  562. # which are only available with CMake 3.4 or later.
  563. get_target_property(_targetDirs ${_linkedTarget} BINARY_DIR)
  564. if (_targetDirs)
  565. list (APPEND _dirs ${_targetDirs})
  566. endif()
  567. get_target_property(_targetDirs ${_linkedTarget} SOURCE_DIR)
  568. if (_targetDirs)
  569. list (APPEND _dirs ${_targetDirs})
  570. endif()
  571. endif()
  572. get_target_property(_targetDirs ${_linkedTarget} INTERFACE_INCLUDE_DIRECTORIES)
  573. if (_targetDirs)
  574. list (APPEND _dirs ${_targetDirs})
  575. endif()
  576. get_target_property(_targetDirs ${_linkedTarget} INTERFACE_SYSTEM_INCLUDE_DIRECTORIES)
  577. if (_targetDirs)
  578. list (APPEND _systemIncludeDirs ${_targetDirs})
  579. endif()
  580. endforeach()
  581. endif()
  582. if (dirs)
  583. list (REMOVE_DUPLICATES _dirs)
  584. endif()
  585. list (LENGTH _includeDirs _projectInsertIndex)
  586. foreach (_dir ${_dirs})
  587. if (CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE)
  588. cotire_check_is_path_relative_to("${_dir}" _isRelative "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}")
  589. if (_isRelative)
  590. list (LENGTH _includeDirs _len)
  591. if (_len EQUAL _projectInsertIndex)
  592. list (APPEND _includeDirs "${_dir}")
  593. else()
  594. list (INSERT _includeDirs _projectInsertIndex "${_dir}")
  595. endif()
  596. math (EXPR _projectInsertIndex "${_projectInsertIndex} + 1")
  597. else()
  598. list (APPEND _includeDirs "${_dir}")
  599. endif()
  600. else()
  601. list (APPEND _includeDirs "${_dir}")
  602. endif()
  603. endforeach()
  604. list (REMOVE_DUPLICATES _includeDirs)
  605. list (REMOVE_DUPLICATES _systemIncludeDirs)
  606. if (CMAKE_${_language}_IMPLICIT_INCLUDE_DIRECTORIES)
  607. list (REMOVE_ITEM _includeDirs ${CMAKE_${_language}_IMPLICIT_INCLUDE_DIRECTORIES})
  608. endif()
  609. if (WIN32 AND NOT MINGW)
  610. # convert Windows paths in include directories to CMake paths
  611. if (_includeDirs)
  612. set (_paths "")
  613. foreach (_dir ${_includeDirs})
  614. file (TO_CMAKE_PATH "${_dir}" _path)
  615. list (APPEND _paths "${_path}")
  616. endforeach()
  617. set (_includeDirs ${_paths})
  618. endif()
  619. if (_systemIncludeDirs)
  620. set (_paths "")
  621. foreach (_dir ${_systemIncludeDirs})
  622. file (TO_CMAKE_PATH "${_dir}" _path)
  623. list (APPEND _paths "${_path}")
  624. endforeach()
  625. set (_systemIncludeDirs ${_paths})
  626. endif()
  627. endif()
  628. if (COTIRE_DEBUG AND _includeDirs)
  629. message (STATUS "Target ${_target} include dirs: ${_includeDirs}")
  630. endif()
  631. set (${_includeDirsVar} ${_includeDirs} PARENT_SCOPE)
  632. if (COTIRE_DEBUG AND _systemIncludeDirs)
  633. message (STATUS "Target ${_target} system include dirs: ${_systemIncludeDirs}")
  634. endif()
  635. set (${_systemIncludeDirsVar} ${_systemIncludeDirs} PARENT_SCOPE)
  636. endfunction()
  637. function (cotire_get_target_export_symbol _target _exportSymbolVar)
  638. set (_exportSymbol "")
  639. get_target_property(_targetType ${_target} TYPE)
  640. get_target_property(_enableExports ${_target} ENABLE_EXPORTS)
  641. if (_targetType MATCHES "(SHARED|MODULE)_LIBRARY" OR
  642. (_targetType STREQUAL "EXECUTABLE" AND _enableExports))
  643. get_target_property(_exportSymbol ${_target} DEFINE_SYMBOL)
  644. if (NOT _exportSymbol)
  645. set (_exportSymbol "${_target}_EXPORTS")
  646. endif()
  647. string (MAKE_C_IDENTIFIER "${_exportSymbol}" _exportSymbol)
  648. endif()
  649. set (${_exportSymbolVar} ${_exportSymbol} PARENT_SCOPE)
  650. endfunction()
  651. function (cotire_get_target_compile_definitions _config _language _target _definitionsVar)
  652. string (TOUPPER "${_config}" _upperConfig)
  653. set (_configDefinitions "")
  654. # CMAKE_INTDIR for multi-configuration build systems
  655. if (NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".")
  656. list (APPEND _configDefinitions "CMAKE_INTDIR=\"${_config}\"")
  657. endif()
  658. # target export define symbol
  659. cotire_get_target_export_symbol("${_target}" _defineSymbol)
  660. if (_defineSymbol)
  661. list (APPEND _configDefinitions "${_defineSymbol}")
  662. endif()
  663. # directory compile definitions
  664. get_directory_property(_definitions DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" COMPILE_DEFINITIONS)
  665. if (_definitions)
  666. list (APPEND _configDefinitions ${_definitions})
  667. endif()
  668. get_directory_property(_definitions DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" COMPILE_DEFINITIONS_${_upperConfig})
  669. if (_definitions)
  670. list (APPEND _configDefinitions ${_definitions})
  671. endif()
  672. # target compile definitions
  673. get_target_property(_definitions ${_target} COMPILE_DEFINITIONS)
  674. if (_definitions)
  675. list (APPEND _configDefinitions ${_definitions})
  676. endif()
  677. get_target_property(_definitions ${_target} COMPILE_DEFINITIONS_${_upperConfig})
  678. if (_definitions)
  679. list (APPEND _configDefinitions ${_definitions})
  680. endif()
  681. # interface compile definitions from linked library targets
  682. set (_linkedTargets "")
  683. cotire_get_target_usage_requirements(${_target} ${_config} _linkedTargets)
  684. foreach (_linkedTarget ${_linkedTargets})
  685. get_target_property(_definitions ${_linkedTarget} INTERFACE_COMPILE_DEFINITIONS)
  686. if (_definitions)
  687. list (APPEND _configDefinitions ${_definitions})
  688. endif()
  689. endforeach()
  690. # parse additional compile definitions from target compile flags
  691. # and don't look at directory compile definitions, which we already handled
  692. set (_targetFlags "")
  693. cotire_get_target_compile_flags("${_config}" "${_language}" "${_target}" _targetFlags)
  694. cotire_filter_compile_flags("${_language}" "D" _definitions _ignore ${_targetFlags})
  695. if (_definitions)
  696. list (APPEND _configDefinitions ${_definitions})
  697. endif()
  698. list (REMOVE_DUPLICATES _configDefinitions)
  699. if (COTIRE_DEBUG AND _configDefinitions)
  700. message (STATUS "Target ${_target} compile definitions: ${_configDefinitions}")
  701. endif()
  702. set (${_definitionsVar} ${_configDefinitions} PARENT_SCOPE)
  703. endfunction()
  704. function (cotire_get_target_compiler_flags _config _language _target _compilerFlagsVar)
  705. # parse target compile flags omitting compile definitions and include directives
  706. set (_targetFlags "")
  707. cotire_get_target_compile_flags("${_config}" "${_language}" "${_target}" _targetFlags)
  708. set (_flagFilter "D")
  709. if (CMAKE_INCLUDE_FLAG_${_language})
  710. string (STRIP "${CMAKE_INCLUDE_FLAG_${_language}}" _includeFlag)
  711. string (REGEX REPLACE "^[-/]+" "" _includeFlag "${_includeFlag}")
  712. if (_includeFlag)
  713. set (_flagFilter "${_flagFilter}|${_includeFlag}")
  714. endif()
  715. endif()
  716. if (CMAKE_INCLUDE_SYSTEM_FLAG_${_language})
  717. string (STRIP "${CMAKE_INCLUDE_SYSTEM_FLAG_${_language}}" _includeFlag)
  718. string (REGEX REPLACE "^[-/]+" "" _includeFlag "${_includeFlag}")
  719. if (_includeFlag)
  720. set (_flagFilter "${_flagFilter}|${_includeFlag}")
  721. endif()
  722. endif()
  723. set (_compilerFlags "")
  724. cotire_filter_compile_flags("${_language}" "${_flagFilter}" _ignore _compilerFlags ${_targetFlags})
  725. if (COTIRE_DEBUG AND _compilerFlags)
  726. message (STATUS "Target ${_target} compiler flags: ${_compilerFlags}")
  727. endif()
  728. set (${_compilerFlagsVar} ${_compilerFlags} PARENT_SCOPE)
  729. endfunction()
  730. function (cotire_add_sys_root_paths _pathsVar)
  731. if (APPLE)
  732. if (CMAKE_OSX_SYSROOT AND CMAKE_${_language}_HAS_ISYSROOT)
  733. foreach (_path IN LISTS ${_pathsVar})
  734. if (IS_ABSOLUTE "${_path}")
  735. get_filename_component(_path "${CMAKE_OSX_SYSROOT}/${_path}" ABSOLUTE)
  736. if (EXISTS "${_path}")
  737. list (APPEND ${_pathsVar} "${_path}")
  738. endif()
  739. endif()
  740. endforeach()
  741. endif()
  742. endif()
  743. set (${_pathsVar} ${${_pathsVar}} PARENT_SCOPE)
  744. endfunction()
  745. function (cotire_get_source_extra_properties _sourceFile _pattern _resultVar)
  746. set (_extraProperties ${ARGN})
  747. set (_result "")
  748. if (_extraProperties)
  749. list (FIND _extraProperties "${_sourceFile}" _index)
  750. if (_index GREATER -1)
  751. math (EXPR _index "${_index} + 1")
  752. list (LENGTH _extraProperties _len)
  753. math (EXPR _len "${_len} - 1")
  754. foreach (_index RANGE ${_index} ${_len})
  755. list (GET _extraProperties ${_index} _value)
  756. if (_value MATCHES "${_pattern}")
  757. list (APPEND _result "${_value}")
  758. else()
  759. break()
  760. endif()
  761. endforeach()
  762. endif()
  763. endif()
  764. set (${_resultVar} ${_result} PARENT_SCOPE)
  765. endfunction()
  766. function (cotire_get_source_compile_definitions _config _language _sourceFile _definitionsVar)
  767. set (_compileDefinitions "")
  768. if (NOT CMAKE_SCRIPT_MODE_FILE)
  769. string (TOUPPER "${_config}" _upperConfig)
  770. get_source_file_property(_definitions "${_sourceFile}" COMPILE_DEFINITIONS)
  771. if (_definitions)
  772. list (APPEND _compileDefinitions ${_definitions})
  773. endif()
  774. get_source_file_property(_definitions "${_sourceFile}" COMPILE_DEFINITIONS_${_upperConfig})
  775. if (_definitions)
  776. list (APPEND _compileDefinitions ${_definitions})
  777. endif()
  778. endif()
  779. cotire_get_source_extra_properties("${_sourceFile}" "^[a-zA-Z0-9_]+(=.*)?$" _definitions ${ARGN})
  780. if (_definitions)
  781. list (APPEND _compileDefinitions ${_definitions})
  782. endif()
  783. if (COTIRE_DEBUG AND _compileDefinitions)
  784. message (STATUS "Source ${_sourceFile} compile definitions: ${_compileDefinitions}")
  785. endif()
  786. set (${_definitionsVar} ${_compileDefinitions} PARENT_SCOPE)
  787. endfunction()
  788. function (cotire_get_source_files_compile_definitions _config _language _definitionsVar)
  789. set (_configDefinitions "")
  790. foreach (_sourceFile ${ARGN})
  791. cotire_get_source_compile_definitions("${_config}" "${_language}" "${_sourceFile}" _sourceDefinitions)
  792. if (_sourceDefinitions)
  793. list (APPEND _configDefinitions "${_sourceFile}" ${_sourceDefinitions} "-")
  794. endif()
  795. endforeach()
  796. set (${_definitionsVar} ${_configDefinitions} PARENT_SCOPE)
  797. endfunction()
  798. function (cotire_get_source_undefs _sourceFile _property _sourceUndefsVar)
  799. set (_sourceUndefs "")
  800. if (NOT CMAKE_SCRIPT_MODE_FILE)
  801. get_source_file_property(_undefs "${_sourceFile}" ${_property})
  802. if (_undefs)
  803. list (APPEND _sourceUndefs ${_undefs})
  804. endif()
  805. endif()
  806. cotire_get_source_extra_properties("${_sourceFile}" "^[a-zA-Z0-9_]+$" _undefs ${ARGN})
  807. if (_undefs)
  808. list (APPEND _sourceUndefs ${_undefs})
  809. endif()
  810. if (COTIRE_DEBUG AND _sourceUndefs)
  811. message (STATUS "Source ${_sourceFile} ${_property} undefs: ${_sourceUndefs}")
  812. endif()
  813. set (${_sourceUndefsVar} ${_sourceUndefs} PARENT_SCOPE)
  814. endfunction()
  815. function (cotire_get_source_files_undefs _property _sourceUndefsVar)
  816. set (_sourceUndefs "")
  817. foreach (_sourceFile ${ARGN})
  818. cotire_get_source_undefs("${_sourceFile}" ${_property} _undefs)
  819. if (_undefs)
  820. list (APPEND _sourceUndefs "${_sourceFile}" ${_undefs} "-")
  821. endif()
  822. endforeach()
  823. set (${_sourceUndefsVar} ${_sourceUndefs} PARENT_SCOPE)
  824. endfunction()
  825. macro (cotire_set_cmd_to_prologue _cmdVar)
  826. set (${_cmdVar} "${CMAKE_COMMAND}")
  827. if (COTIRE_DEBUG)
  828. list (APPEND ${_cmdVar} "--warn-uninitialized")
  829. endif()
  830. list (APPEND ${_cmdVar} "-DCOTIRE_BUILD_TYPE:STRING=$<CONFIGURATION>")
  831. if (XCODE)
  832. list (APPEND ${_cmdVar} "-DXCODE:BOOL=TRUE")
  833. endif()
  834. if (COTIRE_VERBOSE)
  835. list (APPEND ${_cmdVar} "-DCOTIRE_VERBOSE:BOOL=ON")
  836. elseif("${CMAKE_GENERATOR}" MATCHES "Makefiles")
  837. list (APPEND ${_cmdVar} "-DCOTIRE_VERBOSE:BOOL=$(VERBOSE)")
  838. endif()
  839. endmacro()
  840. function (cotire_init_compile_cmd _cmdVar _language _compilerLauncher _compilerExe _compilerArg1)
  841. if (NOT _compilerLauncher)
  842. set (_compilerLauncher ${CMAKE_${_language}_COMPILER_LAUNCHER})
  843. endif()
  844. if (NOT _compilerExe)
  845. set (_compilerExe "${CMAKE_${_language}_COMPILER}")
  846. endif()
  847. if (NOT _compilerArg1)
  848. set (_compilerArg1 ${CMAKE_${_language}_COMPILER_ARG1})
  849. endif()
  850. string (STRIP "${_compilerArg1}" _compilerArg1)
  851. if ("${CMAKE_GENERATOR}" MATCHES "Make|Ninja")
  852. # compiler launcher is only supported for Makefile and Ninja
  853. set (${_cmdVar} ${_compilerLauncher} "${_compilerExe}" ${_compilerArg1} PARENT_SCOPE)
  854. else()
  855. set (${_cmdVar} "${_compilerExe}" ${_compilerArg1} PARENT_SCOPE)
  856. endif()
  857. endfunction()
  858. macro (cotire_add_definitions_to_cmd _cmdVar _language)
  859. foreach (_definition ${ARGN})
  860. if (WIN32 AND CMAKE_${_language}_COMPILER_ID MATCHES "MSVC|Intel")
  861. list (APPEND ${_cmdVar} "/D${_definition}")
  862. else()
  863. list (APPEND ${_cmdVar} "-D${_definition}")
  864. endif()
  865. endforeach()
  866. endmacro()
  867. function (cotire_add_includes_to_cmd _cmdVar _language _includesVar _systemIncludesVar)
  868. set (_includeDirs ${${_includesVar}} ${${_systemIncludesVar}})
  869. if (_includeDirs)
  870. list (REMOVE_DUPLICATES _includeDirs)
  871. foreach (_include ${_includeDirs})
  872. if (WIN32 AND CMAKE_${_language}_COMPILER_ID MATCHES "MSVC|Intel")
  873. file (TO_NATIVE_PATH "${_include}" _include)
  874. list (APPEND ${_cmdVar} "${CMAKE_INCLUDE_FLAG_${_language}}${CMAKE_INCLUDE_FLAG_SEP_${_language}}${_include}")
  875. else()
  876. set (_index -1)
  877. if ("${CMAKE_INCLUDE_SYSTEM_FLAG_${_language}}" MATCHES ".+")
  878. list (FIND ${_systemIncludesVar} "${_include}" _index)
  879. endif()
  880. if (_index GREATER -1)
  881. list (APPEND ${_cmdVar} "${CMAKE_INCLUDE_SYSTEM_FLAG_${_language}}${CMAKE_INCLUDE_FLAG_SEP_${_language}}${_include}")
  882. else()
  883. list (APPEND ${_cmdVar} "${CMAKE_INCLUDE_FLAG_${_language}}${CMAKE_INCLUDE_FLAG_SEP_${_language}}${_include}")
  884. endif()
  885. endif()
  886. endforeach()
  887. endif()
  888. set (${_cmdVar} ${${_cmdVar}} PARENT_SCOPE)
  889. endfunction()
  890. function (cotire_add_frameworks_to_cmd _cmdVar _language _includesVar _systemIncludesVar)
  891. if (APPLE)
  892. set (_frameworkDirs "")
  893. foreach (_include ${${_includesVar}})
  894. if (IS_ABSOLUTE "${_include}" AND _include MATCHES "\\.framework$")
  895. get_filename_component(_frameworkDir "${_include}" DIRECTORY)
  896. list (APPEND _frameworkDirs "${_frameworkDir}")
  897. endif()
  898. endforeach()
  899. set (_systemFrameworkDirs "")
  900. foreach (_include ${${_systemIncludesVar}})
  901. if (IS_ABSOLUTE "${_include}" AND _include MATCHES "\\.framework$")
  902. get_filename_component(_frameworkDir "${_include}" DIRECTORY)
  903. list (APPEND _systemFrameworkDirs "${_frameworkDir}")
  904. endif()
  905. endforeach()
  906. if (_systemFrameworkDirs)
  907. list (APPEND _frameworkDirs ${_systemFrameworkDirs})
  908. endif()
  909. if (_frameworkDirs)
  910. list (REMOVE_DUPLICATES _frameworkDirs)
  911. foreach (_frameworkDir ${_frameworkDirs})
  912. set (_index -1)
  913. if ("${CMAKE_${_language}_SYSTEM_FRAMEWORK_SEARCH_FLAG}" MATCHES ".+")
  914. list (FIND _systemFrameworkDirs "${_frameworkDir}" _index)
  915. endif()
  916. if (_index GREATER -1)
  917. list (APPEND ${_cmdVar} "${CMAKE_${_language}_SYSTEM_FRAMEWORK_SEARCH_FLAG}${_frameworkDir}")
  918. else()
  919. list (APPEND ${_cmdVar} "${CMAKE_${_language}_FRAMEWORK_SEARCH_FLAG}${_frameworkDir}")
  920. endif()
  921. endforeach()
  922. endif()
  923. endif()
  924. set (${_cmdVar} ${${_cmdVar}} PARENT_SCOPE)
  925. endfunction()
  926. macro (cotire_add_compile_flags_to_cmd _cmdVar)
  927. foreach (_flag ${ARGN})
  928. list (APPEND ${_cmdVar} "${_flag}")
  929. endforeach()
  930. endmacro()
  931. function (cotire_check_file_up_to_date _fileIsUpToDateVar _file)
  932. if (EXISTS "${_file}")
  933. set (_triggerFile "")
  934. foreach (_dependencyFile ${ARGN})
  935. if (EXISTS "${_dependencyFile}")
  936. # IS_NEWER_THAN returns TRUE if both files have the same timestamp
  937. # thus we do the comparison in both directions to exclude ties
  938. if ("${_dependencyFile}" IS_NEWER_THAN "${_file}" AND
  939. NOT "${_file}" IS_NEWER_THAN "${_dependencyFile}")
  940. set (_triggerFile "${_dependencyFile}")
  941. break()
  942. endif()
  943. endif()
  944. endforeach()
  945. if (_triggerFile)
  946. if (COTIRE_VERBOSE)
  947. get_filename_component(_fileName "${_file}" NAME)
  948. message (STATUS "${_fileName} update triggered by ${_triggerFile} change.")
  949. endif()
  950. set (${_fileIsUpToDateVar} FALSE PARENT_SCOPE)
  951. else()
  952. if (COTIRE_VERBOSE)
  953. get_filename_component(_fileName "${_file}" NAME)
  954. message (STATUS "${_fileName} is up-to-date.")
  955. endif()
  956. set (${_fileIsUpToDateVar} TRUE PARENT_SCOPE)
  957. endif()
  958. else()
  959. if (COTIRE_VERBOSE)
  960. get_filename_component(_fileName "${_file}" NAME)
  961. message (STATUS "${_fileName} does not exist yet.")
  962. endif()
  963. set (${_fileIsUpToDateVar} FALSE PARENT_SCOPE)
  964. endif()
  965. endfunction()
  966. macro (cotire_find_closest_relative_path _headerFile _includeDirs _relPathVar)
  967. set (${_relPathVar} "")
  968. foreach (_includeDir ${_includeDirs})
  969. if (IS_DIRECTORY "${_includeDir}")
  970. file (RELATIVE_PATH _relPath "${_includeDir}" "${_headerFile}")
  971. if (NOT IS_ABSOLUTE "${_relPath}" AND NOT "${_relPath}" MATCHES "^\\.\\.")
  972. string (LENGTH "${${_relPathVar}}" _closestLen)
  973. string (LENGTH "${_relPath}" _relLen)
  974. if (_closestLen EQUAL 0 OR _relLen LESS _closestLen)
  975. set (${_relPathVar} "${_relPath}")
  976. endif()
  977. endif()
  978. elseif ("${_includeDir}" STREQUAL "${_headerFile}")
  979. # if path matches exactly, return short non-empty string
  980. set (${_relPathVar} "1")
  981. break()
  982. endif()
  983. endforeach()
  984. endmacro()
  985. macro (cotire_check_header_file_location _headerFile _insideIncludeDirs _outsideIncludeDirs _headerIsInside)
  986. # check header path against ignored and honored include directories
  987. cotire_find_closest_relative_path("${_headerFile}" "${_insideIncludeDirs}" _insideRelPath)
  988. if (_insideRelPath)
  989. # header is inside, but could be become outside if there is a shorter outside match
  990. cotire_find_closest_relative_path("${_headerFile}" "${_outsideIncludeDirs}" _outsideRelPath)
  991. if (_outsideRelPath)
  992. string (LENGTH "${_insideRelPath}" _insideRelPathLen)
  993. string (LENGTH "${_outsideRelPath}" _outsideRelPathLen)
  994. if (_outsideRelPathLen LESS _insideRelPathLen)
  995. set (${_headerIsInside} FALSE)
  996. else()
  997. set (${_headerIsInside} TRUE)
  998. endif()
  999. else()
  1000. set (${_headerIsInside} TRUE)
  1001. endif()
  1002. else()
  1003. # header is outside
  1004. set (${_headerIsInside} FALSE)
  1005. endif()
  1006. endmacro()
  1007. macro (cotire_check_ignore_header_file_path _headerFile _headerIsIgnoredVar)
  1008. if (NOT EXISTS "${_headerFile}")
  1009. set (${_headerIsIgnoredVar} TRUE)
  1010. elseif (IS_DIRECTORY "${_headerFile}")
  1011. set (${_headerIsIgnoredVar} TRUE)
  1012. elseif ("${_headerFile}" MATCHES "\\.\\.|[_-]fixed" AND "${_headerFile}" MATCHES "\\.h$")
  1013. # heuristic: ignore C headers with embedded parent directory references or "-fixed" or "_fixed" in path
  1014. # these often stem from using GCC #include_next tricks, which may break the precompiled header compilation
  1015. # with the error message "error: no include path in which to search for header.h"
  1016. set (${_headerIsIgnoredVar} TRUE)
  1017. else()
  1018. set (${_headerIsIgnoredVar} FALSE)
  1019. endif()
  1020. endmacro()
  1021. macro (cotire_check_ignore_header_file_ext _headerFile _ignoreExtensionsVar _headerIsIgnoredVar)
  1022. # check header file extension
  1023. cotire_get_source_file_extension("${_headerFile}" _headerFileExt)
  1024. set (${_headerIsIgnoredVar} FALSE)
  1025. if (_headerFileExt)
  1026. list (FIND ${_ignoreExtensionsVar} "${_headerFileExt}" _index)
  1027. if (_index GREATER -1)
  1028. set (${_headerIsIgnoredVar} TRUE)
  1029. endif()
  1030. endif()
  1031. endmacro()
  1032. macro (cotire_parse_line _line _headerFileVar _headerDepthVar)
  1033. if (MSVC)
  1034. # cl.exe /showIncludes output looks different depending on the language pack used, e.g.:
  1035. # English: "Note: including file: C:\directory\file"
  1036. # German: "Hinweis: Einlesen der Datei: C:\directory\file"
  1037. # We use a very general regular expression, relying on the presence of the : characters
  1038. if (_line MATCHES "( +)([a-zA-Z]:[^:]+)$")
  1039. # Visual Studio compiler output
  1040. string (LENGTH "${CMAKE_MATCH_1}" ${_headerDepthVar})
  1041. get_filename_component(${_headerFileVar} "${CMAKE_MATCH_2}" ABSOLUTE)
  1042. else()
  1043. set (${_headerFileVar} "")
  1044. set (${_headerDepthVar} 0)
  1045. endif()
  1046. else()
  1047. if (_line MATCHES "^(\\.+) (.*)$")
  1048. # GCC like output
  1049. string (LENGTH "${CMAKE_MATCH_1}" ${_headerDepthVar})
  1050. if (IS_ABSOLUTE "${CMAKE_MATCH_2}")
  1051. set (${_headerFileVar} "${CMAKE_MATCH_2}")
  1052. else()
  1053. get_filename_component(${_headerFileVar} "${CMAKE_MATCH_2}" REALPATH)
  1054. endif()
  1055. else()
  1056. set (${_headerFileVar} "")
  1057. set (${_headerDepthVar} 0)
  1058. endif()
  1059. endif()
  1060. endmacro()
  1061. function (cotire_parse_includes _language _scanOutput _ignoredIncludeDirs _honoredIncludeDirs _ignoredExtensions _selectedIncludesVar _unparsedLinesVar)
  1062. if (WIN32)
  1063. # prevent CMake macro invocation errors due to backslash characters in Windows paths
  1064. string (REPLACE "\\" "/" _scanOutput "${_scanOutput}")
  1065. endif()
  1066. # canonize slashes
  1067. string (REPLACE "//" "/" _scanOutput "${_scanOutput}")
  1068. # prevent semicolon from being interpreted as a line separator
  1069. string (REPLACE ";" "\\;" _scanOutput "${_scanOutput}")
  1070. # then separate lines
  1071. string (REGEX REPLACE "\n" ";" _scanOutput "${_scanOutput}")
  1072. list (LENGTH _scanOutput _len)
  1073. # remove duplicate lines to speed up parsing
  1074. list (REMOVE_DUPLICATES _scanOutput)
  1075. list (LENGTH _scanOutput _uniqueLen)
  1076. if (COTIRE_VERBOSE OR COTIRE_DEBUG)
  1077. message (STATUS "Scanning ${_uniqueLen} unique lines of ${_len} for includes")
  1078. if (_ignoredExtensions)
  1079. message (STATUS "Ignored extensions: ${_ignoredExtensions}")
  1080. endif()
  1081. if (_ignoredIncludeDirs)
  1082. message (STATUS "Ignored paths: ${_ignoredIncludeDirs}")
  1083. endif()
  1084. if (_honoredIncludeDirs)
  1085. message (STATUS "Included paths: ${_honoredIncludeDirs}")
  1086. endif()
  1087. endif()
  1088. set (_sourceFiles ${ARGN})
  1089. set (_selectedIncludes "")
  1090. set (_unparsedLines "")
  1091. # stack keeps track of inside/outside project status of processed header files
  1092. set (_headerIsInsideStack "")
  1093. foreach (_line IN LISTS _scanOutput)
  1094. if (_line)
  1095. cotire_parse_line("${_line}" _headerFile _headerDepth)
  1096. if (_headerFile)
  1097. cotire_check_header_file_location("${_headerFile}" "${_ignoredIncludeDirs}" "${_honoredIncludeDirs}" _headerIsInside)
  1098. if (COTIRE_DEBUG)
  1099. message (STATUS "${_headerDepth}: ${_headerFile} ${_headerIsInside}")
  1100. endif()
  1101. # update stack
  1102. list (LENGTH _headerIsInsideStack _stackLen)
  1103. if (_headerDepth GREATER _stackLen)
  1104. math (EXPR _stackLen "${_stackLen} + 1")
  1105. foreach (_index RANGE ${_stackLen} ${_headerDepth})
  1106. list (APPEND _headerIsInsideStack ${_headerIsInside})
  1107. endforeach()
  1108. else()
  1109. foreach (_index RANGE ${_headerDepth} ${_stackLen})
  1110. list (REMOVE_AT _headerIsInsideStack -1)
  1111. endforeach()
  1112. list (APPEND _headerIsInsideStack ${_headerIsInside})
  1113. endif()
  1114. if (COTIRE_DEBUG)
  1115. message (STATUS "${_headerIsInsideStack}")
  1116. endif()
  1117. # header is a candidate if it is outside project
  1118. if (NOT _headerIsInside)
  1119. # get parent header file's inside/outside status
  1120. if (_headerDepth GREATER 1)
  1121. math (EXPR _index "${_headerDepth} - 2")
  1122. list (GET _headerIsInsideStack ${_index} _parentHeaderIsInside)
  1123. else()
  1124. set (_parentHeaderIsInside TRUE)
  1125. endif()
  1126. # select header file if parent header file is inside project
  1127. # (e.g., a project header file that includes a standard header file)
  1128. if (_parentHeaderIsInside)
  1129. cotire_check_ignore_header_file_path("${_headerFile}" _headerIsIgnored)
  1130. if (NOT _headerIsIgnored)
  1131. cotire_check_ignore_header_file_ext("${_headerFile}" _ignoredExtensions _headerIsIgnored)
  1132. if (NOT _headerIsIgnored)
  1133. list (APPEND _selectedIncludes "${_headerFile}")
  1134. else()
  1135. # fix header's inside status on stack, it is ignored by extension now
  1136. list (REMOVE_AT _headerIsInsideStack -1)
  1137. list (APPEND _headerIsInsideStack TRUE)
  1138. endif()
  1139. endif()
  1140. if (COTIRE_DEBUG)
  1141. message (STATUS "${_headerFile} ${_ignoredExtensions} ${_headerIsIgnored}")
  1142. endif()
  1143. endif()
  1144. endif()
  1145. else()
  1146. if (MSVC)
  1147. # for cl.exe do not keep unparsed lines which solely consist of a source file name
  1148. string (FIND "${_sourceFiles}" "${_line}" _index)
  1149. if (_index LESS 0)
  1150. list (APPEND _unparsedLines "${_line}")
  1151. endif()
  1152. else()
  1153. list (APPEND _unparsedLines "${_line}")
  1154. endif()
  1155. endif()
  1156. endif()
  1157. endforeach()
  1158. list (REMOVE_DUPLICATES _selectedIncludes)
  1159. set (${_selectedIncludesVar} ${_selectedIncludes} PARENT_SCOPE)
  1160. set (${_unparsedLinesVar} ${_unparsedLines} PARENT_SCOPE)
  1161. endfunction()
  1162. function (cotire_scan_includes _includesVar)
  1163. set(_options "")
  1164. set(_oneValueArgs COMPILER_ID COMPILER_EXECUTABLE COMPILER_ARG1 COMPILER_VERSION LANGUAGE UNPARSED_LINES SCAN_RESULT)
  1165. set(_multiValueArgs COMPILE_DEFINITIONS COMPILE_FLAGS INCLUDE_DIRECTORIES SYSTEM_INCLUDE_DIRECTORIES
  1166. IGNORE_PATH INCLUDE_PATH IGNORE_EXTENSIONS INCLUDE_PRIORITY_PATH COMPILER_LAUNCHER)
  1167. cmake_parse_arguments(_option "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
  1168. set (_sourceFiles ${_option_UNPARSED_ARGUMENTS})
  1169. if (NOT _option_LANGUAGE)
  1170. set (_option_LANGUAGE "CXX")
  1171. endif()
  1172. if (NOT _option_COMPILER_ID)
  1173. set (_option_COMPILER_ID "${CMAKE_${_option_LANGUAGE}_ID}")
  1174. endif()
  1175. if (NOT _option_COMPILER_VERSION)
  1176. set (_option_COMPILER_VERSION "${CMAKE_${_option_LANGUAGE}_COMPILER_VERSION}")
  1177. endif()
  1178. cotire_init_compile_cmd(_cmd "${_option_LANGUAGE}" "${_option_COMPILER_LAUNCHER}" "${_option_COMPILER_EXECUTABLE}" "${_option_COMPILER_ARG1}")
  1179. cotire_add_definitions_to_cmd(_cmd "${_option_LANGUAGE}" ${_option_COMPILE_DEFINITIONS})
  1180. cotire_add_compile_flags_to_cmd(_cmd ${_option_COMPILE_FLAGS})
  1181. cotire_add_includes_to_cmd(_cmd "${_option_LANGUAGE}" _option_INCLUDE_DIRECTORIES _option_SYSTEM_INCLUDE_DIRECTORIES)
  1182. cotire_add_frameworks_to_cmd(_cmd "${_option_LANGUAGE}" _option_INCLUDE_DIRECTORIES _option_SYSTEM_INCLUDE_DIRECTORIES)
  1183. cotire_add_makedep_flags("${_option_LANGUAGE}" "${_option_COMPILER_ID}" "${_option_COMPILER_VERSION}" _cmd)
  1184. # only consider existing source files for scanning
  1185. set (_existingSourceFiles "")
  1186. foreach (_sourceFile ${_sourceFiles})
  1187. if (EXISTS "${_sourceFile}")
  1188. list (APPEND _existingSourceFiles "${_sourceFile}")
  1189. endif()
  1190. endforeach()
  1191. if (NOT _existingSourceFiles)
  1192. set (${_includesVar} "" PARENT_SCOPE)
  1193. return()
  1194. endif()
  1195. list (APPEND _cmd ${_existingSourceFiles})
  1196. if (COTIRE_VERBOSE)
  1197. message (STATUS "execute_process: ${_cmd}")
  1198. endif()
  1199. if (_option_COMPILER_ID MATCHES "MSVC")
  1200. # cl.exe messes with the output streams unless the environment variable VS_UNICODE_OUTPUT is cleared
  1201. unset (ENV{VS_UNICODE_OUTPUT})
  1202. endif()
  1203. execute_process(
  1204. COMMAND ${_cmd}
  1205. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  1206. RESULT_VARIABLE _result
  1207. OUTPUT_QUIET
  1208. ERROR_VARIABLE _output)
  1209. if (_result)
  1210. message (STATUS "Result ${_result} scanning includes of ${_existingSourceFiles}.")
  1211. endif()
  1212. cotire_parse_includes(
  1213. "${_option_LANGUAGE}" "${_output}"
  1214. "${_option_IGNORE_PATH}" "${_option_INCLUDE_PATH}"
  1215. "${_option_IGNORE_EXTENSIONS}"
  1216. _includes _unparsedLines
  1217. ${_sourceFiles})
  1218. if (_option_INCLUDE_PRIORITY_PATH)
  1219. set (_sortedIncludes "")
  1220. foreach (_priorityPath ${_option_INCLUDE_PRIORITY_PATH})
  1221. foreach (_include ${_includes})
  1222. string (FIND ${_include} ${_priorityPath} _position)
  1223. if (_position GREATER -1)
  1224. list (APPEND _sortedIncludes ${_include})
  1225. endif()
  1226. endforeach()
  1227. endforeach()
  1228. if (_sortedIncludes)
  1229. list (INSERT _includes 0 ${_sortedIncludes})
  1230. list (REMOVE_DUPLICATES _includes)
  1231. endif()
  1232. endif()
  1233. set (${_includesVar} ${_includes} PARENT_SCOPE)
  1234. if (_option_UNPARSED_LINES)
  1235. set (${_option_UNPARSED_LINES} ${_unparsedLines} PARENT_SCOPE)
  1236. endif()
  1237. if (_option_SCAN_RESULT)
  1238. set (${_option_SCAN_RESULT} ${_result} PARENT_SCOPE)
  1239. endif()
  1240. endfunction()
  1241. macro (cotire_append_undefs _contentsVar)
  1242. set (_undefs ${ARGN})
  1243. if (_undefs)
  1244. list (REMOVE_DUPLICATES _undefs)
  1245. foreach (_definition ${_undefs})
  1246. list (APPEND ${_contentsVar} "#undef ${_definition}")
  1247. endforeach()
  1248. endif()
  1249. endmacro()
  1250. macro (cotire_comment_str _language _commentText _commentVar)
  1251. if ("${_language}" STREQUAL "CMAKE")
  1252. set (${_commentVar} "# ${_commentText}")
  1253. else()
  1254. set (${_commentVar} "/* ${_commentText} */")
  1255. endif()
  1256. endmacro()
  1257. function (cotire_write_file _language _file _contents _force)
  1258. get_filename_component(_moduleName "${COTIRE_CMAKE_MODULE_FILE}" NAME)
  1259. cotire_comment_str("${_language}" "${_moduleName} ${COTIRE_CMAKE_MODULE_VERSION} generated file" _header1)
  1260. cotire_comment_str("${_language}" "${_file}" _header2)
  1261. set (_contents "${_header1}\n${_header2}\n${_contents}")
  1262. if (COTIRE_DEBUG)
  1263. message (STATUS "${_contents}")
  1264. endif()
  1265. if (_force OR NOT EXISTS "${_file}")
  1266. file (WRITE "${_file}" "${_contents}")
  1267. else()
  1268. file (READ "${_file}" _oldContents)
  1269. if (NOT "${_oldContents}" STREQUAL "${_contents}")
  1270. file (WRITE "${_file}" "${_contents}")
  1271. else()
  1272. if (COTIRE_DEBUG)
  1273. message (STATUS "${_file} unchanged")
  1274. endif()
  1275. endif()
  1276. endif()
  1277. endfunction()
  1278. function (cotire_generate_unity_source _unityFile)
  1279. set(_options "")
  1280. set(_oneValueArgs LANGUAGE)
  1281. set(_multiValueArgs
  1282. DEPENDS SOURCES_COMPILE_DEFINITIONS
  1283. PRE_UNDEFS SOURCES_PRE_UNDEFS POST_UNDEFS SOURCES_POST_UNDEFS PROLOGUE EPILOGUE)
  1284. cmake_parse_arguments(_option "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
  1285. if (_option_DEPENDS)
  1286. cotire_check_file_up_to_date(_unityFileIsUpToDate "${_unityFile}" ${_option_DEPENDS})
  1287. if (_unityFileIsUpToDate)
  1288. return()
  1289. endif()
  1290. endif()
  1291. set (_sourceFiles ${_option_UNPARSED_ARGUMENTS})
  1292. if (NOT _option_PRE_UNDEFS)
  1293. set (_option_PRE_UNDEFS "")
  1294. endif()
  1295. if (NOT _option_SOURCES_PRE_UNDEFS)
  1296. set (_option_SOURCES_PRE_UNDEFS "")
  1297. endif()
  1298. if (NOT _option_POST_UNDEFS)
  1299. set (_option_POST_UNDEFS "")
  1300. endif()
  1301. if (NOT _option_SOURCES_POST_UNDEFS)
  1302. set (_option_SOURCES_POST_UNDEFS "")
  1303. endif()
  1304. set (_contents "")
  1305. if (_option_PROLOGUE)
  1306. list (APPEND _contents ${_option_PROLOGUE})
  1307. endif()
  1308. if (_option_LANGUAGE AND _sourceFiles)
  1309. if ("${_option_LANGUAGE}" STREQUAL "CXX")
  1310. list (APPEND _contents "#ifdef __cplusplus")
  1311. elseif ("${_option_LANGUAGE}" STREQUAL "C")
  1312. list (APPEND _contents "#ifndef __cplusplus")
  1313. endif()
  1314. endif()
  1315. set (_compileUndefinitions "")
  1316. foreach (_sourceFile ${_sourceFiles})
  1317. cotire_get_source_compile_definitions(
  1318. "${_option_CONFIGURATION}" "${_option_LANGUAGE}" "${_sourceFile}" _compileDefinitions
  1319. ${_option_SOURCES_COMPILE_DEFINITIONS})
  1320. cotire_get_source_undefs("${_sourceFile}" COTIRE_UNITY_SOURCE_PRE_UNDEFS _sourcePreUndefs ${_option_SOURCES_PRE_UNDEFS})
  1321. cotire_get_source_undefs("${_sourceFile}" COTIRE_UNITY_SOURCE_POST_UNDEFS _sourcePostUndefs ${_option_SOURCES_POST_UNDEFS})
  1322. if (_option_PRE_UNDEFS)
  1323. list (APPEND _compileUndefinitions ${_option_PRE_UNDEFS})
  1324. endif()
  1325. if (_sourcePreUndefs)
  1326. list (APPEND _compileUndefinitions ${_sourcePreUndefs})
  1327. endif()
  1328. if (_compileUndefinitions)
  1329. cotire_append_undefs(_contents ${_compileUndefinitions})
  1330. set (_compileUndefinitions "")
  1331. endif()
  1332. if (_sourcePostUndefs)
  1333. list (APPEND _compileUndefinitions ${_sourcePostUndefs})
  1334. endif()
  1335. if (_option_POST_UNDEFS)
  1336. list (APPEND _compileUndefinitions ${_option_POST_UNDEFS})
  1337. endif()
  1338. foreach (_definition ${_compileDefinitions})
  1339. if (_definition MATCHES "^([a-zA-Z0-9_]+)=(.+)$")
  1340. list (APPEND _contents "#define ${CMAKE_MATCH_1} ${CMAKE_MATCH_2}")
  1341. list (INSERT _compileUndefinitions 0 "${CMAKE_MATCH_1}")
  1342. else()
  1343. list (APPEND _contents "#define ${_definition}")
  1344. list (INSERT _compileUndefinitions 0 "${_definition}")
  1345. endif()
  1346. endforeach()
  1347. # use absolute path as source file location
  1348. get_filename_component(_sourceFileLocation "${_sourceFile}" ABSOLUTE)
  1349. if (WIN32)
  1350. file (TO_NATIVE_PATH "${_sourceFileLocation}" _sourceFileLocation)
  1351. endif()
  1352. list (APPEND _contents "#include \"${_sourceFileLocation}\"")
  1353. endforeach()
  1354. if (_compileUndefinitions)
  1355. cotire_append_undefs(_contents ${_compileUndefinitions})
  1356. set (_compileUndefinitions "")
  1357. endif()
  1358. if (_option_LANGUAGE AND _sourceFiles)
  1359. list (APPEND _contents "#endif")
  1360. endif()
  1361. if (_option_EPILOGUE)
  1362. list (APPEND _contents ${_option_EPILOGUE})
  1363. endif()
  1364. list (APPEND _contents "")
  1365. string (REPLACE ";" "\n" _contents "${_contents}")
  1366. if (COTIRE_VERBOSE)
  1367. message ("${_contents}")
  1368. endif()
  1369. cotire_write_file("${_option_LANGUAGE}" "${_unityFile}" "${_contents}" TRUE)
  1370. endfunction()
  1371. function (cotire_generate_prefix_header _prefixFile)
  1372. set(_options "")
  1373. set(_oneValueArgs LANGUAGE COMPILER_EXECUTABLE COMPILER_ARG1 COMPILER_ID COMPILER_VERSION)
  1374. set(_multiValueArgs DEPENDS COMPILE_DEFINITIONS COMPILE_FLAGS
  1375. INCLUDE_DIRECTORIES SYSTEM_INCLUDE_DIRECTORIES IGNORE_PATH INCLUDE_PATH
  1376. IGNORE_EXTENSIONS INCLUDE_PRIORITY_PATH COMPILER_LAUNCHER)
  1377. cmake_parse_arguments(_option "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
  1378. if (NOT _option_COMPILER_ID)
  1379. set (_option_COMPILER_ID "${CMAKE_${_option_LANGUAGE}_ID}")
  1380. endif()
  1381. if (NOT _option_COMPILER_VERSION)
  1382. set (_option_COMPILER_VERSION "${CMAKE_${_option_LANGUAGE}_COMPILER_VERSION}")
  1383. endif()
  1384. if (_option_DEPENDS)
  1385. cotire_check_file_up_to_date(_prefixFileIsUpToDate "${_prefixFile}" ${_option_DEPENDS})
  1386. if (_prefixFileIsUpToDate)
  1387. # create empty log file
  1388. set (_unparsedLinesFile "${_prefixFile}.log")
  1389. file (WRITE "${_unparsedLinesFile}" "")
  1390. return()
  1391. endif()
  1392. endif()
  1393. set (_prologue "")
  1394. set (_epilogue "")
  1395. if (_option_COMPILER_ID MATCHES "Clang")
  1396. set (_prologue "#pragma clang system_header")
  1397. elseif (_option_COMPILER_ID MATCHES "GNU")
  1398. set (_prologue "#pragma GCC system_header")
  1399. elseif (_option_COMPILER_ID MATCHES "MSVC")
  1400. set (_prologue "#pragma warning(push, 0)")
  1401. set (_epilogue "#pragma warning(pop)")
  1402. elseif (_option_COMPILER_ID MATCHES "Intel")
  1403. # Intel compiler requires hdrstop pragma to stop generating PCH file
  1404. set (_epilogue "#pragma hdrstop")
  1405. endif()
  1406. set (_sourceFiles ${_option_UNPARSED_ARGUMENTS})
  1407. cotire_scan_includes(_selectedHeaders ${_sourceFiles}
  1408. LANGUAGE "${_option_LANGUAGE}"
  1409. COMPILER_LAUNCHER "${_option_COMPILER_LAUNCHER}"
  1410. COMPILER_EXECUTABLE "${_option_COMPILER_EXECUTABLE}"
  1411. COMPILER_ARG1 "${_option_COMPILER_ARG1}"
  1412. COMPILER_ID "${_option_COMPILER_ID}"
  1413. COMPILER_VERSION "${_option_COMPILER_VERSION}"
  1414. COMPILE_DEFINITIONS ${_option_COMPILE_DEFINITIONS}
  1415. COMPILE_FLAGS ${_option_COMPILE_FLAGS}
  1416. INCLUDE_DIRECTORIES ${_option_INCLUDE_DIRECTORIES}
  1417. SYSTEM_INCLUDE_DIRECTORIES ${_option_SYSTEM_INCLUDE_DIRECTORIES}
  1418. IGNORE_PATH ${_option_IGNORE_PATH}
  1419. INCLUDE_PATH ${_option_INCLUDE_PATH}
  1420. IGNORE_EXTENSIONS ${_option_IGNORE_EXTENSIONS}
  1421. INCLUDE_PRIORITY_PATH ${_option_INCLUDE_PRIORITY_PATH}
  1422. UNPARSED_LINES _unparsedLines
  1423. SCAN_RESULT _scanResult)
  1424. cotire_generate_unity_source("${_prefixFile}"
  1425. PROLOGUE ${_prologue} EPILOGUE ${_epilogue} LANGUAGE "${_option_LANGUAGE}" ${_selectedHeaders})
  1426. set (_unparsedLinesFile "${_prefixFile}.log")
  1427. if (_unparsedLines)
  1428. if (COTIRE_VERBOSE OR _scanResult OR NOT _selectedHeaders)
  1429. list (LENGTH _unparsedLines _skippedLineCount)
  1430. message (STATUS "${_skippedLineCount} line(s) skipped, see ${_unparsedLinesFile}")
  1431. endif()
  1432. string (REPLACE ";" "\n" _unparsedLines "${_unparsedLines}")
  1433. endif()
  1434. file (WRITE "${_unparsedLinesFile}" "${_unparsedLines}")
  1435. endfunction()
  1436. function (cotire_add_makedep_flags _language _compilerID _compilerVersion _flagsVar)
  1437. set (_flags ${${_flagsVar}})
  1438. if (_compilerID MATCHES "MSVC")
  1439. # cl.exe options used
  1440. # /nologo suppresses display of sign-on banner
  1441. # /TC treat all files named on the command line as C source files
  1442. # /TP treat all files named on the command line as C++ source files
  1443. # /EP preprocess to stdout without #line directives
  1444. # /showIncludes list include files
  1445. set (_sourceFileTypeC "/TC")
  1446. set (_sourceFileTypeCXX "/TP")
  1447. if (_flags)
  1448. # append to list
  1449. list (APPEND _flags /nologo "${_sourceFileType${_language}}" /EP /showIncludes)
  1450. else()
  1451. # return as a flag string
  1452. set (_flags "${_sourceFileType${_language}} /EP /showIncludes")
  1453. endif()
  1454. elseif (_compilerID MATCHES "GNU")
  1455. # GCC options used
  1456. # -H print the name of each header file used
  1457. # -E invoke preprocessor
  1458. # -fdirectives-only do not expand macros, requires GCC >= 4.3
  1459. if (_flags)
  1460. # append to list
  1461. list (APPEND _flags -H -E)
  1462. if (NOT "${_compilerVersion}" VERSION_LESS "4.3.0")
  1463. list (APPEND _flags "-fdirectives-only")
  1464. endif()
  1465. else()
  1466. # return as a flag string
  1467. set (_flags "-H -E")
  1468. if (NOT "${_compilerVersion}" VERSION_LESS "4.3.0")
  1469. set (_flags "${_flags} -fdirectives-only")
  1470. endif()
  1471. endif()
  1472. elseif (_compilerID MATCHES "Clang")
  1473. # Clang options used
  1474. # -H print the name of each header file used
  1475. # -E invoke preprocessor
  1476. # -fno-color-diagnostics don't prints diagnostics in color
  1477. if (_flags)
  1478. # append to list
  1479. list (APPEND _flags -H -E -fno-color-diagnostics)
  1480. else()
  1481. # return as a flag string
  1482. set (_flags "-H -E -fno-color-diagnostics")
  1483. endif()
  1484. elseif (_compilerID MATCHES "Intel")
  1485. if (WIN32)
  1486. # Windows Intel options used
  1487. # /nologo do not display compiler version information
  1488. # /QH display the include file order
  1489. # /EP preprocess to stdout, omitting #line directives
  1490. # /TC process all source or unrecognized file types as C source files
  1491. # /TP process all source or unrecognized file types as C++ source files
  1492. set (_sourceFileTypeC "/TC")
  1493. set (_sourceFileTypeCXX "/TP")
  1494. if (_flags)
  1495. # append to list
  1496. list (APPEND _flags /nologo "${_sourceFileType${_language}}" /EP /QH)
  1497. else()
  1498. # return as a flag string
  1499. set (_flags "${_sourceFileType${_language}} /EP /QH")
  1500. endif()
  1501. else()
  1502. # Linux / Mac OS X Intel options used
  1503. # -H print the name of each header file used
  1504. # -EP preprocess to stdout, omitting #line directives
  1505. # -Kc++ process all source or unrecognized file types as C++ source files
  1506. if (_flags)
  1507. # append to list
  1508. if ("${_language}" STREQUAL "CXX")
  1509. list (APPEND _flags -Kc++)
  1510. endif()
  1511. list (APPEND _flags -H -EP)
  1512. else()
  1513. # return as a flag string
  1514. if ("${_language}" STREQUAL "CXX")
  1515. set (_flags "-Kc++ ")
  1516. endif()
  1517. set (_flags "${_flags}-H -EP")
  1518. endif()
  1519. endif()
  1520. else()
  1521. message (FATAL_ERROR "cotire: unsupported ${_language} compiler ${_compilerID} version ${_compilerVersion}.")
  1522. endif()
  1523. set (${_flagsVar} ${_flags} PARENT_SCOPE)
  1524. endfunction()
  1525. function (cotire_add_pch_compilation_flags _language _compilerID _compilerVersion _prefixFile _pchFile _hostFile _flagsVar)
  1526. set (_flags ${${_flagsVar}})
  1527. if (_compilerID MATCHES "MSVC")
  1528. file (TO_NATIVE_PATH "${_prefixFile}" _prefixFileNative)
  1529. file (TO_NATIVE_PATH "${_pchFile}" _pchFileNative)
  1530. file (TO_NATIVE_PATH "${_hostFile}" _hostFileNative)
  1531. # cl.exe options used
  1532. # /Yc creates a precompiled header file
  1533. # /Fp specifies precompiled header binary file name
  1534. # /FI forces inclusion of file
  1535. # /TC treat all files named on the command line as C source files
  1536. # /TP treat all files named on the command line as C++ source files
  1537. # /Zs syntax check only
  1538. # /Zm precompiled header memory allocation scaling factor
  1539. set (_sourceFileTypeC "/TC")
  1540. set (_sourceFileTypeCXX "/TP")
  1541. if (_flags)
  1542. # append to list
  1543. list (APPEND _flags /nologo "${_sourceFileType${_language}}"
  1544. "/Yc${_prefixFileNative}" "/Fp${_pchFileNative}" "/FI${_prefixFileNative}" /Zs "${_hostFileNative}")
  1545. if (COTIRE_PCH_MEMORY_SCALING_FACTOR)
  1546. list (APPEND _flags "/Zm${COTIRE_PCH_MEMORY_SCALING_FACTOR}")
  1547. endif()
  1548. else()
  1549. # return as a flag string
  1550. set (_flags "/Yc\"${_prefixFileNative}\" /Fp\"${_pchFileNative}\" /FI\"${_prefixFileNative}\"")
  1551. if (COTIRE_PCH_MEMORY_SCALING_FACTOR)
  1552. set (_flags "${_flags} /Zm${COTIRE_PCH_MEMORY_SCALING_FACTOR}")
  1553. endif()
  1554. endif()
  1555. elseif (_compilerID MATCHES "GNU|Clang")
  1556. # GCC / Clang options used
  1557. # -x specify the source language
  1558. # -c compile but do not link
  1559. # -o place output in file
  1560. # note that we cannot use -w to suppress all warnings upon pre-compiling, because turning off a warning may
  1561. # alter compile flags as a side effect (e.g., -Wwrite-string implies -fconst-strings)
  1562. set (_xLanguage_C "c-header")
  1563. set (_xLanguage_CXX "c++-header")
  1564. if (_flags)
  1565. # append to list
  1566. list (APPEND _flags "-x" "${_xLanguage_${_language}}" "-c" "${_prefixFile}" -o "${_pchFile}")
  1567. else()
  1568. # return as a flag string
  1569. set (_flags "-x ${_xLanguage_${_language}} -c \"${_prefixFile}\" -o \"${_pchFile}\"")
  1570. endif()
  1571. elseif (_compilerID MATCHES "Intel")
  1572. if (WIN32)
  1573. file (TO_NATIVE_PATH "${_prefixFile}" _prefixFileNative)
  1574. file (TO_NATIVE_PATH "${_pchFile}" _pchFileNative)
  1575. file (TO_NATIVE_PATH "${_hostFile}" _hostFileNative)
  1576. # Windows Intel options used
  1577. # /nologo do not display compiler version information
  1578. # /Yc create a precompiled header (PCH) file
  1579. # /Fp specify a path or file name for precompiled header files
  1580. # /FI tells the preprocessor to include a specified file name as the header file
  1581. # /TC process all source or unrecognized file types as C source files
  1582. # /TP process all source or unrecognized file types as C++ source files
  1583. # /Zs syntax check only
  1584. # /Wpch-messages enable diagnostics related to pre-compiled headers (requires Intel XE 2013 Update 2)
  1585. set (_sourceFileTypeC "/TC")
  1586. set (_sourceFileTypeCXX "/TP")
  1587. if (_flags)
  1588. # append to list
  1589. list (APPEND _flags /nologo "${_sourceFileType${_language}}"
  1590. "/Yc" "/Fp${_pchFileNative}" "/FI${_prefixFileNative}" /Zs "${_hostFileNative}")
  1591. if (NOT "${_compilerVersion}" VERSION_LESS "13.1.0")
  1592. list (APPEND _flags "/Wpch-messages")
  1593. endif()
  1594. else()
  1595. # return as a flag string
  1596. set (_flags "/Yc /Fp\"${_pchFileNative}\" /FI\"${_prefixFileNative}\"")
  1597. if (NOT "${_compilerVersion}" VERSION_LESS "13.1.0")
  1598. set (_flags "${_flags} /Wpch-messages")
  1599. endif()
  1600. endif()
  1601. else()
  1602. # Linux / Mac OS X Intel options used
  1603. # -pch-dir location for precompiled header files
  1604. # -pch-create name of the precompiled header (PCH) to create
  1605. # -Kc++ process all source or unrecognized file types as C++ source files
  1606. # -fsyntax-only check only for correct syntax
  1607. # -Wpch-messages enable diagnostics related to pre-compiled headers (requires Intel XE 2013 Update 2)
  1608. get_filename_component(_pchDir "${_pchFile}" DIRECTORY)
  1609. get_filename_component(_pchName "${_pchFile}" NAME)
  1610. set (_xLanguage_C "c-header")
  1611. set (_xLanguage_CXX "c++-header")
  1612. set (_pchSuppressMessages FALSE)
  1613. if ("${CMAKE_${_language}_FLAGS}" MATCHES ".*-Wno-pch-messages.*")
  1614. set(_pchSuppressMessages TRUE)
  1615. endif()
  1616. if (_flags)
  1617. # append to list
  1618. if ("${_language}" STREQUAL "CXX")
  1619. list (APPEND _flags -Kc++)
  1620. endif()
  1621. list (APPEND _flags "-include" "${_prefixFile}" "-pch-dir" "${_pchDir}" "-pch-create" "${_pchName}" "-fsyntax-only" "${_hostFile}")
  1622. if (NOT "${_compilerVersion}" VERSION_LESS "13.1.0")
  1623. if (NOT _pchSuppressMessages)
  1624. list (APPEND _flags "-Wpch-messages")
  1625. endif()
  1626. endif()
  1627. else()
  1628. # return as a flag string
  1629. set (_flags "-include \"${_prefixFile}\" -pch-dir \"${_pchDir}\" -pch-create \"${_pchName}\"")
  1630. if (NOT "${_compilerVersion}" VERSION_LESS "13.1.0")
  1631. if (NOT _pchSuppressMessages)
  1632. set (_flags "${_flags} -Wpch-messages")
  1633. endif()
  1634. endif()
  1635. endif()
  1636. endif()
  1637. else()
  1638. message (FATAL_ERROR "cotire: unsupported ${_language} compiler ${_compilerID} version ${_compilerVersion}.")
  1639. endif()
  1640. set (${_flagsVar} ${_flags} PARENT_SCOPE)
  1641. endfunction()
  1642. function (cotire_add_prefix_pch_inclusion_flags _language _compilerID _compilerVersion _prefixFile _pchFile _flagsVar)
  1643. set (_flags ${${_flagsVar}})
  1644. if (_compilerID MATCHES "MSVC")
  1645. file (TO_NATIVE_PATH "${_prefixFile}" _prefixFileNative)
  1646. # cl.exe options used
  1647. # /Yu uses a precompiled header file during build
  1648. # /Fp specifies precompiled header binary file name
  1649. # /FI forces inclusion of file
  1650. # /Zm precompiled header memory allocation scaling factor
  1651. if (_pchFile)
  1652. file (TO_NATIVE_PATH "${_pchFile}" _pchFileNative)
  1653. if (_flags)
  1654. # append to list
  1655. list (APPEND _flags "/Yu${_prefixFileNative}" "/Fp${_pchFileNative}" "/FI${_prefixFileNative}")
  1656. if (COTIRE_PCH_MEMORY_SCALING_FACTOR)
  1657. list (APPEND _flags "/Zm${COTIRE_PCH_MEMORY_SCALING_FACTOR}")
  1658. endif()
  1659. else()
  1660. # return as a flag string
  1661. set (_flags "/Yu\"${_prefixFileNative}\" /Fp\"${_pchFileNative}\" /FI\"${_prefixFileNative}\"")
  1662. if (COTIRE_PCH_MEMORY_SCALING_FACTOR)
  1663. set (_flags "${_flags} /Zm${COTIRE_PCH_MEMORY_SCALING_FACTOR}")
  1664. endif()
  1665. endif()
  1666. else()
  1667. # no precompiled header, force inclusion of prefix header
  1668. if (_flags)
  1669. # append to list
  1670. list (APPEND _flags "/FI${_prefixFileNative}")
  1671. else()
  1672. # return as a flag string
  1673. set (_flags "/FI\"${_prefixFileNative}\"")
  1674. endif()
  1675. endif()
  1676. elseif (_compilerID MATCHES "GNU")
  1677. # GCC options used
  1678. # -include process include file as the first line of the primary source file
  1679. # -Winvalid-pch warns if precompiled header is found but cannot be used
  1680. # note: ccache requires the -include flag to be used in order to process precompiled header correctly
  1681. if (_flags)
  1682. # append to list
  1683. list (APPEND _flags "-Winvalid-pch" "-include" "${_prefixFile}")
  1684. else()
  1685. # return as a flag string
  1686. set (_flags "-Winvalid-pch -include \"${_prefixFile}\"")
  1687. endif()
  1688. elseif (_compilerID MATCHES "Clang")
  1689. # Clang options used
  1690. # -include process include file as the first line of the primary source file
  1691. # -include-pch include precompiled header file
  1692. # -Qunused-arguments don't emit warning for unused driver arguments
  1693. # note: ccache requires the -include flag to be used in order to process precompiled header correctly
  1694. if (_flags)
  1695. # append to list
  1696. list (APPEND _flags "-Qunused-arguments" "-include" "${_prefixFile}")
  1697. else()
  1698. # return as a flag string
  1699. set (_flags "-Qunused-arguments -include \"${_prefixFile}\"")
  1700. endif()
  1701. elseif (_compilerID MATCHES "Intel")
  1702. if (WIN32)
  1703. file (TO_NATIVE_PATH "${_prefixFile}" _prefixFileNative)
  1704. # Windows Intel options used
  1705. # /Yu use a precompiled header (PCH) file
  1706. # /Fp specify a path or file name for precompiled header files
  1707. # /FI tells the preprocessor to include a specified file name as the header file
  1708. # /Wpch-messages enable diagnostics related to pre-compiled headers (requires Intel XE 2013 Update 2)
  1709. if (_pchFile)
  1710. file (TO_NATIVE_PATH "${_pchFile}" _pchFileNative)
  1711. if (_flags)
  1712. # append to list
  1713. list (APPEND _flags "/Yu" "/Fp${_pchFileNative}" "/FI${_prefixFileNative}")
  1714. if (NOT "${_compilerVersion}" VERSION_LESS "13.1.0")
  1715. list (APPEND _flags "/Wpch-messages")
  1716. endif()
  1717. else()
  1718. # return as a flag string
  1719. set (_flags "/Yu /Fp\"${_pchFileNative}\" /FI\"${_prefixFileNative}\"")
  1720. if (NOT "${_compilerVersion}" VERSION_LESS "13.1.0")
  1721. set (_flags "${_flags} /Wpch-messages")
  1722. endif()
  1723. endif()
  1724. else()
  1725. # no precompiled header, force inclusion of prefix header
  1726. if (_flags)
  1727. # append to list
  1728. list (APPEND _flags "/FI${_prefixFileNative}")
  1729. else()
  1730. # return as a flag string
  1731. set (_flags "/FI\"${_prefixFileNative}\"")
  1732. endif()
  1733. endif()
  1734. else()
  1735. # Linux / Mac OS X Intel options used
  1736. # -pch-dir location for precompiled header files
  1737. # -pch-use name of the precompiled header (PCH) to use
  1738. # -include process include file as the first line of the primary source file
  1739. # -Wpch-messages enable diagnostics related to pre-compiled headers (requires Intel XE 2013 Update 2)
  1740. if (_pchFile)
  1741. get_filename_component(_pchDir "${_pchFile}" DIRECTORY)
  1742. get_filename_component(_pchName "${_pchFile}" NAME)
  1743. set (_pchSuppressMessages FALSE)
  1744. if ("${CMAKE_${_language}_FLAGS}" MATCHES ".*-Wno-pch-messages.*")
  1745. set(_pchSuppressMessages TRUE)
  1746. endif()
  1747. if (_flags)
  1748. # append to list
  1749. list (APPEND _flags "-include" "${_prefixFile}" "-pch-dir" "${_pchDir}" "-pch-use" "${_pchName}")
  1750. if (NOT "${_compilerVersion}" VERSION_LESS "13.1.0")
  1751. if (NOT _pchSuppressMessages)
  1752. list (APPEND _flags "-Wpch-messages")
  1753. endif()
  1754. endif()
  1755. else()
  1756. # return as a flag string
  1757. set (_flags "-include \"${_prefixFile}\" -pch-dir \"${_pchDir}\" -pch-use \"${_pchName}\"")
  1758. if (NOT "${_compilerVersion}" VERSION_LESS "13.1.0")
  1759. if (NOT _pchSuppressMessages)
  1760. set (_flags "${_flags} -Wpch-messages")
  1761. endif()
  1762. endif()
  1763. endif()
  1764. else()
  1765. # no precompiled header, force inclusion of prefix header
  1766. if (_flags)
  1767. # append to list
  1768. list (APPEND _flags "-include" "${_prefixFile}")
  1769. else()
  1770. # return as a flag string
  1771. set (_flags "-include \"${_prefixFile}\"")
  1772. endif()
  1773. endif()
  1774. endif()
  1775. else()
  1776. message (FATAL_ERROR "cotire: unsupported ${_language} compiler ${_compilerID} version ${_compilerVersion}.")
  1777. endif()
  1778. set (${_flagsVar} ${_flags} PARENT_SCOPE)
  1779. endfunction()
  1780. function (cotire_precompile_prefix_header _prefixFile _pchFile _hostFile)
  1781. set(_options "")
  1782. set(_oneValueArgs COMPILER_EXECUTABLE COMPILER_ARG1 COMPILER_ID COMPILER_VERSION LANGUAGE)
  1783. set(_multiValueArgs COMPILE_DEFINITIONS COMPILE_FLAGS INCLUDE_DIRECTORIES SYSTEM_INCLUDE_DIRECTORIES SYS COMPILER_LAUNCHER)
  1784. cmake_parse_arguments(_option "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
  1785. if (NOT _option_LANGUAGE)
  1786. set (_option_LANGUAGE "CXX")
  1787. endif()
  1788. if (NOT _option_COMPILER_ID)
  1789. set (_option_COMPILER_ID "${CMAKE_${_option_LANGUAGE}_ID}")
  1790. endif()
  1791. if (NOT _option_COMPILER_VERSION)
  1792. set (_option_COMPILER_VERSION "${CMAKE_${_option_LANGUAGE}_COMPILER_VERSION}")
  1793. endif()
  1794. cotire_init_compile_cmd(_cmd "${_option_LANGUAGE}" "${_option_COMPILER_LAUNCHER}" "${_option_COMPILER_EXECUTABLE}" "${_option_COMPILER_ARG1}")
  1795. cotire_add_definitions_to_cmd(_cmd "${_option_LANGUAGE}" ${_option_COMPILE_DEFINITIONS})
  1796. cotire_add_compile_flags_to_cmd(_cmd ${_option_COMPILE_FLAGS})
  1797. cotire_add_includes_to_cmd(_cmd "${_option_LANGUAGE}" _option_INCLUDE_DIRECTORIES _option_SYSTEM_INCLUDE_DIRECTORIES)
  1798. cotire_add_frameworks_to_cmd(_cmd "${_option_LANGUAGE}" _option_INCLUDE_DIRECTORIES _option_SYSTEM_INCLUDE_DIRECTORIES)
  1799. cotire_add_pch_compilation_flags(
  1800. "${_option_LANGUAGE}" "${_option_COMPILER_ID}" "${_option_COMPILER_VERSION}"
  1801. "${_prefixFile}" "${_pchFile}" "${_hostFile}" _cmd)
  1802. if (COTIRE_VERBOSE)
  1803. message (STATUS "execute_process: ${_cmd}")
  1804. endif()
  1805. if (_option_COMPILER_ID MATCHES "MSVC")
  1806. # cl.exe messes with the output streams unless the environment variable VS_UNICODE_OUTPUT is cleared
  1807. unset (ENV{VS_UNICODE_OUTPUT})
  1808. elseif (_option_COMPILER_ID MATCHES "GNU|Clang")
  1809. if (_option_COMPILER_LAUNCHER MATCHES "ccache" OR
  1810. _option_COMPILER_EXECUTABLE MATCHES "ccache")
  1811. # Newer versions of Clang and GCC seem to embed a compilation timestamp into the precompiled header binary,
  1812. # which results in "file has been modified since the precompiled header was built" errors if ccache is used.
  1813. # We work around the problem by disabling ccache upon pre-compiling the prefix header.
  1814. set (ENV{CCACHE_DISABLE} "true")
  1815. endif()
  1816. endif()
  1817. execute_process(
  1818. COMMAND ${_cmd}
  1819. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  1820. RESULT_VARIABLE _result)
  1821. if (_result)
  1822. message (FATAL_ERROR "cotire: error ${_result} precompiling ${_prefixFile}.")
  1823. endif()
  1824. endfunction()
  1825. function (cotire_check_precompiled_header_support _language _target _msgVar)
  1826. set (_unsupportedCompiler
  1827. "Precompiled headers not supported for ${_language} compiler ${CMAKE_${_language}_COMPILER_ID}")
  1828. if (CMAKE_${_language}_COMPILER_ID MATCHES "MSVC")
  1829. # supported since Visual Studio C++ 6.0
  1830. # and CMake does not support an earlier version
  1831. set (${_msgVar} "" PARENT_SCOPE)
  1832. elseif (CMAKE_${_language}_COMPILER_ID MATCHES "GNU")
  1833. # GCC PCH support requires version >= 3.4
  1834. if ("${CMAKE_${_language}_COMPILER_VERSION}" VERSION_LESS "3.4.0")
  1835. set (${_msgVar} "${_unsupportedCompiler} version ${CMAKE_${_language}_COMPILER_VERSION}." PARENT_SCOPE)
  1836. else()
  1837. set (${_msgVar} "" PARENT_SCOPE)
  1838. endif()
  1839. elseif (CMAKE_${_language}_COMPILER_ID MATCHES "Clang")
  1840. # all Clang versions have PCH support
  1841. set (${_msgVar} "" PARENT_SCOPE)
  1842. elseif (CMAKE_${_language}_COMPILER_ID MATCHES "Intel")
  1843. # Intel PCH support requires version >= 8.0.0
  1844. if ("${CMAKE_${_language}_COMPILER_VERSION}" VERSION_LESS "8.0.0")
  1845. set (${_msgVar} "${_unsupportedCompiler} version ${CMAKE_${_language}_COMPILER_VERSION}." PARENT_SCOPE)
  1846. else()
  1847. set (${_msgVar} "" PARENT_SCOPE)
  1848. endif()
  1849. else()
  1850. set (${_msgVar} "${_unsupportedCompiler}." PARENT_SCOPE)
  1851. endif()
  1852. get_target_property(_launcher ${_target} ${_language}_COMPILER_LAUNCHER)
  1853. if (CMAKE_${_language}_COMPILER MATCHES "ccache" OR _launcher MATCHES "ccache")
  1854. if (DEFINED ENV{CCACHE_SLOPPINESS})
  1855. if (NOT "$ENV{CCACHE_SLOPPINESS}" MATCHES "pch_defines" OR NOT "$ENV{CCACHE_SLOPPINESS}" MATCHES "time_macros")
  1856. set (${_msgVar}
  1857. "ccache requires the environment variable CCACHE_SLOPPINESS to be set to \"pch_defines,time_macros\"."
  1858. PARENT_SCOPE)
  1859. endif()
  1860. else()
  1861. if (_launcher MATCHES "ccache")
  1862. get_filename_component(_ccacheExe "${_launcher}" REALPATH)
  1863. else()
  1864. get_filename_component(_ccacheExe "${CMAKE_${_language}_COMPILER}" REALPATH)
  1865. endif()
  1866. execute_process(
  1867. COMMAND "${_ccacheExe}" "--print-config"
  1868. WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
  1869. RESULT_VARIABLE _result
  1870. OUTPUT_VARIABLE _ccacheConfig OUTPUT_STRIP_TRAILING_WHITESPACE
  1871. ERROR_QUIET)
  1872. if (_result OR NOT
  1873. _ccacheConfig MATCHES "sloppiness.*=.*time_macros" OR NOT
  1874. _ccacheConfig MATCHES "sloppiness.*=.*pch_defines")
  1875. set (${_msgVar}
  1876. "ccache requires configuration setting \"sloppiness\" to be set to \"pch_defines,time_macros\"."
  1877. PARENT_SCOPE)
  1878. endif()
  1879. endif()
  1880. endif()
  1881. if (APPLE)
  1882. # PCH compilation not supported by GCC / Clang for multi-architecture builds (e.g., i386, x86_64)
  1883. cotire_get_configuration_types(_configs)
  1884. foreach (_config ${_configs})
  1885. set (_targetFlags "")
  1886. cotire_get_target_compile_flags("${_config}" "${_language}" "${_target}" _targetFlags)
  1887. cotire_filter_compile_flags("${_language}" "arch" _architectures _ignore ${_targetFlags})
  1888. list (LENGTH _architectures _numberOfArchitectures)
  1889. if (_numberOfArchitectures GREATER 1)
  1890. string (REPLACE ";" ", " _architectureStr "${_architectures}")
  1891. set (${_msgVar}
  1892. "Precompiled headers not supported on Darwin for multi-architecture builds (${_architectureStr})."
  1893. PARENT_SCOPE)
  1894. break()
  1895. endif()
  1896. endforeach()
  1897. endif()
  1898. endfunction()
  1899. macro (cotire_get_intermediate_dir _cotireDir)
  1900. # ${CMAKE_CFG_INTDIR} may reference a build-time variable when using a generator which supports configuration types
  1901. get_filename_component(${_cotireDir} "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${COTIRE_INTDIR}" ABSOLUTE)
  1902. endmacro()
  1903. macro (cotire_setup_file_extension_variables)
  1904. set (_unityFileExt_C ".c")
  1905. set (_unityFileExt_CXX ".cxx")
  1906. set (_prefixFileExt_C ".h")
  1907. set (_prefixFileExt_CXX ".hxx")
  1908. set (_prefixSourceFileExt_C ".c")
  1909. set (_prefixSourceFileExt_CXX ".cxx")
  1910. endmacro()
  1911. function (cotire_make_single_unity_source_file_path _language _target _unityFileVar)
  1912. cotire_setup_file_extension_variables()
  1913. if (NOT DEFINED _unityFileExt_${_language})
  1914. set (${_unityFileVar} "" PARENT_SCOPE)
  1915. return()
  1916. endif()
  1917. set (_unityFileBaseName "${_target}_${_language}${COTIRE_UNITY_SOURCE_FILENAME_SUFFIX}")
  1918. set (_unityFileName "${_unityFileBaseName}${_unityFileExt_${_language}}")
  1919. cotire_get_intermediate_dir(_baseDir)
  1920. set (_unityFile "${_baseDir}/${_unityFileName}")
  1921. set (${_unityFileVar} "${_unityFile}" PARENT_SCOPE)
  1922. endfunction()
  1923. function (cotire_make_unity_source_file_paths _language _target _maxIncludes _unityFilesVar)
  1924. cotire_setup_file_extension_variables()
  1925. if (NOT DEFINED _unityFileExt_${_language})
  1926. set (${_unityFileVar} "" PARENT_SCOPE)
  1927. return()
  1928. endif()
  1929. set (_unityFileBaseName "${_target}_${_language}${COTIRE_UNITY_SOURCE_FILENAME_SUFFIX}")
  1930. cotire_get_intermediate_dir(_baseDir)
  1931. set (_startIndex 0)
  1932. set (_index 0)
  1933. set (_unityFiles "")
  1934. set (_sourceFiles ${ARGN})
  1935. foreach (_sourceFile ${_sourceFiles})
  1936. get_source_file_property(_startNew "${_sourceFile}" COTIRE_START_NEW_UNITY_SOURCE)
  1937. math (EXPR _unityFileCount "${_index} - ${_startIndex}")
  1938. if (_startNew OR (_maxIncludes GREATER 0 AND NOT _unityFileCount LESS _maxIncludes))
  1939. if (_index GREATER 0)
  1940. # start new unity file segment
  1941. math (EXPR _endIndex "${_index} - 1")
  1942. set (_unityFileName "${_unityFileBaseName}_${_startIndex}_${_endIndex}${_unityFileExt_${_language}}")
  1943. list (APPEND _unityFiles "${_baseDir}/${_unityFileName}")
  1944. endif()
  1945. set (_startIndex ${_index})
  1946. endif()
  1947. math (EXPR _index "${_index} + 1")
  1948. endforeach()
  1949. list (LENGTH _sourceFiles _numberOfSources)
  1950. if (_startIndex EQUAL 0)
  1951. # there is only a single unity file
  1952. cotire_make_single_unity_source_file_path(${_language} ${_target} _unityFiles)
  1953. elseif (_startIndex LESS _numberOfSources)
  1954. # end with final unity file segment
  1955. math (EXPR _endIndex "${_index} - 1")
  1956. set (_unityFileName "${_unityFileBaseName}_${_startIndex}_${_endIndex}${_unityFileExt_${_language}}")
  1957. list (APPEND _unityFiles "${_baseDir}/${_unityFileName}")
  1958. endif()
  1959. set (${_unityFilesVar} ${_unityFiles} PARENT_SCOPE)
  1960. if (COTIRE_DEBUG AND _unityFiles)
  1961. message (STATUS "unity files: ${_unityFiles}")
  1962. endif()
  1963. endfunction()
  1964. function (cotire_unity_to_prefix_file_path _language _target _unityFile _prefixFileVar)
  1965. cotire_setup_file_extension_variables()
  1966. if (NOT DEFINED _unityFileExt_${_language})
  1967. set (${_prefixFileVar} "" PARENT_SCOPE)
  1968. return()
  1969. endif()
  1970. set (_unityFileBaseName "${_target}_${_language}${COTIRE_UNITY_SOURCE_FILENAME_SUFFIX}")
  1971. set (_prefixFileBaseName "${_target}_${_language}${COTIRE_PREFIX_HEADER_FILENAME_SUFFIX}")
  1972. string (REPLACE "${_unityFileBaseName}" "${_prefixFileBaseName}" _prefixFile "${_unityFile}")
  1973. string (REGEX REPLACE "${_unityFileExt_${_language}}$" "${_prefixFileExt_${_language}}" _prefixFile "${_prefixFile}")
  1974. set (${_prefixFileVar} "${_prefixFile}" PARENT_SCOPE)
  1975. endfunction()
  1976. function (cotire_prefix_header_to_source_file_path _language _prefixHeaderFile _prefixSourceFileVar)
  1977. cotire_setup_file_extension_variables()
  1978. if (NOT DEFINED _prefixSourceFileExt_${_language})
  1979. set (${_prefixSourceFileVar} "" PARENT_SCOPE)
  1980. return()
  1981. endif()
  1982. string (REGEX REPLACE "${_prefixFileExt_${_language}}$" "${_prefixSourceFileExt_${_language}}" _prefixSourceFile "${_prefixHeaderFile}")
  1983. set (${_prefixSourceFileVar} "${_prefixSourceFile}" PARENT_SCOPE)
  1984. endfunction()
  1985. function (cotire_make_prefix_file_name _language _target _prefixFileBaseNameVar _prefixFileNameVar)
  1986. cotire_setup_file_extension_variables()
  1987. if (NOT _language)
  1988. set (_prefixFileBaseName "${_target}${COTIRE_PREFIX_HEADER_FILENAME_SUFFIX}")
  1989. set (_prefixFileName "${_prefixFileBaseName}${_prefixFileExt_C}")
  1990. elseif (DEFINED _prefixFileExt_${_language})
  1991. set (_prefixFileBaseName "${_target}_${_language}${COTIRE_PREFIX_HEADER_FILENAME_SUFFIX}")
  1992. set (_prefixFileName "${_prefixFileBaseName}${_prefixFileExt_${_language}}")
  1993. else()
  1994. set (_prefixFileBaseName "")
  1995. set (_prefixFileName "")
  1996. endif()
  1997. set (${_prefixFileBaseNameVar} "${_prefixFileBaseName}" PARENT_SCOPE)
  1998. set (${_prefixFileNameVar} "${_prefixFileName}" PARENT_SCOPE)
  1999. endfunction()
  2000. function (cotire_make_prefix_file_path _language _target _prefixFileVar)
  2001. cotire_make_prefix_file_name("${_language}" "${_target}" _prefixFileBaseName _prefixFileName)
  2002. set (${_prefixFileVar} "" PARENT_SCOPE)
  2003. if (_prefixFileName)
  2004. if (NOT _language)
  2005. set (_language "C")
  2006. endif()
  2007. if (CMAKE_${_language}_COMPILER_ID MATCHES "GNU|Clang|Intel|MSVC")
  2008. cotire_get_intermediate_dir(_baseDir)
  2009. set (${_prefixFileVar} "${_baseDir}/${_prefixFileName}" PARENT_SCOPE)
  2010. endif()
  2011. endif()
  2012. endfunction()
  2013. function (cotire_make_pch_file_path _language _target _pchFileVar)
  2014. cotire_make_prefix_file_name("${_language}" "${_target}" _prefixFileBaseName _prefixFileName)
  2015. set (${_pchFileVar} "" PARENT_SCOPE)
  2016. if (_prefixFileBaseName AND _prefixFileName)
  2017. cotire_check_precompiled_header_support("${_language}" "${_target}" _msg)
  2018. if (NOT _msg)
  2019. if (XCODE)
  2020. # For Xcode, we completely hand off the compilation of the prefix header to the IDE
  2021. return()
  2022. endif()
  2023. cotire_get_intermediate_dir(_baseDir)
  2024. if (CMAKE_${_language}_COMPILER_ID MATCHES "MSVC")
  2025. # MSVC uses the extension .pch added to the prefix header base name
  2026. set (${_pchFileVar} "${_baseDir}/${_prefixFileBaseName}.pch" PARENT_SCOPE)
  2027. elseif (CMAKE_${_language}_COMPILER_ID MATCHES "Clang")
  2028. # Clang looks for a precompiled header corresponding to the prefix header with the extension .pch appended
  2029. set (${_pchFileVar} "${_baseDir}/${_prefixFileName}.pch" PARENT_SCOPE)
  2030. elseif (CMAKE_${_language}_COMPILER_ID MATCHES "GNU")
  2031. # GCC looks for a precompiled header corresponding to the prefix header with the extension .gch appended
  2032. set (${_pchFileVar} "${_baseDir}/${_prefixFileName}.gch" PARENT_SCOPE)
  2033. elseif (CMAKE_${_language}_COMPILER_ID MATCHES "Intel")
  2034. # Intel uses the extension .pchi added to the prefix header base name
  2035. set (${_pchFileVar} "${_baseDir}/${_prefixFileBaseName}.pchi" PARENT_SCOPE)
  2036. endif()
  2037. endif()
  2038. endif()
  2039. endfunction()
  2040. function (cotire_select_unity_source_files _unityFile _sourcesVar)
  2041. set (_sourceFiles ${ARGN})
  2042. if (_sourceFiles AND "${_unityFile}" MATCHES "${COTIRE_UNITY_SOURCE_FILENAME_SUFFIX}_([0-9]+)_([0-9]+)")
  2043. set (_startIndex ${CMAKE_MATCH_1})
  2044. set (_endIndex ${CMAKE_MATCH_2})
  2045. list (LENGTH _sourceFiles _numberOfSources)
  2046. if (NOT _startIndex LESS _numberOfSources)
  2047. math (EXPR _startIndex "${_numberOfSources} - 1")
  2048. endif()
  2049. if (NOT _endIndex LESS _numberOfSources)
  2050. math (EXPR _endIndex "${_numberOfSources} - 1")
  2051. endif()
  2052. set (_files "")
  2053. foreach (_index RANGE ${_startIndex} ${_endIndex})
  2054. list (GET _sourceFiles ${_index} _file)
  2055. list (APPEND _files "${_file}")
  2056. endforeach()
  2057. else()
  2058. set (_files ${_sourceFiles})
  2059. endif()
  2060. set (${_sourcesVar} ${_files} PARENT_SCOPE)
  2061. endfunction()
  2062. function (cotire_get_unity_source_dependencies _language _target _dependencySourcesVar)
  2063. set (_dependencySources "")
  2064. # depend on target's generated source files
  2065. get_target_property(_targetSourceFiles ${_target} SOURCES)
  2066. cotire_get_objects_with_property_on(_generatedSources GENERATED SOURCE ${_targetSourceFiles})
  2067. if (_generatedSources)
  2068. # but omit all generated source files that have the COTIRE_EXCLUDED property set to true
  2069. cotire_get_objects_with_property_on(_excludedGeneratedSources COTIRE_EXCLUDED SOURCE ${_generatedSources})
  2070. if (_excludedGeneratedSources)
  2071. list (REMOVE_ITEM _generatedSources ${_excludedGeneratedSources})
  2072. endif()
  2073. # and omit all generated source files that have the COTIRE_DEPENDENCY property set to false explicitly
  2074. cotire_get_objects_with_property_off(_excludedNonDependencySources COTIRE_DEPENDENCY SOURCE ${_generatedSources})
  2075. if (_excludedNonDependencySources)
  2076. list (REMOVE_ITEM _generatedSources ${_excludedNonDependencySources})
  2077. endif()
  2078. if (_generatedSources)
  2079. list (APPEND _dependencySources ${_generatedSources})
  2080. endif()
  2081. endif()
  2082. if (COTIRE_DEBUG AND _dependencySources)
  2083. message (STATUS "${_language} ${_target} unity source dependencies: ${_dependencySources}")
  2084. endif()
  2085. set (${_dependencySourcesVar} ${_dependencySources} PARENT_SCOPE)
  2086. endfunction()
  2087. function (cotire_get_prefix_header_dependencies _language _target _dependencySourcesVar)
  2088. set (_dependencySources "")
  2089. # depend on target source files marked with custom COTIRE_DEPENDENCY property
  2090. get_target_property(_targetSourceFiles ${_target} SOURCES)
  2091. cotire_get_objects_with_property_on(_dependencySources COTIRE_DEPENDENCY SOURCE ${_targetSourceFiles})
  2092. if (COTIRE_DEBUG AND _dependencySources)
  2093. message (STATUS "${_language} ${_target} prefix header dependencies: ${_dependencySources}")
  2094. endif()
  2095. set (${_dependencySourcesVar} ${_dependencySources} PARENT_SCOPE)
  2096. endfunction()
  2097. function (cotire_generate_target_script _language _configurations _target _targetScriptVar _targetConfigScriptVar)
  2098. set (_targetSources ${ARGN})
  2099. cotire_get_prefix_header_dependencies(${_language} ${_target} COTIRE_TARGET_PREFIX_DEPENDS ${_targetSources})
  2100. cotire_get_unity_source_dependencies(${_language} ${_target} COTIRE_TARGET_UNITY_DEPENDS ${_targetSources})
  2101. # set up variables to be configured
  2102. set (COTIRE_TARGET_LANGUAGE "${_language}")
  2103. get_target_property(COTIRE_TARGET_IGNORE_PATH ${_target} COTIRE_PREFIX_HEADER_IGNORE_PATH)
  2104. cotire_add_sys_root_paths(COTIRE_TARGET_IGNORE_PATH)
  2105. get_target_property(COTIRE_TARGET_INCLUDE_PATH ${_target} COTIRE_PREFIX_HEADER_INCLUDE_PATH)
  2106. cotire_add_sys_root_paths(COTIRE_TARGET_INCLUDE_PATH)
  2107. get_target_property(COTIRE_TARGET_PRE_UNDEFS ${_target} COTIRE_UNITY_SOURCE_PRE_UNDEFS)
  2108. get_target_property(COTIRE_TARGET_POST_UNDEFS ${_target} COTIRE_UNITY_SOURCE_POST_UNDEFS)
  2109. get_target_property(COTIRE_TARGET_MAXIMUM_NUMBER_OF_INCLUDES ${_target} COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES)
  2110. get_target_property(COTIRE_TARGET_INCLUDE_PRIORITY_PATH ${_target} COTIRE_PREFIX_HEADER_INCLUDE_PRIORITY_PATH)
  2111. cotire_get_source_files_undefs(COTIRE_UNITY_SOURCE_PRE_UNDEFS COTIRE_TARGET_SOURCES_PRE_UNDEFS ${_targetSources})
  2112. cotire_get_source_files_undefs(COTIRE_UNITY_SOURCE_POST_UNDEFS COTIRE_TARGET_SOURCES_POST_UNDEFS ${_targetSources})
  2113. set (COTIRE_TARGET_CONFIGURATION_TYPES "${_configurations}")
  2114. foreach (_config ${_configurations})
  2115. string (TOUPPER "${_config}" _upperConfig)
  2116. cotire_get_target_include_directories(
  2117. "${_config}" "${_language}" "${_target}" COTIRE_TARGET_INCLUDE_DIRECTORIES_${_upperConfig} COTIRE_TARGET_SYSTEM_INCLUDE_DIRECTORIES_${_upperConfig})
  2118. cotire_get_target_compile_definitions(
  2119. "${_config}" "${_language}" "${_target}" COTIRE_TARGET_COMPILE_DEFINITIONS_${_upperConfig})
  2120. cotire_get_target_compiler_flags(
  2121. "${_config}" "${_language}" "${_target}" COTIRE_TARGET_COMPILE_FLAGS_${_upperConfig})
  2122. cotire_get_source_files_compile_definitions(
  2123. "${_config}" "${_language}" COTIRE_TARGET_SOURCES_COMPILE_DEFINITIONS_${_upperConfig} ${_targetSources})
  2124. endforeach()
  2125. get_target_property(COTIRE_TARGET_${_language}_COMPILER_LAUNCHER ${_target} ${_language}_COMPILER_LAUNCHER)
  2126. # set up COTIRE_TARGET_SOURCES
  2127. set (COTIRE_TARGET_SOURCES "")
  2128. foreach (_sourceFile ${_targetSources})
  2129. get_source_file_property(_generated "${_sourceFile}" GENERATED)
  2130. if (_generated)
  2131. # use absolute paths for generated files only, retrieving the LOCATION property is an expensive operation
  2132. get_source_file_property(_sourceLocation "${_sourceFile}" LOCATION)
  2133. list (APPEND COTIRE_TARGET_SOURCES "${_sourceLocation}")
  2134. else()
  2135. list (APPEND COTIRE_TARGET_SOURCES "${_sourceFile}")
  2136. endif()
  2137. endforeach()
  2138. # copy variable definitions to cotire target script
  2139. get_cmake_property(_vars VARIABLES)
  2140. string (REGEX MATCHALL "COTIRE_[A-Za-z0-9_]+" _matchVars "${_vars}")
  2141. # omit COTIRE_*_INIT variables
  2142. string (REGEX MATCHALL "COTIRE_[A-Za-z0-9_]+_INIT" _initVars "${_matchVars}")
  2143. if (_initVars)
  2144. list (REMOVE_ITEM _matchVars ${_initVars})
  2145. endif()
  2146. # omit COTIRE_VERBOSE which is passed as a CMake define on command line
  2147. list (REMOVE_ITEM _matchVars COTIRE_VERBOSE)
  2148. set (_contents "")
  2149. set (_contentsHasGeneratorExpressions FALSE)
  2150. foreach (_var IN LISTS _matchVars ITEMS
  2151. XCODE MSVC CMAKE_GENERATOR CMAKE_BUILD_TYPE CMAKE_CONFIGURATION_TYPES
  2152. CMAKE_${_language}_COMPILER_ID CMAKE_${_language}_COMPILER_VERSION
  2153. CMAKE_${_language}_COMPILER_LAUNCHER CMAKE_${_language}_COMPILER CMAKE_${_language}_COMPILER_ARG1
  2154. CMAKE_INCLUDE_FLAG_${_language} CMAKE_INCLUDE_FLAG_SEP_${_language}
  2155. CMAKE_INCLUDE_SYSTEM_FLAG_${_language}
  2156. CMAKE_${_language}_FRAMEWORK_SEARCH_FLAG
  2157. CMAKE_${_language}_SYSTEM_FRAMEWORK_SEARCH_FLAG
  2158. CMAKE_${_language}_SOURCE_FILE_EXTENSIONS)
  2159. if (DEFINED ${_var})
  2160. string (REPLACE "\"" "\\\"" _value "${${_var}}")
  2161. set (_contents "${_contents}set (${_var} \"${_value}\")\n")
  2162. if (NOT _contentsHasGeneratorExpressions)
  2163. if ("${_value}" MATCHES "\\$<.*>")
  2164. set (_contentsHasGeneratorExpressions TRUE)
  2165. endif()
  2166. endif()
  2167. endif()
  2168. endforeach()
  2169. # generate target script file
  2170. get_filename_component(_moduleName "${COTIRE_CMAKE_MODULE_FILE}" NAME)
  2171. set (_targetCotireScript "${CMAKE_CURRENT_BINARY_DIR}/${_target}_${_language}_${_moduleName}")
  2172. cotire_write_file("CMAKE" "${_targetCotireScript}" "${_contents}" FALSE)
  2173. if (_contentsHasGeneratorExpressions)
  2174. # use file(GENERATE ...) to expand generator expressions in the target script at CMake generate-time
  2175. set (_configNameOrNoneGeneratorExpression "$<$<CONFIG:>:None>$<$<NOT:$<CONFIG:>>:$<CONFIGURATION>>")
  2176. set (_targetCotireConfigScript "${CMAKE_CURRENT_BINARY_DIR}/${_target}_${_language}_${_configNameOrNoneGeneratorExpression}_${_moduleName}")
  2177. file (GENERATE OUTPUT "${_targetCotireConfigScript}" INPUT "${_targetCotireScript}")
  2178. else()
  2179. set (_targetCotireConfigScript "${_targetCotireScript}")
  2180. endif()
  2181. set (${_targetScriptVar} "${_targetCotireScript}" PARENT_SCOPE)
  2182. set (${_targetConfigScriptVar} "${_targetCotireConfigScript}" PARENT_SCOPE)
  2183. endfunction()
  2184. function (cotire_setup_pch_file_compilation _language _target _targetScript _prefixFile _pchFile _hostFile)
  2185. set (_sourceFiles ${ARGN})
  2186. if (CMAKE_${_language}_COMPILER_ID MATCHES "MSVC|Intel")
  2187. # for Visual Studio and Intel, we attach the precompiled header compilation to the host file
  2188. # the remaining files include the precompiled header, see cotire_setup_pch_file_inclusion
  2189. if (_sourceFiles)
  2190. set (_flags "")
  2191. cotire_add_pch_compilation_flags(
  2192. "${_language}" "${CMAKE_${_language}_COMPILER_ID}" "${CMAKE_${_language}_COMPILER_VERSION}"
  2193. "${_prefixFile}" "${_pchFile}" "${_hostFile}" _flags)
  2194. set_property (SOURCE ${_hostFile} APPEND_STRING PROPERTY COMPILE_FLAGS " ${_flags} ")
  2195. set_property (SOURCE ${_hostFile} APPEND PROPERTY OBJECT_OUTPUTS "${_pchFile}")
  2196. # make object file generated from host file depend on prefix header
  2197. set_property (SOURCE ${_hostFile} APPEND PROPERTY OBJECT_DEPENDS "${_prefixFile}")
  2198. # mark host file as cotired to prevent it from being used in another cotired target
  2199. set_property (SOURCE ${_hostFile} PROPERTY COTIRE_TARGET "${_target}")
  2200. endif()
  2201. elseif ("${CMAKE_GENERATOR}" MATCHES "Make|Ninja")
  2202. # for makefile based generator, we add a custom command to precompile the prefix header
  2203. if (_targetScript)
  2204. cotire_set_cmd_to_prologue(_cmds)
  2205. list (APPEND _cmds -P "${COTIRE_CMAKE_MODULE_FILE}" "precompile" "${_targetScript}" "${_prefixFile}" "${_pchFile}" "${_hostFile}")
  2206. if (MSVC_IDE)
  2207. file (TO_NATIVE_PATH "${_pchFile}" _pchFileLogPath)
  2208. else()
  2209. file (RELATIVE_PATH _pchFileLogPath "${CMAKE_BINARY_DIR}" "${_pchFile}")
  2210. endif()
  2211. # make precompiled header compilation depend on the actual compiler executable used to force
  2212. # re-compilation when the compiler executable is updated. This prevents "created by a different GCC executable"
  2213. # warnings when the precompiled header is included.
  2214. get_filename_component(_realCompilerExe "${CMAKE_${_language}_COMPILER}" ABSOLUTE)
  2215. if (COTIRE_DEBUG)
  2216. message (STATUS "add_custom_command: OUTPUT ${_pchFile} ${_cmds} DEPENDS ${_prefixFile} ${_realCompilerExe} IMPLICIT_DEPENDS ${_language} ${_prefixFile}")
  2217. endif()
  2218. set_property (SOURCE "${_pchFile}" PROPERTY GENERATED TRUE)
  2219. add_custom_command(
  2220. OUTPUT "${_pchFile}"
  2221. COMMAND ${_cmds}
  2222. DEPENDS "${_prefixFile}" "${_realCompilerExe}"
  2223. IMPLICIT_DEPENDS ${_language} "${_prefixFile}"
  2224. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  2225. COMMENT "Building ${_language} precompiled header ${_pchFileLogPath}"
  2226. VERBATIM)
  2227. endif()
  2228. endif()
  2229. endfunction()
  2230. function (cotire_setup_pch_file_inclusion _language _target _wholeTarget _prefixFile _pchFile _hostFile)
  2231. if (CMAKE_${_language}_COMPILER_ID MATCHES "MSVC|Intel")
  2232. # for Visual Studio and Intel, we include the precompiled header in all but the host file
  2233. # the host file does the precompiled header compilation, see cotire_setup_pch_file_compilation
  2234. set (_sourceFiles ${ARGN})
  2235. list (LENGTH _sourceFiles _numberOfSourceFiles)
  2236. if (_numberOfSourceFiles GREATER 0)
  2237. # mark sources as cotired to prevent them from being used in another cotired target
  2238. set_source_files_properties(${_sourceFiles} PROPERTIES COTIRE_TARGET "${_target}")
  2239. set (_flags "")
  2240. cotire_add_prefix_pch_inclusion_flags(
  2241. "${_language}" "${CMAKE_${_language}_COMPILER_ID}" "${CMAKE_${_language}_COMPILER_VERSION}"
  2242. "${_prefixFile}" "${_pchFile}" _flags)
  2243. set_property (SOURCE ${_sourceFiles} APPEND_STRING PROPERTY COMPILE_FLAGS " ${_flags} ")
  2244. # make object files generated from source files depend on precompiled header
  2245. set_property (SOURCE ${_sourceFiles} APPEND PROPERTY OBJECT_DEPENDS "${_pchFile}")
  2246. endif()
  2247. elseif ("${CMAKE_GENERATOR}" MATCHES "Make|Ninja")
  2248. set (_sourceFiles ${_hostFile} ${ARGN})
  2249. if (NOT _wholeTarget)
  2250. # for makefile based generator, we force the inclusion of the prefix header for a subset
  2251. # of the source files, if this is a multi-language target or has excluded files
  2252. set (_flags "")
  2253. cotire_add_prefix_pch_inclusion_flags(
  2254. "${_language}" "${CMAKE_${_language}_COMPILER_ID}" "${CMAKE_${_language}_COMPILER_VERSION}"
  2255. "${_prefixFile}" "${_pchFile}" _flags)
  2256. set_property (SOURCE ${_sourceFiles} APPEND_STRING PROPERTY COMPILE_FLAGS " ${_flags} ")
  2257. # mark sources as cotired to prevent them from being used in another cotired target
  2258. set_source_files_properties(${_sourceFiles} PROPERTIES COTIRE_TARGET "${_target}")
  2259. endif()
  2260. # make object files generated from source files depend on precompiled header
  2261. set_property (SOURCE ${_sourceFiles} APPEND PROPERTY OBJECT_DEPENDS "${_pchFile}")
  2262. endif()
  2263. endfunction()
  2264. function (cotire_setup_prefix_file_inclusion _language _target _prefixFile)
  2265. set (_sourceFiles ${ARGN})
  2266. # force the inclusion of the prefix header for the given source files
  2267. set (_flags "")
  2268. set (_pchFile "")
  2269. cotire_add_prefix_pch_inclusion_flags(
  2270. "${_language}" "${CMAKE_${_language}_COMPILER_ID}" "${CMAKE_${_language}_COMPILER_VERSION}"
  2271. "${_prefixFile}" "${_pchFile}" _flags)
  2272. set_property (SOURCE ${_sourceFiles} APPEND_STRING PROPERTY COMPILE_FLAGS " ${_flags} ")
  2273. # mark sources as cotired to prevent them from being used in another cotired target
  2274. set_source_files_properties(${_sourceFiles} PROPERTIES COTIRE_TARGET "${_target}")
  2275. # make object files generated from source files depend on prefix header
  2276. set_property (SOURCE ${_sourceFiles} APPEND PROPERTY OBJECT_DEPENDS "${_prefixFile}")
  2277. endfunction()
  2278. function (cotire_get_first_set_property_value _propertyValueVar _type _object)
  2279. set (_properties ${ARGN})
  2280. foreach (_property ${_properties})
  2281. get_property(_propertyValue ${_type} "${_object}" PROPERTY ${_property})
  2282. if (_propertyValue)
  2283. set (${_propertyValueVar} ${_propertyValue} PARENT_SCOPE)
  2284. return()
  2285. endif()
  2286. endforeach()
  2287. set (${_propertyValueVar} "" PARENT_SCOPE)
  2288. endfunction()
  2289. function (cotire_setup_combine_command _language _targetScript _joinedFile _cmdsVar)
  2290. set (_files ${ARGN})
  2291. set (_filesPaths "")
  2292. foreach (_file ${_files})
  2293. get_filename_component(_filePath "${_file}" ABSOLUTE)
  2294. list (APPEND _filesPaths "${_filePath}")
  2295. endforeach()
  2296. cotire_set_cmd_to_prologue(_prefixCmd)
  2297. list (APPEND _prefixCmd -P "${COTIRE_CMAKE_MODULE_FILE}" "combine")
  2298. if (_targetScript)
  2299. list (APPEND _prefixCmd "${_targetScript}")
  2300. endif()
  2301. list (APPEND _prefixCmd "${_joinedFile}" ${_filesPaths})
  2302. if (COTIRE_DEBUG)
  2303. message (STATUS "add_custom_command: OUTPUT ${_joinedFile} COMMAND ${_prefixCmd} DEPENDS ${_files}")
  2304. endif()
  2305. set_property (SOURCE "${_joinedFile}" PROPERTY GENERATED TRUE)
  2306. if (MSVC_IDE)
  2307. file (TO_NATIVE_PATH "${_joinedFile}" _joinedFileLogPath)
  2308. else()
  2309. file (RELATIVE_PATH _joinedFileLogPath "${CMAKE_BINARY_DIR}" "${_joinedFile}")
  2310. endif()
  2311. get_filename_component(_joinedFileBaseName "${_joinedFile}" NAME_WE)
  2312. get_filename_component(_joinedFileExt "${_joinedFile}" EXT)
  2313. if (_language AND _joinedFileBaseName MATCHES "${COTIRE_UNITY_SOURCE_FILENAME_SUFFIX}$")
  2314. set (_comment "Generating ${_language} unity source ${_joinedFileLogPath}")
  2315. elseif (_language AND _joinedFileBaseName MATCHES "${COTIRE_PREFIX_HEADER_FILENAME_SUFFIX}$")
  2316. if (_joinedFileExt MATCHES "^\\.c")
  2317. set (_comment "Generating ${_language} prefix source ${_joinedFileLogPath}")
  2318. else()
  2319. set (_comment "Generating ${_language} prefix header ${_joinedFileLogPath}")
  2320. endif()
  2321. else()
  2322. set (_comment "Generating ${_joinedFileLogPath}")
  2323. endif()
  2324. add_custom_command(
  2325. OUTPUT "${_joinedFile}"
  2326. COMMAND ${_prefixCmd}
  2327. DEPENDS ${_files}
  2328. COMMENT "${_comment}"
  2329. WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
  2330. VERBATIM)
  2331. list (APPEND ${_cmdsVar} COMMAND ${_prefixCmd})
  2332. set (${_cmdsVar} ${${_cmdsVar}} PARENT_SCOPE)
  2333. endfunction()
  2334. function (cotire_setup_target_pch_usage _languages _target _wholeTarget)
  2335. if (XCODE)
  2336. # for Xcode, we attach a pre-build action to generate the unity sources and prefix headers
  2337. set (_prefixFiles "")
  2338. foreach (_language ${_languages})
  2339. get_property(_prefixFile TARGET ${_target} PROPERTY COTIRE_${_language}_PREFIX_HEADER)
  2340. if (_prefixFile)
  2341. list (APPEND _prefixFiles "${_prefixFile}")
  2342. endif()
  2343. endforeach()
  2344. set (_cmds ${ARGN})
  2345. list (LENGTH _prefixFiles _numberOfPrefixFiles)
  2346. if (_numberOfPrefixFiles GREATER 1)
  2347. # we also generate a generic, single prefix header which includes all language specific prefix headers
  2348. set (_language "")
  2349. set (_targetScript "")
  2350. cotire_make_prefix_file_path("${_language}" ${_target} _prefixHeader)
  2351. cotire_setup_combine_command("${_language}" "${_targetScript}" "${_prefixHeader}" _cmds ${_prefixFiles})
  2352. else()
  2353. set (_prefixHeader "${_prefixFiles}")
  2354. endif()
  2355. if (COTIRE_DEBUG)
  2356. message (STATUS "add_custom_command: TARGET ${_target} PRE_BUILD ${_cmds}")
  2357. endif()
  2358. # because CMake PRE_BUILD command does not support dependencies,
  2359. # we check dependencies explicity in cotire script mode when the pre-build action is run
  2360. add_custom_command(
  2361. TARGET "${_target}"
  2362. PRE_BUILD ${_cmds}
  2363. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  2364. COMMENT "Updating target ${_target} prefix headers"
  2365. VERBATIM)
  2366. # make Xcode precompile the generated prefix header with ProcessPCH and ProcessPCH++
  2367. set_target_properties(${_target} PROPERTIES XCODE_ATTRIBUTE_GCC_PRECOMPILE_PREFIX_HEADER "YES")
  2368. set_target_properties(${_target} PROPERTIES XCODE_ATTRIBUTE_GCC_PREFIX_HEADER "${_prefixHeader}")
  2369. elseif ("${CMAKE_GENERATOR}" MATCHES "Make|Ninja")
  2370. # for makefile based generator, we force inclusion of the prefix header for all target source files
  2371. # if this is a single-language target without any excluded files
  2372. if (_wholeTarget)
  2373. set (_language "${_languages}")
  2374. # for Visual Studio and Intel, precompiled header inclusion is always done on the source file level
  2375. # see cotire_setup_pch_file_inclusion
  2376. if (NOT CMAKE_${_language}_COMPILER_ID MATCHES "MSVC|Intel")
  2377. get_property(_prefixFile TARGET ${_target} PROPERTY COTIRE_${_language}_PREFIX_HEADER)
  2378. if (_prefixFile)
  2379. get_property(_pchFile TARGET ${_target} PROPERTY COTIRE_${_language}_PRECOMPILED_HEADER)
  2380. set (_options COMPILE_OPTIONS)
  2381. cotire_add_prefix_pch_inclusion_flags(
  2382. "${_language}" "${CMAKE_${_language}_COMPILER_ID}" "${CMAKE_${_language}_COMPILER_VERSION}"
  2383. "${_prefixFile}" "${_pchFile}" _options)
  2384. set_property(TARGET ${_target} APPEND PROPERTY ${_options})
  2385. endif()
  2386. endif()
  2387. endif()
  2388. endif()
  2389. endfunction()
  2390. function (cotire_setup_unity_generation_commands _language _target _targetScript _targetConfigScript _unityFiles _cmdsVar)
  2391. set (_dependencySources "")
  2392. cotire_get_unity_source_dependencies(${_language} ${_target} _dependencySources ${ARGN})
  2393. foreach (_unityFile ${_unityFiles})
  2394. set_property (SOURCE "${_unityFile}" PROPERTY GENERATED TRUE)
  2395. # set up compiled unity source dependencies via OBJECT_DEPENDS
  2396. # this ensures that missing source files are generated before the unity file is compiled
  2397. if (COTIRE_DEBUG AND _dependencySources)
  2398. message (STATUS "${_unityFile} OBJECT_DEPENDS ${_dependencySources}")
  2399. endif()
  2400. if (_dependencySources)
  2401. # the OBJECT_DEPENDS property requires a list of full paths
  2402. set (_objectDependsPaths "")
  2403. foreach (_sourceFile ${_dependencySources})
  2404. get_source_file_property(_sourceLocation "${_sourceFile}" LOCATION)
  2405. list (APPEND _objectDependsPaths "${_sourceLocation}")
  2406. endforeach()
  2407. set_property (SOURCE "${_unityFile}" PROPERTY OBJECT_DEPENDS ${_objectDependsPaths})
  2408. endif()
  2409. if (WIN32 AND CMAKE_${_language}_COMPILER_ID MATCHES "MSVC|Intel")
  2410. # unity file compilation results in potentially huge object file, thus use /bigobj by default unter MSVC and Windows Intel
  2411. set_property (SOURCE "${_unityFile}" APPEND_STRING PROPERTY COMPILE_FLAGS "/bigobj")
  2412. endif()
  2413. cotire_set_cmd_to_prologue(_unityCmd)
  2414. list (APPEND _unityCmd -P "${COTIRE_CMAKE_MODULE_FILE}" "unity" "${_targetConfigScript}" "${_unityFile}")
  2415. if (CMAKE_VERSION VERSION_LESS "3.1.0")
  2416. set (_unityCmdDepends "${_targetScript}")
  2417. else()
  2418. # CMake 3.1.0 supports generator expressions in arguments to DEPENDS
  2419. set (_unityCmdDepends "${_targetConfigScript}")
  2420. endif()
  2421. if (MSVC_IDE)
  2422. file (TO_NATIVE_PATH "${_unityFile}" _unityFileLogPath)
  2423. else()
  2424. file (RELATIVE_PATH _unityFileLogPath "${CMAKE_BINARY_DIR}" "${_unityFile}")
  2425. endif()
  2426. if (COTIRE_DEBUG)
  2427. message (STATUS "add_custom_command: OUTPUT ${_unityFile} COMMAND ${_unityCmd} DEPENDS ${_unityCmdDepends}")
  2428. endif()
  2429. add_custom_command(
  2430. OUTPUT "${_unityFile}"
  2431. COMMAND ${_unityCmd}
  2432. DEPENDS ${_unityCmdDepends}
  2433. COMMENT "Generating ${_language} unity source ${_unityFileLogPath}"
  2434. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  2435. VERBATIM)
  2436. list (APPEND ${_cmdsVar} COMMAND ${_unityCmd})
  2437. endforeach()
  2438. set (${_cmdsVar} ${${_cmdsVar}} PARENT_SCOPE)
  2439. endfunction()
  2440. function (cotire_setup_prefix_generation_command _language _target _targetScript _prefixFile _unityFiles _cmdsVar)
  2441. set (_sourceFiles ${ARGN})
  2442. set (_dependencySources "")
  2443. cotire_get_prefix_header_dependencies(${_language} ${_target} _dependencySources ${_sourceFiles})
  2444. cotire_set_cmd_to_prologue(_prefixCmd)
  2445. list (APPEND _prefixCmd -P "${COTIRE_CMAKE_MODULE_FILE}" "prefix" "${_targetScript}" "${_prefixFile}" ${_unityFiles})
  2446. set_property (SOURCE "${_prefixFile}" PROPERTY GENERATED TRUE)
  2447. # make prefix header generation depend on the actual compiler executable used to force
  2448. # re-generation when the compiler executable is updated. This prevents "file not found"
  2449. # errors for compiler version specific system header files.
  2450. get_filename_component(_realCompilerExe "${CMAKE_${_language}_COMPILER}" ABSOLUTE)
  2451. if (COTIRE_DEBUG)
  2452. message (STATUS "add_custom_command: OUTPUT ${_prefixFile} COMMAND ${_prefixCmd} DEPENDS ${_unityFile} ${_dependencySources} ${_realCompilerExe}")
  2453. endif()
  2454. if (MSVC_IDE)
  2455. file (TO_NATIVE_PATH "${_prefixFile}" _prefixFileLogPath)
  2456. else()
  2457. file (RELATIVE_PATH _prefixFileLogPath "${CMAKE_BINARY_DIR}" "${_prefixFile}")
  2458. endif()
  2459. get_filename_component(_prefixFileExt "${_prefixFile}" EXT)
  2460. if (_prefixFileExt MATCHES "^\\.c")
  2461. set (_comment "Generating ${_language} prefix source ${_prefixFileLogPath}")
  2462. else()
  2463. set (_comment "Generating ${_language} prefix header ${_prefixFileLogPath}")
  2464. endif()
  2465. # prevent pre-processing errors upon generating the prefix header when a target's generated include file does not yet exist
  2466. # we do not add a file-level dependency for the target's generated files though, because we only want to depend on their existence
  2467. # thus we make the prefix header generation depend on a custom helper target which triggers the generation of the files
  2468. set (_preTargetName "${_target}${COTIRE_PCH_TARGET_SUFFIX}_pre")
  2469. if (TARGET ${_preTargetName})
  2470. # custom helper target has already been generated while processing a different language
  2471. list (APPEND _dependencySources ${_preTargetName})
  2472. else()
  2473. get_target_property(_targetSourceFiles ${_target} SOURCES)
  2474. cotire_get_objects_with_property_on(_generatedSources GENERATED SOURCE ${_targetSourceFiles})
  2475. if (_generatedSources)
  2476. add_custom_target("${_preTargetName}" DEPENDS ${_generatedSources})
  2477. cotire_init_target("${_preTargetName}")
  2478. list (APPEND _dependencySources ${_preTargetName})
  2479. endif()
  2480. endif()
  2481. add_custom_command(
  2482. OUTPUT "${_prefixFile}" "${_prefixFile}.log"
  2483. COMMAND ${_prefixCmd}
  2484. DEPENDS ${_unityFiles} ${_dependencySources} "${_realCompilerExe}"
  2485. COMMENT "${_comment}"
  2486. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
  2487. VERBATIM)
  2488. list (APPEND ${_cmdsVar} COMMAND ${_prefixCmd})
  2489. set (${_cmdsVar} ${${_cmdsVar}} PARENT_SCOPE)
  2490. endfunction()
  2491. function (cotire_setup_prefix_generation_from_unity_command _language _target _targetScript _prefixFile _unityFiles _cmdsVar)
  2492. set (_sourceFiles ${ARGN})
  2493. if (CMAKE_${_language}_COMPILER_ID MATCHES "GNU|Clang")
  2494. # GNU and Clang require indirect compilation of the prefix header to make them honor the system_header pragma
  2495. cotire_prefix_header_to_source_file_path(${_language} "${_prefixFile}" _prefixSourceFile)
  2496. else()
  2497. set (_prefixSourceFile "${_prefixFile}")
  2498. endif()
  2499. cotire_setup_prefix_generation_command(
  2500. ${_language} ${_target} "${_targetScript}"
  2501. "${_prefixSourceFile}" "${_unityFiles}" ${_cmdsVar} ${_sourceFiles})
  2502. if (CMAKE_${_language}_COMPILER_ID MATCHES "GNU|Clang")
  2503. # set up generation of a prefix source file which includes the prefix header
  2504. cotire_setup_combine_command(${_language} "${_targetScript}" "${_prefixFile}" _cmds ${_prefixSourceFile})
  2505. endif()
  2506. set (${_cmdsVar} ${${_cmdsVar}} PARENT_SCOPE)
  2507. endfunction()
  2508. function (cotire_setup_prefix_generation_from_provided_command _language _target _targetScript _prefixFile _cmdsVar)
  2509. set (_prefixHeaderFiles ${ARGN})
  2510. if (CMAKE_${_language}_COMPILER_ID MATCHES "GNU|Clang")
  2511. # GNU and Clang require indirect compilation of the prefix header to make them honor the system_header pragma
  2512. cotire_prefix_header_to_source_file_path(${_language} "${_prefixFile}" _prefixSourceFile)
  2513. else()
  2514. set (_prefixSourceFile "${_prefixFile}")
  2515. endif()
  2516. cotire_setup_combine_command(${_language} "${_targetScript}" "${_prefixSourceFile}" _cmds ${_prefixHeaderFiles})
  2517. if (CMAKE_${_language}_COMPILER_ID MATCHES "GNU|Clang")
  2518. # set up generation of a prefix source file which includes the prefix header
  2519. cotire_setup_combine_command(${_language} "${_targetScript}" "${_prefixFile}" _cmds ${_prefixSourceFile})
  2520. endif()
  2521. set (${_cmdsVar} ${${_cmdsVar}} PARENT_SCOPE)
  2522. endfunction()
  2523. function (cotire_init_cotire_target_properties _target)
  2524. get_property(_isSet TARGET ${_target} PROPERTY COTIRE_ENABLE_PRECOMPILED_HEADER SET)
  2525. if (NOT _isSet)
  2526. set_property(TARGET ${_target} PROPERTY COTIRE_ENABLE_PRECOMPILED_HEADER TRUE)
  2527. endif()
  2528. get_property(_isSet TARGET ${_target} PROPERTY COTIRE_ADD_UNITY_BUILD SET)
  2529. if (NOT _isSet)
  2530. set_property(TARGET ${_target} PROPERTY COTIRE_ADD_UNITY_BUILD TRUE)
  2531. endif()
  2532. get_property(_isSet TARGET ${_target} PROPERTY COTIRE_ADD_CLEAN SET)
  2533. if (NOT _isSet)
  2534. set_property(TARGET ${_target} PROPERTY COTIRE_ADD_CLEAN FALSE)
  2535. endif()
  2536. get_property(_isSet TARGET ${_target} PROPERTY COTIRE_PREFIX_HEADER_IGNORE_PATH SET)
  2537. if (NOT _isSet)
  2538. set_property(TARGET ${_target} PROPERTY COTIRE_PREFIX_HEADER_IGNORE_PATH "${CMAKE_SOURCE_DIR}")
  2539. cotire_check_is_path_relative_to("${CMAKE_BINARY_DIR}" _isRelative "${CMAKE_SOURCE_DIR}")
  2540. if (NOT _isRelative)
  2541. set_property(TARGET ${_target} APPEND PROPERTY COTIRE_PREFIX_HEADER_IGNORE_PATH "${CMAKE_BINARY_DIR}")
  2542. endif()
  2543. endif()
  2544. get_property(_isSet TARGET ${_target} PROPERTY COTIRE_PREFIX_HEADER_INCLUDE_PATH SET)
  2545. if (NOT _isSet)
  2546. set_property(TARGET ${_target} PROPERTY COTIRE_PREFIX_HEADER_INCLUDE_PATH "")
  2547. endif()
  2548. get_property(_isSet TARGET ${_target} PROPERTY COTIRE_PREFIX_HEADER_INCLUDE_PRIORITY_PATH SET)
  2549. if (NOT _isSet)
  2550. set_property(TARGET ${_target} PROPERTY COTIRE_PREFIX_HEADER_INCLUDE_PRIORITY_PATH "")
  2551. endif()
  2552. get_property(_isSet TARGET ${_target} PROPERTY COTIRE_UNITY_SOURCE_PRE_UNDEFS SET)
  2553. if (NOT _isSet)
  2554. set_property(TARGET ${_target} PROPERTY COTIRE_UNITY_SOURCE_PRE_UNDEFS "")
  2555. endif()
  2556. get_property(_isSet TARGET ${_target} PROPERTY COTIRE_UNITY_SOURCE_POST_UNDEFS SET)
  2557. if (NOT _isSet)
  2558. set_property(TARGET ${_target} PROPERTY COTIRE_UNITY_SOURCE_POST_UNDEFS "")
  2559. endif()
  2560. get_property(_isSet TARGET ${_target} PROPERTY COTIRE_UNITY_LINK_LIBRARIES_INIT SET)
  2561. if (NOT _isSet)
  2562. set_property(TARGET ${_target} PROPERTY COTIRE_UNITY_LINK_LIBRARIES_INIT "COPY_UNITY")
  2563. endif()
  2564. get_property(_isSet TARGET ${_target} PROPERTY COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES SET)
  2565. if (NOT _isSet)
  2566. if (COTIRE_MAXIMUM_NUMBER_OF_UNITY_INCLUDES)
  2567. set_property(TARGET ${_target} PROPERTY COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES "${COTIRE_MAXIMUM_NUMBER_OF_UNITY_INCLUDES}")
  2568. else()
  2569. set_property(TARGET ${_target} PROPERTY COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES "")
  2570. endif()
  2571. endif()
  2572. endfunction()
  2573. function (cotire_make_target_message _target _languages _disableMsg _targetMsgVar)
  2574. get_target_property(_targetUsePCH ${_target} COTIRE_ENABLE_PRECOMPILED_HEADER)
  2575. get_target_property(_targetAddSCU ${_target} COTIRE_ADD_UNITY_BUILD)
  2576. string (REPLACE ";" " " _languagesStr "${_languages}")
  2577. math (EXPR _numberOfExcludedFiles "${ARGC} - 4")
  2578. if (_numberOfExcludedFiles EQUAL 0)
  2579. set (_excludedStr "")
  2580. elseif (COTIRE_VERBOSE OR _numberOfExcludedFiles LESS 4)
  2581. string (REPLACE ";" ", " _excludedStr "excluding ${ARGN}")
  2582. else()
  2583. set (_excludedStr "excluding ${_numberOfExcludedFiles} files")
  2584. endif()
  2585. set (_targetMsg "")
  2586. if (NOT _languages)
  2587. set (_targetMsg "Target ${_target} cannot be cotired.")
  2588. if (_disableMsg)
  2589. set (_targetMsg "${_targetMsg} ${_disableMsg}")
  2590. endif()
  2591. elseif (NOT _targetUsePCH AND NOT _targetAddSCU)
  2592. set (_targetMsg "${_languagesStr} target ${_target} cotired without unity build and precompiled header.")
  2593. if (_disableMsg)
  2594. set (_targetMsg "${_targetMsg} ${_disableMsg}")
  2595. endif()
  2596. elseif (NOT _targetUsePCH)
  2597. if (_excludedStr)
  2598. set (_targetMsg "${_languagesStr} target ${_target} cotired without precompiled header ${_excludedStr}.")
  2599. else()
  2600. set (_targetMsg "${_languagesStr} target ${_target} cotired without precompiled header.")
  2601. endif()
  2602. if (_disableMsg)
  2603. set (_targetMsg "${_targetMsg} ${_disableMsg}")
  2604. endif()
  2605. elseif (NOT _targetAddSCU)
  2606. if (_excludedStr)
  2607. set (_targetMsg "${_languagesStr} target ${_target} cotired without unity build ${_excludedStr}.")
  2608. else()
  2609. set (_targetMsg "${_languagesStr} target ${_target} cotired without unity build.")
  2610. endif()
  2611. else()
  2612. if (_excludedStr)
  2613. set (_targetMsg "${_languagesStr} target ${_target} cotired ${_excludedStr}.")
  2614. else()
  2615. set (_targetMsg "${_languagesStr} target ${_target} cotired.")
  2616. endif()
  2617. endif()
  2618. set (${_targetMsgVar} "${_targetMsg}" PARENT_SCOPE)
  2619. endfunction()
  2620. function (cotire_choose_target_languages _target _targetLanguagesVar _wholeTargetVar)
  2621. set (_languages ${ARGN})
  2622. set (_allSourceFiles "")
  2623. set (_allExcludedSourceFiles "")
  2624. set (_allCotiredSourceFiles "")
  2625. set (_targetLanguages "")
  2626. set (_pchEligibleTargetLanguages "")
  2627. get_target_property(_targetType ${_target} TYPE)
  2628. get_target_property(_targetSourceFiles ${_target} SOURCES)
  2629. get_target_property(_targetUsePCH ${_target} COTIRE_ENABLE_PRECOMPILED_HEADER)
  2630. get_target_property(_targetAddSCU ${_target} COTIRE_ADD_UNITY_BUILD)
  2631. set (_disableMsg "")
  2632. foreach (_language ${_languages})
  2633. get_target_property(_prefixHeader ${_target} COTIRE_${_language}_PREFIX_HEADER)
  2634. get_target_property(_unityBuildFile ${_target} COTIRE_${_language}_UNITY_SOURCE)
  2635. if (_prefixHeader OR _unityBuildFile)
  2636. message (STATUS "cotire: target ${_target} has already been cotired.")
  2637. set (${_targetLanguagesVar} "" PARENT_SCOPE)
  2638. return()
  2639. endif()
  2640. if (_targetUsePCH AND "${_language}" MATCHES "^C|CXX$" AND DEFINED CMAKE_${_language}_COMPILER_ID)
  2641. if (CMAKE_${_language}_COMPILER_ID)
  2642. cotire_check_precompiled_header_support("${_language}" "${_target}" _disableMsg)
  2643. if (_disableMsg)
  2644. set (_targetUsePCH FALSE)
  2645. endif()
  2646. endif()
  2647. endif()
  2648. set (_sourceFiles "")
  2649. set (_excludedSources "")
  2650. set (_cotiredSources "")
  2651. cotire_filter_language_source_files(${_language} ${_target} _sourceFiles _excludedSources _cotiredSources ${_targetSourceFiles})
  2652. if (_sourceFiles OR _excludedSources OR _cotiredSources)
  2653. list (APPEND _targetLanguages ${_language})
  2654. endif()
  2655. if (_sourceFiles)
  2656. list (APPEND _allSourceFiles ${_sourceFiles})
  2657. endif()
  2658. list (LENGTH _sourceFiles _numberOfSources)
  2659. if (NOT _numberOfSources LESS ${COTIRE_MINIMUM_NUMBER_OF_TARGET_SOURCES})
  2660. list (APPEND _pchEligibleTargetLanguages ${_language})
  2661. endif()
  2662. if (_excludedSources)
  2663. list (APPEND _allExcludedSourceFiles ${_excludedSources})
  2664. endif()
  2665. if (_cotiredSources)
  2666. list (APPEND _allCotiredSourceFiles ${_cotiredSources})
  2667. endif()
  2668. endforeach()
  2669. set (_targetMsgLevel STATUS)
  2670. if (NOT _targetLanguages)
  2671. string (REPLACE ";" " or " _languagesStr "${_languages}")
  2672. set (_disableMsg "No ${_languagesStr} source files.")
  2673. set (_targetUsePCH FALSE)
  2674. set (_targetAddSCU FALSE)
  2675. endif()
  2676. if (_targetUsePCH)
  2677. if (_allCotiredSourceFiles)
  2678. cotire_get_source_file_property_values(_cotireTargets COTIRE_TARGET ${_allCotiredSourceFiles})
  2679. list (REMOVE_DUPLICATES _cotireTargets)
  2680. string (REPLACE ";" ", " _cotireTargetsStr "${_cotireTargets}")
  2681. set (_disableMsg "Target sources already include a precompiled header for target(s) ${_cotireTargets}.")
  2682. set (_disableMsg "${_disableMsg} Set target property COTIRE_ENABLE_PRECOMPILED_HEADER to FALSE for targets ${_target},")
  2683. set (_disableMsg "${_disableMsg} ${_cotireTargetsStr} to get a workable build system.")
  2684. set (_targetMsgLevel SEND_ERROR)
  2685. set (_targetUsePCH FALSE)
  2686. elseif (NOT _pchEligibleTargetLanguages)
  2687. set (_disableMsg "Too few applicable sources.")
  2688. set (_targetUsePCH FALSE)
  2689. elseif (XCODE AND _allExcludedSourceFiles)
  2690. # for Xcode, we cannot apply the precompiled header to individual sources, only to the whole target
  2691. set (_disableMsg "Exclusion of source files not supported for generator Xcode.")
  2692. set (_targetUsePCH FALSE)
  2693. elseif (XCODE AND "${_targetType}" STREQUAL "OBJECT_LIBRARY")
  2694. # for Xcode, we cannot apply the required PRE_BUILD action to generate the prefix header to an OBJECT_LIBRARY target
  2695. set (_disableMsg "Required PRE_BUILD action not supported for OBJECT_LIBRARY targets for generator Xcode.")
  2696. set (_targetUsePCH FALSE)
  2697. endif()
  2698. endif()
  2699. set_property(TARGET ${_target} PROPERTY COTIRE_ENABLE_PRECOMPILED_HEADER ${_targetUsePCH})
  2700. set_property(TARGET ${_target} PROPERTY COTIRE_ADD_UNITY_BUILD ${_targetAddSCU})
  2701. cotire_make_target_message(${_target} "${_targetLanguages}" "${_disableMsg}" _targetMsg ${_allExcludedSourceFiles})
  2702. if (_targetMsg)
  2703. if (NOT DEFINED COTIREMSG_${_target})
  2704. set (COTIREMSG_${_target} "")
  2705. endif()
  2706. if (COTIRE_VERBOSE OR NOT "${_targetMsgLevel}" STREQUAL "STATUS" OR
  2707. NOT "${COTIREMSG_${_target}}" STREQUAL "${_targetMsg}")
  2708. # cache message to avoid redundant messages on re-configure
  2709. set (COTIREMSG_${_target} "${_targetMsg}" CACHE INTERNAL "${_target} cotire message.")
  2710. message (${_targetMsgLevel} "${_targetMsg}")
  2711. endif()
  2712. endif()
  2713. list (LENGTH _targetLanguages _numberOfLanguages)
  2714. if (_numberOfLanguages GREATER 1 OR _allExcludedSourceFiles)
  2715. set (${_wholeTargetVar} FALSE PARENT_SCOPE)
  2716. else()
  2717. set (${_wholeTargetVar} TRUE PARENT_SCOPE)
  2718. endif()
  2719. set (${_targetLanguagesVar} ${_targetLanguages} PARENT_SCOPE)
  2720. endfunction()
  2721. function (cotire_compute_unity_max_number_of_includes _target _maxIncludesVar)
  2722. set (_sourceFiles ${ARGN})
  2723. get_target_property(_maxIncludes ${_target} COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES)
  2724. if (_maxIncludes MATCHES "(-j|--parallel|--jobs) ?([0-9]*)")
  2725. set (_numberOfThreads "${CMAKE_MATCH_2}")
  2726. if (NOT _numberOfThreads)
  2727. # use all available cores
  2728. ProcessorCount(_numberOfThreads)
  2729. endif()
  2730. list (LENGTH _sourceFiles _numberOfSources)
  2731. math (EXPR _maxIncludes "(${_numberOfSources} + ${_numberOfThreads} - 1) / ${_numberOfThreads}")
  2732. elseif (NOT _maxIncludes MATCHES "[0-9]+")
  2733. set (_maxIncludes 0)
  2734. endif()
  2735. if (COTIRE_DEBUG)
  2736. message (STATUS "${_target} unity source max includes: ${_maxIncludes}")
  2737. endif()
  2738. set (${_maxIncludesVar} ${_maxIncludes} PARENT_SCOPE)
  2739. endfunction()
  2740. function (cotire_process_target_language _language _configurations _target _wholeTarget _cmdsVar)
  2741. set (${_cmdsVar} "" PARENT_SCOPE)
  2742. get_target_property(_targetSourceFiles ${_target} SOURCES)
  2743. set (_sourceFiles "")
  2744. set (_excludedSources "")
  2745. set (_cotiredSources "")
  2746. cotire_filter_language_source_files(${_language} ${_target} _sourceFiles _excludedSources _cotiredSources ${_targetSourceFiles})
  2747. if (NOT _sourceFiles AND NOT _cotiredSources)
  2748. return()
  2749. endif()
  2750. set (_cmds "")
  2751. # check for user provided unity source file list
  2752. get_property(_unitySourceFiles TARGET ${_target} PROPERTY COTIRE_${_language}_UNITY_SOURCE_INIT)
  2753. if (NOT _unitySourceFiles)
  2754. set (_unitySourceFiles ${_sourceFiles} ${_cotiredSources})
  2755. endif()
  2756. cotire_generate_target_script(
  2757. ${_language} "${_configurations}" ${_target} _targetScript _targetConfigScript ${_unitySourceFiles})
  2758. # set up unity files for parallel compilation
  2759. cotire_compute_unity_max_number_of_includes(${_target} _maxIncludes ${_unitySourceFiles})
  2760. cotire_make_unity_source_file_paths(${_language} ${_target} ${_maxIncludes} _unityFiles ${_unitySourceFiles})
  2761. list (LENGTH _unityFiles _numberOfUnityFiles)
  2762. if (_numberOfUnityFiles EQUAL 0)
  2763. return()
  2764. elseif (_numberOfUnityFiles GREATER 1)
  2765. cotire_setup_unity_generation_commands(
  2766. ${_language} ${_target} "${_targetScript}" "${_targetConfigScript}" "${_unityFiles}" _cmds ${_unitySourceFiles})
  2767. endif()
  2768. # set up single unity file for prefix header generation
  2769. cotire_make_single_unity_source_file_path(${_language} ${_target} _unityFile)
  2770. cotire_setup_unity_generation_commands(
  2771. ${_language} ${_target} "${_targetScript}" "${_targetConfigScript}" "${_unityFile}" _cmds ${_unitySourceFiles})
  2772. cotire_make_prefix_file_path(${_language} ${_target} _prefixFile)
  2773. # set up prefix header
  2774. if (_prefixFile)
  2775. # check for user provided prefix header files
  2776. get_property(_prefixHeaderFiles TARGET ${_target} PROPERTY COTIRE_${_language}_PREFIX_HEADER_INIT)
  2777. if (_prefixHeaderFiles)
  2778. cotire_setup_prefix_generation_from_provided_command(
  2779. ${_language} ${_target} "${_targetConfigScript}" "${_prefixFile}" _cmds ${_prefixHeaderFiles})
  2780. else()
  2781. cotire_setup_prefix_generation_from_unity_command(
  2782. ${_language} ${_target} "${_targetConfigScript}" "${_prefixFile}" "${_unityFile}" _cmds ${_unitySourceFiles})
  2783. endif()
  2784. # check if selected language has enough sources at all
  2785. list (LENGTH _sourceFiles _numberOfSources)
  2786. if (_numberOfSources LESS ${COTIRE_MINIMUM_NUMBER_OF_TARGET_SOURCES})
  2787. set (_targetUsePCH FALSE)
  2788. else()
  2789. get_target_property(_targetUsePCH ${_target} COTIRE_ENABLE_PRECOMPILED_HEADER)
  2790. endif()
  2791. if (_targetUsePCH)
  2792. cotire_make_pch_file_path(${_language} ${_target} _pchFile)
  2793. if (_pchFile)
  2794. # first file in _sourceFiles is passed as the host file
  2795. cotire_setup_pch_file_compilation(
  2796. ${_language} ${_target} "${_targetConfigScript}" "${_prefixFile}" "${_pchFile}" ${_sourceFiles})
  2797. cotire_setup_pch_file_inclusion(
  2798. ${_language} ${_target} ${_wholeTarget} "${_prefixFile}" "${_pchFile}" ${_sourceFiles})
  2799. endif()
  2800. elseif (_prefixHeaderFiles)
  2801. # user provided prefix header must be included unconditionally
  2802. cotire_setup_prefix_file_inclusion(${_language} ${_target} "${_prefixFile}" ${_sourceFiles})
  2803. endif()
  2804. endif()
  2805. # mark target as cotired for language
  2806. set_property(TARGET ${_target} PROPERTY COTIRE_${_language}_UNITY_SOURCE "${_unityFiles}")
  2807. if (_prefixFile)
  2808. set_property(TARGET ${_target} PROPERTY COTIRE_${_language}_PREFIX_HEADER "${_prefixFile}")
  2809. if (_targetUsePCH AND _pchFile)
  2810. set_property(TARGET ${_target} PROPERTY COTIRE_${_language}_PRECOMPILED_HEADER "${_pchFile}")
  2811. endif()
  2812. endif()
  2813. set (${_cmdsVar} ${_cmds} PARENT_SCOPE)
  2814. endfunction()
  2815. function (cotire_setup_clean_target _target)
  2816. set (_cleanTargetName "${_target}${COTIRE_CLEAN_TARGET_SUFFIX}")
  2817. if (NOT TARGET "${_cleanTargetName}")
  2818. cotire_set_cmd_to_prologue(_cmds)
  2819. get_filename_component(_outputDir "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}" ABSOLUTE)
  2820. list (APPEND _cmds -P "${COTIRE_CMAKE_MODULE_FILE}" "cleanup" "${_outputDir}" "${COTIRE_INTDIR}" "${_target}")
  2821. add_custom_target(${_cleanTargetName}
  2822. COMMAND ${_cmds}
  2823. WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
  2824. COMMENT "Cleaning up target ${_target} cotire generated files"
  2825. VERBATIM)
  2826. cotire_init_target("${_cleanTargetName}")
  2827. endif()
  2828. endfunction()
  2829. function (cotire_setup_pch_target _languages _configurations _target)
  2830. if ("${CMAKE_GENERATOR}" MATCHES "Make|Ninja")
  2831. # for makefile based generators, we add a custom target to trigger the generation of the cotire related files
  2832. set (_dependsFiles "")
  2833. foreach (_language ${_languages})
  2834. set (_props COTIRE_${_language}_PREFIX_HEADER COTIRE_${_language}_UNITY_SOURCE)
  2835. if (NOT CMAKE_${_language}_COMPILER_ID MATCHES "MSVC|Intel")
  2836. # Visual Studio and Intel only create precompiled header as a side effect
  2837. list (INSERT _props 0 COTIRE_${_language}_PRECOMPILED_HEADER)
  2838. endif()
  2839. cotire_get_first_set_property_value(_dependsFile TARGET ${_target} ${_props})
  2840. if (_dependsFile)
  2841. list (APPEND _dependsFiles "${_dependsFile}")
  2842. endif()
  2843. endforeach()
  2844. if (_dependsFiles)
  2845. set (_pchTargetName "${_target}${COTIRE_PCH_TARGET_SUFFIX}")
  2846. add_custom_target("${_pchTargetName}" DEPENDS ${_dependsFiles})
  2847. cotire_init_target("${_pchTargetName}")
  2848. cotire_add_to_pch_all_target(${_pchTargetName})
  2849. endif()
  2850. else()
  2851. # for other generators, we add the "clean all" target to clean up the precompiled header
  2852. cotire_setup_clean_all_target()
  2853. endif()
  2854. endfunction()
  2855. function (cotire_filter_object_libraries _target _objectLibrariesVar)
  2856. set (_objectLibraries "")
  2857. foreach (_source ${ARGN})
  2858. if (_source MATCHES "^\\$<TARGET_OBJECTS:.+>$")
  2859. list (APPEND _objectLibraries "${_source}")
  2860. endif()
  2861. endforeach()
  2862. set (${_objectLibrariesVar} ${_objectLibraries} PARENT_SCOPE)
  2863. endfunction()
  2864. function (cotire_collect_unity_target_sources _target _languages _unityTargetSourcesVar)
  2865. get_target_property(_targetSourceFiles ${_target} SOURCES)
  2866. set (_unityTargetSources ${_targetSourceFiles})
  2867. foreach (_language ${_languages})
  2868. get_property(_unityFiles TARGET ${_target} PROPERTY COTIRE_${_language}_UNITY_SOURCE)
  2869. if (_unityFiles)
  2870. # remove source files that are included in the unity source
  2871. set (_sourceFiles "")
  2872. set (_excludedSources "")
  2873. set (_cotiredSources "")
  2874. cotire_filter_language_source_files(${_language} ${_target} _sourceFiles _excludedSources _cotiredSources ${_targetSourceFiles})
  2875. if (_sourceFiles OR _cotiredSources)
  2876. list (REMOVE_ITEM _unityTargetSources ${_sourceFiles} ${_cotiredSources})
  2877. endif()
  2878. # add unity source files instead
  2879. list (APPEND _unityTargetSources ${_unityFiles})
  2880. endif()
  2881. endforeach()
  2882. get_target_property(_linkLibrariesStrategy ${_target} COTIRE_UNITY_LINK_LIBRARIES_INIT)
  2883. if ("${_linkLibrariesStrategy}" MATCHES "^COPY_UNITY$")
  2884. cotire_filter_object_libraries(${_target} _objectLibraries ${_targetSourceFiles})
  2885. if (_objectLibraries)
  2886. cotire_map_libraries("${_linkLibrariesStrategy}" _unityObjectLibraries ${_objectLibraries})
  2887. list (REMOVE_ITEM _unityTargetSources ${_objectLibraries})
  2888. list (APPEND _unityTargetSources ${_unityObjectLibraries})
  2889. endif()
  2890. endif()
  2891. set (${_unityTargetSourcesVar} ${_unityTargetSources} PARENT_SCOPE)
  2892. endfunction()
  2893. function (cotire_setup_unity_target_pch_usage _languages _target)
  2894. foreach (_language ${_languages})
  2895. get_property(_unityFiles TARGET ${_target} PROPERTY COTIRE_${_language}_UNITY_SOURCE)
  2896. if (_unityFiles)
  2897. get_property(_userPrefixFile TARGET ${_target} PROPERTY COTIRE_${_language}_PREFIX_HEADER_INIT)
  2898. get_property(_prefixFile TARGET ${_target} PROPERTY COTIRE_${_language}_PREFIX_HEADER)
  2899. if (_userPrefixFile AND _prefixFile)
  2900. # user provided prefix header must be included unconditionally by unity sources
  2901. cotire_setup_prefix_file_inclusion(${_language} ${_target} "${_prefixFile}" ${_unityFiles})
  2902. endif()
  2903. endif()
  2904. endforeach()
  2905. endfunction()
  2906. function (cotire_setup_unity_build_target _languages _configurations _target)
  2907. get_target_property(_unityTargetName ${_target} COTIRE_UNITY_TARGET_NAME)
  2908. if (NOT _unityTargetName)
  2909. set (_unityTargetName "${_target}${COTIRE_UNITY_BUILD_TARGET_SUFFIX}")
  2910. endif()
  2911. # determine unity target sub type
  2912. get_target_property(_targetType ${_target} TYPE)
  2913. if ("${_targetType}" STREQUAL "EXECUTABLE")
  2914. set (_unityTargetSubType "")
  2915. elseif (_targetType MATCHES "(STATIC|SHARED|MODULE|OBJECT)_LIBRARY")
  2916. set (_unityTargetSubType "${CMAKE_MATCH_1}")
  2917. else()
  2918. message (WARNING "cotire: target ${_target} has unknown target type ${_targetType}.")
  2919. return()
  2920. endif()
  2921. # determine unity target sources
  2922. set (_unityTargetSources "")
  2923. cotire_collect_unity_target_sources(${_target} "${_languages}" _unityTargetSources)
  2924. # handle automatic Qt processing
  2925. get_target_property(_targetAutoMoc ${_target} AUTOMOC)
  2926. get_target_property(_targetAutoUic ${_target} AUTOUIC)
  2927. get_target_property(_targetAutoRcc ${_target} AUTORCC)
  2928. if (_targetAutoMoc OR _targetAutoUic OR _targetAutoRcc)
  2929. # if the original target sources are subject to CMake's automatic Qt processing,
  2930. # also include implicitly generated <targetname>_automoc.cpp file
  2931. if (CMAKE_VERSION VERSION_LESS "3.8.0")
  2932. list (APPEND _unityTargetSources "${_target}_automoc.cpp")
  2933. set_property (SOURCE "${_target}_automoc.cpp" PROPERTY GENERATED TRUE)
  2934. else()
  2935. list (APPEND _unityTargetSources "${_target}_autogen/moc_compilation.cpp")
  2936. set_property (SOURCE "${_target}_autogen/moc_compilation.cpp" PROPERTY GENERATED TRUE)
  2937. endif()
  2938. endif()
  2939. # prevent AUTOMOC, AUTOUIC and AUTORCC properties from being set when the unity target is created
  2940. set (CMAKE_AUTOMOC OFF)
  2941. set (CMAKE_AUTOUIC OFF)
  2942. set (CMAKE_AUTORCC OFF)
  2943. if (COTIRE_DEBUG)
  2944. message (STATUS "add target ${_targetType} ${_unityTargetName} ${_unityTargetSubType} EXCLUDE_FROM_ALL ${_unityTargetSources}")
  2945. endif()
  2946. # generate unity target
  2947. if ("${_targetType}" STREQUAL "EXECUTABLE")
  2948. add_executable(${_unityTargetName} ${_unityTargetSubType} EXCLUDE_FROM_ALL ${_unityTargetSources})
  2949. else()
  2950. add_library(${_unityTargetName} ${_unityTargetSubType} EXCLUDE_FROM_ALL ${_unityTargetSources})
  2951. endif()
  2952. if ("${CMAKE_GENERATOR}" MATCHES "Visual Studio")
  2953. # depend on original target's automoc target, if it exists
  2954. if (TARGET ${_target}_automoc)
  2955. add_dependencies(${_unityTargetName} ${_target}_automoc)
  2956. endif()
  2957. else()
  2958. if (_targetAutoMoc OR _targetAutoUic OR _targetAutoRcc)
  2959. # depend on the original target's implicity generated <targetname>_automoc target
  2960. if (CMAKE_VERSION VERSION_LESS "3.8.0")
  2961. add_dependencies(${_unityTargetName} ${_target}_automoc)
  2962. else()
  2963. add_dependencies(${_unityTargetName} ${_target}_autogen)
  2964. endif()
  2965. endif()
  2966. endif()
  2967. # copy output location properties
  2968. set (_outputDirProperties
  2969. ARCHIVE_OUTPUT_DIRECTORY ARCHIVE_OUTPUT_DIRECTORY_<CONFIG>
  2970. LIBRARY_OUTPUT_DIRECTORY LIBRARY_OUTPUT_DIRECTORY_<CONFIG>
  2971. RUNTIME_OUTPUT_DIRECTORY RUNTIME_OUTPUT_DIRECTORY_<CONFIG>)
  2972. if (COTIRE_UNITY_OUTPUT_DIRECTORY)
  2973. set (_setDefaultOutputDir TRUE)
  2974. if (IS_ABSOLUTE "${COTIRE_UNITY_OUTPUT_DIRECTORY}")
  2975. set (_outputDir "${COTIRE_UNITY_OUTPUT_DIRECTORY}")
  2976. else()
  2977. # append relative COTIRE_UNITY_OUTPUT_DIRECTORY to target's actual output directory
  2978. cotire_copy_set_properties("${_configurations}" TARGET ${_target} ${_unityTargetName} ${_outputDirProperties})
  2979. cotire_resolve_config_properties("${_configurations}" _properties ${_outputDirProperties})
  2980. foreach (_property ${_properties})
  2981. get_property(_outputDir TARGET ${_target} PROPERTY ${_property})
  2982. if (_outputDir)
  2983. get_filename_component(_outputDir "${_outputDir}/${COTIRE_UNITY_OUTPUT_DIRECTORY}" ABSOLUTE)
  2984. set_property(TARGET ${_unityTargetName} PROPERTY ${_property} "${_outputDir}")
  2985. set (_setDefaultOutputDir FALSE)
  2986. endif()
  2987. endforeach()
  2988. if (_setDefaultOutputDir)
  2989. get_filename_component(_outputDir "${CMAKE_CURRENT_BINARY_DIR}/${COTIRE_UNITY_OUTPUT_DIRECTORY}" ABSOLUTE)
  2990. endif()
  2991. endif()
  2992. if (_setDefaultOutputDir)
  2993. set_target_properties(${_unityTargetName} PROPERTIES
  2994. ARCHIVE_OUTPUT_DIRECTORY "${_outputDir}"
  2995. LIBRARY_OUTPUT_DIRECTORY "${_outputDir}"
  2996. RUNTIME_OUTPUT_DIRECTORY "${_outputDir}")
  2997. endif()
  2998. else()
  2999. cotire_copy_set_properties("${_configurations}" TARGET ${_target} ${_unityTargetName}
  3000. ${_outputDirProperties})
  3001. endif()
  3002. # copy output name
  3003. cotire_copy_set_properties("${_configurations}" TARGET ${_target} ${_unityTargetName}
  3004. ARCHIVE_OUTPUT_NAME ARCHIVE_OUTPUT_NAME_<CONFIG>
  3005. LIBRARY_OUTPUT_NAME LIBRARY_OUTPUT_NAME_<CONFIG>
  3006. OUTPUT_NAME OUTPUT_NAME_<CONFIG>
  3007. RUNTIME_OUTPUT_NAME RUNTIME_OUTPUT_NAME_<CONFIG>
  3008. PREFIX <CONFIG>_POSTFIX SUFFIX
  3009. IMPORT_PREFIX IMPORT_SUFFIX)
  3010. # copy compile stuff
  3011. cotire_copy_set_properties("${_configurations}" TARGET ${_target} ${_unityTargetName}
  3012. COMPILE_DEFINITIONS COMPILE_DEFINITIONS_<CONFIG>
  3013. COMPILE_FLAGS COMPILE_OPTIONS
  3014. Fortran_FORMAT Fortran_MODULE_DIRECTORY
  3015. INCLUDE_DIRECTORIES
  3016. INTERPROCEDURAL_OPTIMIZATION INTERPROCEDURAL_OPTIMIZATION_<CONFIG>
  3017. POSITION_INDEPENDENT_CODE
  3018. C_COMPILER_LAUNCHER CXX_COMPILER_LAUNCHER
  3019. C_INCLUDE_WHAT_YOU_USE CXX_INCLUDE_WHAT_YOU_USE
  3020. C_VISIBILITY_PRESET CXX_VISIBILITY_PRESET VISIBILITY_INLINES_HIDDEN
  3021. C_CLANG_TIDY CXX_CLANG_TIDY)
  3022. # copy compile features
  3023. cotire_copy_set_properties("${_configurations}" TARGET ${_target} ${_unityTargetName}
  3024. C_EXTENSIONS C_STANDARD C_STANDARD_REQUIRED
  3025. CXX_EXTENSIONS CXX_STANDARD CXX_STANDARD_REQUIRED
  3026. COMPILE_FEATURES)
  3027. # copy interface stuff
  3028. cotire_copy_set_properties("${_configurations}" TARGET ${_target} ${_unityTargetName}
  3029. COMPATIBLE_INTERFACE_BOOL COMPATIBLE_INTERFACE_NUMBER_MAX COMPATIBLE_INTERFACE_NUMBER_MIN
  3030. COMPATIBLE_INTERFACE_STRING
  3031. INTERFACE_COMPILE_DEFINITIONS INTERFACE_COMPILE_FEATURES INTERFACE_COMPILE_OPTIONS
  3032. INTERFACE_INCLUDE_DIRECTORIES INTERFACE_SOURCES
  3033. INTERFACE_POSITION_INDEPENDENT_CODE INTERFACE_SYSTEM_INCLUDE_DIRECTORIES
  3034. INTERFACE_AUTOUIC_OPTIONS NO_SYSTEM_FROM_IMPORTED)
  3035. # copy link stuff
  3036. cotire_copy_set_properties("${_configurations}" TARGET ${_target} ${_unityTargetName}
  3037. BUILD_WITH_INSTALL_RPATH INSTALL_RPATH INSTALL_RPATH_USE_LINK_PATH SKIP_BUILD_RPATH
  3038. LINKER_LANGUAGE LINK_DEPENDS LINK_DEPENDS_NO_SHARED
  3039. LINK_FLAGS LINK_FLAGS_<CONFIG>
  3040. LINK_INTERFACE_LIBRARIES LINK_INTERFACE_LIBRARIES_<CONFIG>
  3041. LINK_INTERFACE_MULTIPLICITY LINK_INTERFACE_MULTIPLICITY_<CONFIG>
  3042. LINK_SEARCH_START_STATIC LINK_SEARCH_END_STATIC
  3043. STATIC_LIBRARY_FLAGS STATIC_LIBRARY_FLAGS_<CONFIG>
  3044. NO_SONAME SOVERSION VERSION
  3045. LINK_WHAT_YOU_USE BUILD_RPATH)
  3046. # copy cmake stuff
  3047. cotire_copy_set_properties("${_configurations}" TARGET ${_target} ${_unityTargetName}
  3048. IMPLICIT_DEPENDS_INCLUDE_TRANSFORM RULE_LAUNCH_COMPILE RULE_LAUNCH_CUSTOM RULE_LAUNCH_LINK)
  3049. # copy Apple platform specific stuff
  3050. cotire_copy_set_properties("${_configurations}" TARGET ${_target} ${_unityTargetName}
  3051. BUNDLE BUNDLE_EXTENSION FRAMEWORK FRAMEWORK_VERSION INSTALL_NAME_DIR
  3052. MACOSX_BUNDLE MACOSX_BUNDLE_INFO_PLIST MACOSX_FRAMEWORK_INFO_PLIST MACOSX_RPATH
  3053. OSX_ARCHITECTURES OSX_ARCHITECTURES_<CONFIG> PRIVATE_HEADER PUBLIC_HEADER RESOURCE XCTEST
  3054. IOS_INSTALL_COMBINED XCODE_EXPLICIT_FILE_TYPE XCODE_PRODUCT_TYPE)
  3055. # copy Windows platform specific stuff
  3056. cotire_copy_set_properties("${_configurations}" TARGET ${_target} ${_unityTargetName}
  3057. GNUtoMS
  3058. COMPILE_PDB_NAME COMPILE_PDB_NAME_<CONFIG>
  3059. COMPILE_PDB_OUTPUT_DIRECTORY COMPILE_PDB_OUTPUT_DIRECTORY_<CONFIG>
  3060. PDB_NAME PDB_NAME_<CONFIG> PDB_OUTPUT_DIRECTORY PDB_OUTPUT_DIRECTORY_<CONFIG>
  3061. VS_DESKTOP_EXTENSIONS_VERSION VS_DOTNET_REFERENCES VS_DOTNET_TARGET_FRAMEWORK_VERSION
  3062. VS_GLOBAL_KEYWORD VS_GLOBAL_PROJECT_TYPES VS_GLOBAL_ROOTNAMESPACE
  3063. VS_IOT_EXTENSIONS_VERSION VS_IOT_STARTUP_TASK
  3064. VS_KEYWORD VS_MOBILE_EXTENSIONS_VERSION
  3065. VS_SCC_AUXPATH VS_SCC_LOCALPATH VS_SCC_PROJECTNAME VS_SCC_PROVIDER
  3066. VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION
  3067. VS_WINRT_COMPONENT VS_WINRT_EXTENSIONS VS_WINRT_REFERENCES
  3068. WIN32_EXECUTABLE WINDOWS_EXPORT_ALL_SYMBOLS
  3069. DEPLOYMENT_REMOTE_DIRECTORY VS_CONFIGURATION_TYPE
  3070. VS_SDK_REFERENCES VS_USER_PROPS VS_DEBUGGER_WORKING_DIRECTORY)
  3071. # copy Android platform specific stuff
  3072. cotire_copy_set_properties("${_configurations}" TARGET ${_target} ${_unityTargetName}
  3073. ANDROID_API ANDROID_API_MIN ANDROID_GUI
  3074. ANDROID_ANT_ADDITIONAL_OPTIONS ANDROID_ARCH ANDROID_ASSETS_DIRECTORIES
  3075. ANDROID_JAR_DEPENDENCIES ANDROID_JAR_DIRECTORIES ANDROID_JAVA_SOURCE_DIR
  3076. ANDROID_NATIVE_LIB_DEPENDENCIES ANDROID_NATIVE_LIB_DIRECTORIES
  3077. ANDROID_PROCESS_MAX ANDROID_PROGUARD ANDROID_PROGUARD_CONFIG_PATH
  3078. ANDROID_SECURE_PROPS_PATH ANDROID_SKIP_ANT_STEP ANDROID_STL_TYPE)
  3079. # use output name from original target
  3080. get_target_property(_targetOutputName ${_unityTargetName} OUTPUT_NAME)
  3081. if (NOT _targetOutputName)
  3082. set_property(TARGET ${_unityTargetName} PROPERTY OUTPUT_NAME "${_target}")
  3083. endif()
  3084. # use export symbol from original target
  3085. cotire_get_target_export_symbol("${_target}" _defineSymbol)
  3086. if (_defineSymbol)
  3087. set_property(TARGET ${_unityTargetName} PROPERTY DEFINE_SYMBOL "${_defineSymbol}")
  3088. if ("${_targetType}" STREQUAL "EXECUTABLE")
  3089. set_property(TARGET ${_unityTargetName} PROPERTY ENABLE_EXPORTS TRUE)
  3090. endif()
  3091. endif()
  3092. cotire_init_target(${_unityTargetName})
  3093. cotire_add_to_unity_all_target(${_unityTargetName})
  3094. set_property(TARGET ${_target} PROPERTY COTIRE_UNITY_TARGET_NAME "${_unityTargetName}")
  3095. endfunction(cotire_setup_unity_build_target)
  3096. function (cotire_target _target)
  3097. set(_options "")
  3098. set(_oneValueArgs "")
  3099. set(_multiValueArgs LANGUAGES CONFIGURATIONS)
  3100. cmake_parse_arguments(_option "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
  3101. if (NOT _option_LANGUAGES)
  3102. get_property (_option_LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES)
  3103. endif()
  3104. if (NOT _option_CONFIGURATIONS)
  3105. cotire_get_configuration_types(_option_CONFIGURATIONS)
  3106. endif()
  3107. # check if cotire can be applied to target at all
  3108. cotire_is_target_supported(${_target} _isSupported)
  3109. if (NOT _isSupported)
  3110. get_target_property(_imported ${_target} IMPORTED)
  3111. get_target_property(_targetType ${_target} TYPE)
  3112. if (_imported)
  3113. message (WARNING "cotire: imported ${_targetType} target ${_target} cannot be cotired.")
  3114. else()
  3115. message (STATUS "cotire: ${_targetType} target ${_target} cannot be cotired.")
  3116. endif()
  3117. return()
  3118. endif()
  3119. # resolve alias
  3120. get_target_property(_aliasName ${_target} ALIASED_TARGET)
  3121. if (_aliasName)
  3122. if (COTIRE_DEBUG)
  3123. message (STATUS "${_target} is an alias. Applying cotire to aliased target ${_aliasName} instead.")
  3124. endif()
  3125. set (_target ${_aliasName})
  3126. endif()
  3127. # check if target needs to be cotired for build type
  3128. # when using configuration types, the test is performed at build time
  3129. cotire_init_cotire_target_properties(${_target})
  3130. if (NOT CMAKE_CONFIGURATION_TYPES)
  3131. if (CMAKE_BUILD_TYPE)
  3132. list (FIND _option_CONFIGURATIONS "${CMAKE_BUILD_TYPE}" _index)
  3133. else()
  3134. list (FIND _option_CONFIGURATIONS "None" _index)
  3135. endif()
  3136. if (_index EQUAL -1)
  3137. if (COTIRE_DEBUG)
  3138. message (STATUS "CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} not cotired (${_option_CONFIGURATIONS})")
  3139. endif()
  3140. return()
  3141. endif()
  3142. endif()
  3143. # when not using configuration types, immediately create cotire intermediate dir
  3144. if (NOT CMAKE_CONFIGURATION_TYPES)
  3145. cotire_get_intermediate_dir(_baseDir)
  3146. file (MAKE_DIRECTORY "${_baseDir}")
  3147. endif()
  3148. # choose languages that apply to the target
  3149. cotire_choose_target_languages("${_target}" _targetLanguages _wholeTarget ${_option_LANGUAGES})
  3150. if (NOT _targetLanguages)
  3151. return()
  3152. endif()
  3153. set (_cmds "")
  3154. foreach (_language ${_targetLanguages})
  3155. cotire_process_target_language("${_language}" "${_option_CONFIGURATIONS}" ${_target} ${_wholeTarget} _cmd)
  3156. if (_cmd)
  3157. list (APPEND _cmds ${_cmd})
  3158. endif()
  3159. endforeach()
  3160. get_target_property(_targetAddSCU ${_target} COTIRE_ADD_UNITY_BUILD)
  3161. if (_targetAddSCU)
  3162. cotire_setup_unity_build_target("${_targetLanguages}" "${_option_CONFIGURATIONS}" ${_target})
  3163. endif()
  3164. get_target_property(_targetUsePCH ${_target} COTIRE_ENABLE_PRECOMPILED_HEADER)
  3165. if (_targetUsePCH)
  3166. cotire_setup_target_pch_usage("${_targetLanguages}" ${_target} ${_wholeTarget} ${_cmds})
  3167. cotire_setup_pch_target("${_targetLanguages}" "${_option_CONFIGURATIONS}" ${_target})
  3168. if (_targetAddSCU)
  3169. cotire_setup_unity_target_pch_usage("${_targetLanguages}" ${_target})
  3170. endif()
  3171. endif()
  3172. get_target_property(_targetAddCleanTarget ${_target} COTIRE_ADD_CLEAN)
  3173. if (_targetAddCleanTarget)
  3174. cotire_setup_clean_target(${_target})
  3175. endif()
  3176. endfunction(cotire_target)
  3177. function (cotire_map_libraries _strategy _mappedLibrariesVar)
  3178. set (_mappedLibraries "")
  3179. foreach (_library ${ARGN})
  3180. if (_library MATCHES "^\\$<LINK_ONLY:(.+)>$")
  3181. set (_libraryName "${CMAKE_MATCH_1}")
  3182. set (_linkOnly TRUE)
  3183. set (_objectLibrary FALSE)
  3184. elseif (_library MATCHES "^\\$<TARGET_OBJECTS:(.+)>$")
  3185. set (_libraryName "${CMAKE_MATCH_1}")
  3186. set (_linkOnly FALSE)
  3187. set (_objectLibrary TRUE)
  3188. else()
  3189. set (_libraryName "${_library}")
  3190. set (_linkOnly FALSE)
  3191. set (_objectLibrary FALSE)
  3192. endif()
  3193. if ("${_strategy}" MATCHES "COPY_UNITY")
  3194. cotire_is_target_supported(${_libraryName} _isSupported)
  3195. if (_isSupported)
  3196. # use target's corresponding unity target, if available
  3197. get_target_property(_libraryUnityTargetName ${_libraryName} COTIRE_UNITY_TARGET_NAME)
  3198. if (TARGET "${_libraryUnityTargetName}")
  3199. if (_linkOnly)
  3200. list (APPEND _mappedLibraries "$<LINK_ONLY:${_libraryUnityTargetName}>")
  3201. elseif (_objectLibrary)
  3202. list (APPEND _mappedLibraries "$<TARGET_OBJECTS:${_libraryUnityTargetName}>")
  3203. else()
  3204. list (APPEND _mappedLibraries "${_libraryUnityTargetName}")
  3205. endif()
  3206. else()
  3207. list (APPEND _mappedLibraries "${_library}")
  3208. endif()
  3209. else()
  3210. list (APPEND _mappedLibraries "${_library}")
  3211. endif()
  3212. else()
  3213. list (APPEND _mappedLibraries "${_library}")
  3214. endif()
  3215. endforeach()
  3216. list (REMOVE_DUPLICATES _mappedLibraries)
  3217. set (${_mappedLibrariesVar} ${_mappedLibraries} PARENT_SCOPE)
  3218. endfunction()
  3219. function (cotire_target_link_libraries _target)
  3220. cotire_is_target_supported(${_target} _isSupported)
  3221. if (NOT _isSupported)
  3222. return()
  3223. endif()
  3224. get_target_property(_unityTargetName ${_target} COTIRE_UNITY_TARGET_NAME)
  3225. if (TARGET "${_unityTargetName}")
  3226. get_target_property(_linkLibrariesStrategy ${_target} COTIRE_UNITY_LINK_LIBRARIES_INIT)
  3227. if (COTIRE_DEBUG)
  3228. message (STATUS "unity target ${_unityTargetName} link strategy: ${_linkLibrariesStrategy}")
  3229. endif()
  3230. if ("${_linkLibrariesStrategy}" MATCHES "^(COPY|COPY_UNITY)$")
  3231. get_target_property(_linkLibraries ${_target} LINK_LIBRARIES)
  3232. if (_linkLibraries)
  3233. cotire_map_libraries("${_linkLibrariesStrategy}" _unityLinkLibraries ${_linkLibraries})
  3234. set_target_properties(${_unityTargetName} PROPERTIES LINK_LIBRARIES "${_unityLinkLibraries}")
  3235. if (COTIRE_DEBUG)
  3236. message (STATUS "unity target ${_unityTargetName} link libraries: ${_unityLinkLibraries}")
  3237. endif()
  3238. endif()
  3239. get_target_property(_interfaceLinkLibraries ${_target} INTERFACE_LINK_LIBRARIES)
  3240. if (_interfaceLinkLibraries)
  3241. cotire_map_libraries("${_linkLibrariesStrategy}" _unityLinkInterfaceLibraries ${_interfaceLinkLibraries})
  3242. set_target_properties(${_unityTargetName} PROPERTIES INTERFACE_LINK_LIBRARIES "${_unityLinkInterfaceLibraries}")
  3243. if (COTIRE_DEBUG)
  3244. message (STATUS "unity target ${_unityTargetName} interface link libraries: ${_unityLinkInterfaceLibraries}")
  3245. endif()
  3246. endif()
  3247. endif()
  3248. endif()
  3249. endfunction(cotire_target_link_libraries)
  3250. function (cotire_cleanup _binaryDir _cotireIntermediateDirName _targetName)
  3251. if (_targetName)
  3252. file (GLOB_RECURSE _cotireFiles "${_binaryDir}/${_targetName}*.*")
  3253. else()
  3254. file (GLOB_RECURSE _cotireFiles "${_binaryDir}/*.*")
  3255. endif()
  3256. # filter files in intermediate directory
  3257. set (_filesToRemove "")
  3258. foreach (_file ${_cotireFiles})
  3259. get_filename_component(_dir "${_file}" DIRECTORY)
  3260. get_filename_component(_dirName "${_dir}" NAME)
  3261. if ("${_dirName}" STREQUAL "${_cotireIntermediateDirName}")
  3262. list (APPEND _filesToRemove "${_file}")
  3263. endif()
  3264. endforeach()
  3265. if (_filesToRemove)
  3266. if (COTIRE_VERBOSE)
  3267. message (STATUS "cleaning up ${_filesToRemove}")
  3268. endif()
  3269. file (REMOVE ${_filesToRemove})
  3270. endif()
  3271. endfunction()
  3272. function (cotire_init_target _targetName)
  3273. if (COTIRE_TARGETS_FOLDER)
  3274. set_target_properties(${_targetName} PROPERTIES FOLDER "${COTIRE_TARGETS_FOLDER}")
  3275. endif()
  3276. set_target_properties(${_targetName} PROPERTIES EXCLUDE_FROM_ALL TRUE)
  3277. if (MSVC_IDE)
  3278. set_target_properties(${_targetName} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD TRUE)
  3279. endif()
  3280. endfunction()
  3281. function (cotire_add_to_pch_all_target _pchTargetName)
  3282. set (_targetName "${COTIRE_PCH_ALL_TARGET_NAME}")
  3283. if (NOT TARGET "${_targetName}")
  3284. add_custom_target("${_targetName}"
  3285. WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
  3286. VERBATIM)
  3287. cotire_init_target("${_targetName}")
  3288. endif()
  3289. cotire_setup_clean_all_target()
  3290. add_dependencies(${_targetName} ${_pchTargetName})
  3291. endfunction()
  3292. function (cotire_add_to_unity_all_target _unityTargetName)
  3293. set (_targetName "${COTIRE_UNITY_BUILD_ALL_TARGET_NAME}")
  3294. if (NOT TARGET "${_targetName}")
  3295. add_custom_target("${_targetName}"
  3296. WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
  3297. VERBATIM)
  3298. cotire_init_target("${_targetName}")
  3299. endif()
  3300. cotire_setup_clean_all_target()
  3301. add_dependencies(${_targetName} ${_unityTargetName})
  3302. endfunction()
  3303. function (cotire_setup_clean_all_target)
  3304. set (_targetName "${COTIRE_CLEAN_ALL_TARGET_NAME}")
  3305. if (NOT TARGET "${_targetName}")
  3306. cotire_set_cmd_to_prologue(_cmds)
  3307. list (APPEND _cmds -P "${COTIRE_CMAKE_MODULE_FILE}" "cleanup" "${CMAKE_BINARY_DIR}" "${COTIRE_INTDIR}")
  3308. add_custom_target(${_targetName}
  3309. COMMAND ${_cmds}
  3310. WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
  3311. COMMENT "Cleaning up all cotire generated files"
  3312. VERBATIM)
  3313. cotire_init_target("${_targetName}")
  3314. endif()
  3315. endfunction()
  3316. function (cotire)
  3317. set(_options "")
  3318. set(_oneValueArgs "")
  3319. set(_multiValueArgs LANGUAGES CONFIGURATIONS)
  3320. cmake_parse_arguments(_option "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN})
  3321. set (_targets ${_option_UNPARSED_ARGUMENTS})
  3322. foreach (_target ${_targets})
  3323. if (TARGET ${_target})
  3324. cotire_target(${_target} LANGUAGES ${_option_LANGUAGES} CONFIGURATIONS ${_option_CONFIGURATIONS})
  3325. else()
  3326. message (WARNING "cotire: ${_target} is not a target.")
  3327. endif()
  3328. endforeach()
  3329. foreach (_target ${_targets})
  3330. if (TARGET ${_target})
  3331. cotire_target_link_libraries(${_target})
  3332. endif()
  3333. endforeach()
  3334. endfunction()
  3335. if (CMAKE_SCRIPT_MODE_FILE)
  3336. # cotire is being run in script mode
  3337. # locate -P on command args
  3338. set (COTIRE_ARGC -1)
  3339. foreach (_index RANGE ${CMAKE_ARGC})
  3340. if (COTIRE_ARGC GREATER -1)
  3341. set (COTIRE_ARGV${COTIRE_ARGC} "${CMAKE_ARGV${_index}}")
  3342. math (EXPR COTIRE_ARGC "${COTIRE_ARGC} + 1")
  3343. elseif ("${CMAKE_ARGV${_index}}" STREQUAL "-P")
  3344. set (COTIRE_ARGC 0)
  3345. endif()
  3346. endforeach()
  3347. # include target script if available
  3348. if ("${COTIRE_ARGV2}" MATCHES "\\.cmake$")
  3349. # the included target scripts sets up additional variables relating to the target (e.g., COTIRE_TARGET_SOURCES)
  3350. include("${COTIRE_ARGV2}")
  3351. endif()
  3352. if (COTIRE_DEBUG)
  3353. message (STATUS "${COTIRE_ARGV0} ${COTIRE_ARGV1} ${COTIRE_ARGV2} ${COTIRE_ARGV3} ${COTIRE_ARGV4} ${COTIRE_ARGV5}")
  3354. endif()
  3355. if (NOT COTIRE_BUILD_TYPE)
  3356. set (COTIRE_BUILD_TYPE "None")
  3357. endif()
  3358. string (TOUPPER "${COTIRE_BUILD_TYPE}" _upperConfig)
  3359. set (_includeDirs ${COTIRE_TARGET_INCLUDE_DIRECTORIES_${_upperConfig}})
  3360. set (_systemIncludeDirs ${COTIRE_TARGET_SYSTEM_INCLUDE_DIRECTORIES_${_upperConfig}})
  3361. set (_compileDefinitions ${COTIRE_TARGET_COMPILE_DEFINITIONS_${_upperConfig}})
  3362. set (_compileFlags ${COTIRE_TARGET_COMPILE_FLAGS_${_upperConfig}})
  3363. # check if target has been cotired for actual build type COTIRE_BUILD_TYPE
  3364. list (FIND COTIRE_TARGET_CONFIGURATION_TYPES "${COTIRE_BUILD_TYPE}" _index)
  3365. if (_index GREATER -1)
  3366. set (_sources ${COTIRE_TARGET_SOURCES})
  3367. set (_sourcesDefinitions ${COTIRE_TARGET_SOURCES_COMPILE_DEFINITIONS_${_upperConfig}})
  3368. else()
  3369. if (COTIRE_DEBUG)
  3370. message (STATUS "COTIRE_BUILD_TYPE=${COTIRE_BUILD_TYPE} not cotired (${COTIRE_TARGET_CONFIGURATION_TYPES})")
  3371. endif()
  3372. set (_sources "")
  3373. set (_sourcesDefinitions "")
  3374. endif()
  3375. set (_targetPreUndefs ${COTIRE_TARGET_PRE_UNDEFS})
  3376. set (_targetPostUndefs ${COTIRE_TARGET_POST_UNDEFS})
  3377. set (_sourcesPreUndefs ${COTIRE_TARGET_SOURCES_PRE_UNDEFS})
  3378. set (_sourcesPostUndefs ${COTIRE_TARGET_SOURCES_POST_UNDEFS})
  3379. if ("${COTIRE_ARGV1}" STREQUAL "unity")
  3380. if (XCODE)
  3381. # executing pre-build action under Xcode, check dependency on target script
  3382. set (_dependsOption DEPENDS "${COTIRE_ARGV2}")
  3383. else()
  3384. # executing custom command, no need to re-check for dependencies
  3385. set (_dependsOption "")
  3386. endif()
  3387. cotire_select_unity_source_files("${COTIRE_ARGV3}" _sources ${_sources})
  3388. cotire_generate_unity_source(
  3389. "${COTIRE_ARGV3}" ${_sources}
  3390. LANGUAGE "${COTIRE_TARGET_LANGUAGE}"
  3391. SOURCES_COMPILE_DEFINITIONS ${_sourcesDefinitions}
  3392. PRE_UNDEFS ${_targetPreUndefs}
  3393. POST_UNDEFS ${_targetPostUndefs}
  3394. SOURCES_PRE_UNDEFS ${_sourcesPreUndefs}
  3395. SOURCES_POST_UNDEFS ${_sourcesPostUndefs}
  3396. ${_dependsOption})
  3397. elseif ("${COTIRE_ARGV1}" STREQUAL "prefix")
  3398. if (XCODE)
  3399. # executing pre-build action under Xcode, check dependency on unity file and prefix dependencies
  3400. set (_dependsOption DEPENDS "${COTIRE_ARGV4}" ${COTIRE_TARGET_PREFIX_DEPENDS})
  3401. else()
  3402. # executing custom command, no need to re-check for dependencies
  3403. set (_dependsOption "")
  3404. endif()
  3405. set (_files "")
  3406. foreach (_index RANGE 4 ${COTIRE_ARGC})
  3407. if (COTIRE_ARGV${_index})
  3408. list (APPEND _files "${COTIRE_ARGV${_index}}")
  3409. endif()
  3410. endforeach()
  3411. cotire_generate_prefix_header(
  3412. "${COTIRE_ARGV3}" ${_files}
  3413. COMPILER_LAUNCHER "${COTIRE_TARGET_${COTIRE_TARGET_LANGUAGE}_COMPILER_LAUNCHER}"
  3414. COMPILER_EXECUTABLE "${CMAKE_${COTIRE_TARGET_LANGUAGE}_COMPILER}"
  3415. COMPILER_ARG1 ${CMAKE_${COTIRE_TARGET_LANGUAGE}_COMPILER_ARG1}
  3416. COMPILER_ID "${CMAKE_${COTIRE_TARGET_LANGUAGE}_COMPILER_ID}"
  3417. COMPILER_VERSION "${CMAKE_${COTIRE_TARGET_LANGUAGE}_COMPILER_VERSION}"
  3418. LANGUAGE "${COTIRE_TARGET_LANGUAGE}"
  3419. IGNORE_PATH "${COTIRE_TARGET_IGNORE_PATH};${COTIRE_ADDITIONAL_PREFIX_HEADER_IGNORE_PATH}"
  3420. INCLUDE_PATH ${COTIRE_TARGET_INCLUDE_PATH}
  3421. IGNORE_EXTENSIONS "${CMAKE_${COTIRE_TARGET_LANGUAGE}_SOURCE_FILE_EXTENSIONS};${COTIRE_ADDITIONAL_PREFIX_HEADER_IGNORE_EXTENSIONS}"
  3422. INCLUDE_PRIORITY_PATH ${COTIRE_TARGET_INCLUDE_PRIORITY_PATH}
  3423. INCLUDE_DIRECTORIES ${_includeDirs}
  3424. SYSTEM_INCLUDE_DIRECTORIES ${_systemIncludeDirs}
  3425. COMPILE_DEFINITIONS ${_compileDefinitions}
  3426. COMPILE_FLAGS ${_compileFlags}
  3427. ${_dependsOption})
  3428. elseif ("${COTIRE_ARGV1}" STREQUAL "precompile")
  3429. set (_files "")
  3430. foreach (_index RANGE 5 ${COTIRE_ARGC})
  3431. if (COTIRE_ARGV${_index})
  3432. list (APPEND _files "${COTIRE_ARGV${_index}}")
  3433. endif()
  3434. endforeach()
  3435. cotire_precompile_prefix_header(
  3436. "${COTIRE_ARGV3}" "${COTIRE_ARGV4}" "${COTIRE_ARGV5}"
  3437. COMPILER_LAUNCHER "${COTIRE_TARGET_${COTIRE_TARGET_LANGUAGE}_COMPILER_LAUNCHER}"
  3438. COMPILER_EXECUTABLE "${CMAKE_${COTIRE_TARGET_LANGUAGE}_COMPILER}"
  3439. COMPILER_ARG1 ${CMAKE_${COTIRE_TARGET_LANGUAGE}_COMPILER_ARG1}
  3440. COMPILER_ID "${CMAKE_${COTIRE_TARGET_LANGUAGE}_COMPILER_ID}"
  3441. COMPILER_VERSION "${CMAKE_${COTIRE_TARGET_LANGUAGE}_COMPILER_VERSION}"
  3442. LANGUAGE "${COTIRE_TARGET_LANGUAGE}"
  3443. INCLUDE_DIRECTORIES ${_includeDirs}
  3444. SYSTEM_INCLUDE_DIRECTORIES ${_systemIncludeDirs}
  3445. COMPILE_DEFINITIONS ${_compileDefinitions}
  3446. COMPILE_FLAGS ${_compileFlags})
  3447. elseif ("${COTIRE_ARGV1}" STREQUAL "combine")
  3448. if (COTIRE_TARGET_LANGUAGE)
  3449. set (_combinedFile "${COTIRE_ARGV3}")
  3450. set (_startIndex 4)
  3451. else()
  3452. set (_combinedFile "${COTIRE_ARGV2}")
  3453. set (_startIndex 3)
  3454. endif()
  3455. set (_files "")
  3456. foreach (_index RANGE ${_startIndex} ${COTIRE_ARGC})
  3457. if (COTIRE_ARGV${_index})
  3458. list (APPEND _files "${COTIRE_ARGV${_index}}")
  3459. endif()
  3460. endforeach()
  3461. if (XCODE)
  3462. # executing pre-build action under Xcode, check dependency on files to be combined
  3463. set (_dependsOption DEPENDS ${_files})
  3464. else()
  3465. # executing custom command, no need to re-check for dependencies
  3466. set (_dependsOption "")
  3467. endif()
  3468. if (COTIRE_TARGET_LANGUAGE)
  3469. cotire_generate_unity_source(
  3470. "${_combinedFile}" ${_files}
  3471. LANGUAGE "${COTIRE_TARGET_LANGUAGE}"
  3472. ${_dependsOption})
  3473. else()
  3474. cotire_generate_unity_source("${_combinedFile}" ${_files} ${_dependsOption})
  3475. endif()
  3476. elseif ("${COTIRE_ARGV1}" STREQUAL "cleanup")
  3477. cotire_cleanup("${COTIRE_ARGV2}" "${COTIRE_ARGV3}" "${COTIRE_ARGV4}")
  3478. else()
  3479. message (FATAL_ERROR "cotire: unknown command \"${COTIRE_ARGV1}\".")
  3480. endif()
  3481. else()
  3482. # cotire is being run in include mode
  3483. # set up all variable and property definitions
  3484. if (NOT DEFINED COTIRE_DEBUG_INIT)
  3485. if (DEFINED COTIRE_DEBUG)
  3486. set (COTIRE_DEBUG_INIT ${COTIRE_DEBUG})
  3487. else()
  3488. set (COTIRE_DEBUG_INIT FALSE)
  3489. endif()
  3490. endif()
  3491. option (COTIRE_DEBUG "Enable cotire debugging output?" ${COTIRE_DEBUG_INIT})
  3492. if (NOT DEFINED COTIRE_VERBOSE_INIT)
  3493. if (DEFINED COTIRE_VERBOSE)
  3494. set (COTIRE_VERBOSE_INIT ${COTIRE_VERBOSE})
  3495. else()
  3496. set (COTIRE_VERBOSE_INIT FALSE)
  3497. endif()
  3498. endif()
  3499. option (COTIRE_VERBOSE "Enable cotire verbose output?" ${COTIRE_VERBOSE_INIT})
  3500. set (COTIRE_ADDITIONAL_PREFIX_HEADER_IGNORE_EXTENSIONS "inc;inl;ipp" CACHE STRING
  3501. "Ignore headers with the listed file extensions from the generated prefix header.")
  3502. set (COTIRE_ADDITIONAL_PREFIX_HEADER_IGNORE_PATH "" CACHE STRING
  3503. "Ignore headers from these directories when generating the prefix header.")
  3504. set (COTIRE_UNITY_SOURCE_EXCLUDE_EXTENSIONS "m;mm" CACHE STRING
  3505. "Ignore sources with the listed file extensions from the generated unity source.")
  3506. set (COTIRE_MINIMUM_NUMBER_OF_TARGET_SOURCES "3" CACHE STRING
  3507. "Minimum number of sources in target required to enable use of precompiled header.")
  3508. if (NOT DEFINED COTIRE_MAXIMUM_NUMBER_OF_UNITY_INCLUDES_INIT)
  3509. if (DEFINED COTIRE_MAXIMUM_NUMBER_OF_UNITY_INCLUDES)
  3510. set (COTIRE_MAXIMUM_NUMBER_OF_UNITY_INCLUDES_INIT ${COTIRE_MAXIMUM_NUMBER_OF_UNITY_INCLUDES})
  3511. elseif ("${CMAKE_GENERATOR}" MATCHES "JOM|Ninja|Visual Studio")
  3512. # enable parallelization for generators that run multiple jobs by default
  3513. set (COTIRE_MAXIMUM_NUMBER_OF_UNITY_INCLUDES_INIT "-j")
  3514. else()
  3515. set (COTIRE_MAXIMUM_NUMBER_OF_UNITY_INCLUDES_INIT "0")
  3516. endif()
  3517. endif()
  3518. set (COTIRE_MAXIMUM_NUMBER_OF_UNITY_INCLUDES "${COTIRE_MAXIMUM_NUMBER_OF_UNITY_INCLUDES_INIT}" CACHE STRING
  3519. "Maximum number of source files to include in a single unity source file.")
  3520. if (NOT COTIRE_PREFIX_HEADER_FILENAME_SUFFIX)
  3521. set (COTIRE_PREFIX_HEADER_FILENAME_SUFFIX "_prefix")
  3522. endif()
  3523. if (NOT COTIRE_UNITY_SOURCE_FILENAME_SUFFIX)
  3524. set (COTIRE_UNITY_SOURCE_FILENAME_SUFFIX "_unity")
  3525. endif()
  3526. if (NOT COTIRE_INTDIR)
  3527. set (COTIRE_INTDIR "cotire")
  3528. endif()
  3529. if (NOT COTIRE_PCH_ALL_TARGET_NAME)
  3530. set (COTIRE_PCH_ALL_TARGET_NAME "all_pch")
  3531. endif()
  3532. if (NOT COTIRE_UNITY_BUILD_ALL_TARGET_NAME)
  3533. set (COTIRE_UNITY_BUILD_ALL_TARGET_NAME "all_unity")
  3534. endif()
  3535. if (NOT COTIRE_CLEAN_ALL_TARGET_NAME)
  3536. set (COTIRE_CLEAN_ALL_TARGET_NAME "clean_cotire")
  3537. endif()
  3538. if (NOT COTIRE_CLEAN_TARGET_SUFFIX)
  3539. set (COTIRE_CLEAN_TARGET_SUFFIX "_clean_cotire")
  3540. endif()
  3541. if (NOT COTIRE_PCH_TARGET_SUFFIX)
  3542. set (COTIRE_PCH_TARGET_SUFFIX "_pch")
  3543. endif()
  3544. if (MSVC)
  3545. # MSVC default PCH memory scaling factor of 100 percent (75 MB) is too small for template heavy C++ code
  3546. # use a bigger default factor of 170 percent (128 MB)
  3547. if (NOT DEFINED COTIRE_PCH_MEMORY_SCALING_FACTOR)
  3548. set (COTIRE_PCH_MEMORY_SCALING_FACTOR "170")
  3549. endif()
  3550. endif()
  3551. if (NOT COTIRE_UNITY_BUILD_TARGET_SUFFIX)
  3552. set (COTIRE_UNITY_BUILD_TARGET_SUFFIX "_unity")
  3553. endif()
  3554. if (NOT DEFINED COTIRE_TARGETS_FOLDER)
  3555. set (COTIRE_TARGETS_FOLDER "cotire")
  3556. endif()
  3557. if (NOT DEFINED COTIRE_UNITY_OUTPUT_DIRECTORY)
  3558. if ("${CMAKE_GENERATOR}" MATCHES "Ninja")
  3559. # generated Ninja build files do not work if the unity target produces the same output file as the cotired target
  3560. set (COTIRE_UNITY_OUTPUT_DIRECTORY "unity")
  3561. else()
  3562. set (COTIRE_UNITY_OUTPUT_DIRECTORY "")
  3563. endif()
  3564. endif()
  3565. # define cotire cache variables
  3566. define_property(
  3567. CACHED_VARIABLE PROPERTY "COTIRE_ADDITIONAL_PREFIX_HEADER_IGNORE_PATH"
  3568. BRIEF_DOCS "Ignore headers from these directories when generating the prefix header."
  3569. FULL_DOCS
  3570. "The variable can be set to a semicolon separated list of include directories."
  3571. "If a header file is found in one of these directories or sub-directories, it will be excluded from the generated prefix header."
  3572. "If not defined, defaults to empty list."
  3573. )
  3574. define_property(
  3575. CACHED_VARIABLE PROPERTY "COTIRE_ADDITIONAL_PREFIX_HEADER_IGNORE_EXTENSIONS"
  3576. BRIEF_DOCS "Ignore includes with the listed file extensions from the generated prefix header."
  3577. FULL_DOCS
  3578. "The variable can be set to a semicolon separated list of file extensions."
  3579. "If a header file extension matches one in the list, it will be excluded from the generated prefix header."
  3580. "Includes with an extension in CMAKE_<LANG>_SOURCE_FILE_EXTENSIONS are always ignored."
  3581. "If not defined, defaults to inc;inl;ipp."
  3582. )
  3583. define_property(
  3584. CACHED_VARIABLE PROPERTY "COTIRE_UNITY_SOURCE_EXCLUDE_EXTENSIONS"
  3585. BRIEF_DOCS "Exclude sources with the listed file extensions from the generated unity source."
  3586. FULL_DOCS
  3587. "The variable can be set to a semicolon separated list of file extensions."
  3588. "If a source file extension matches one in the list, it will be excluded from the generated unity source file."
  3589. "Source files with an extension in CMAKE_<LANG>_IGNORE_EXTENSIONS are always excluded."
  3590. "If not defined, defaults to m;mm."
  3591. )
  3592. define_property(
  3593. CACHED_VARIABLE PROPERTY "COTIRE_MINIMUM_NUMBER_OF_TARGET_SOURCES"
  3594. BRIEF_DOCS "Minimum number of sources in target required to enable use of precompiled header."
  3595. FULL_DOCS
  3596. "The variable can be set to an integer > 0."
  3597. "If a target contains less than that number of source files, cotire will not enable the use of the precompiled header for the target."
  3598. "If not defined, defaults to 3."
  3599. )
  3600. define_property(
  3601. CACHED_VARIABLE PROPERTY "COTIRE_MAXIMUM_NUMBER_OF_UNITY_INCLUDES"
  3602. BRIEF_DOCS "Maximum number of source files to include in a single unity source file."
  3603. FULL_DOCS
  3604. "This may be set to an integer >= 0."
  3605. "If 0, cotire will only create a single unity source file."
  3606. "If a target contains more than that number of source files, cotire will create multiple unity source files for it."
  3607. "Can be set to \"-j\" to optimize the count of unity source files for the number of available processor cores."
  3608. "Can be set to \"-j jobs\" to optimize the number of unity source files for the given number of simultaneous jobs."
  3609. "Is used to initialize the target property COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES."
  3610. "Defaults to \"-j\" for the generators Visual Studio, JOM or Ninja. Defaults to 0 otherwise."
  3611. )
  3612. # define cotire directory properties
  3613. define_property(
  3614. DIRECTORY PROPERTY "COTIRE_ENABLE_PRECOMPILED_HEADER"
  3615. BRIEF_DOCS "Modify build command of cotired targets added in this directory to make use of the generated precompiled header."
  3616. FULL_DOCS
  3617. "See target property COTIRE_ENABLE_PRECOMPILED_HEADER."
  3618. )
  3619. define_property(
  3620. DIRECTORY PROPERTY "COTIRE_ADD_UNITY_BUILD"
  3621. BRIEF_DOCS "Add a new target that performs a unity build for cotired targets added in this directory."
  3622. FULL_DOCS
  3623. "See target property COTIRE_ADD_UNITY_BUILD."
  3624. )
  3625. define_property(
  3626. DIRECTORY PROPERTY "COTIRE_ADD_CLEAN"
  3627. BRIEF_DOCS "Add a new target that cleans all cotire generated files for cotired targets added in this directory."
  3628. FULL_DOCS
  3629. "See target property COTIRE_ADD_CLEAN."
  3630. )
  3631. define_property(
  3632. DIRECTORY PROPERTY "COTIRE_PREFIX_HEADER_IGNORE_PATH"
  3633. BRIEF_DOCS "Ignore headers from these directories when generating the prefix header."
  3634. FULL_DOCS
  3635. "See target property COTIRE_PREFIX_HEADER_IGNORE_PATH."
  3636. )
  3637. define_property(
  3638. DIRECTORY PROPERTY "COTIRE_PREFIX_HEADER_INCLUDE_PATH"
  3639. BRIEF_DOCS "Honor headers from these directories when generating the prefix header."
  3640. FULL_DOCS
  3641. "See target property COTIRE_PREFIX_HEADER_INCLUDE_PATH."
  3642. )
  3643. define_property(
  3644. DIRECTORY PROPERTY "COTIRE_PREFIX_HEADER_INCLUDE_PRIORITY_PATH"
  3645. BRIEF_DOCS "Header paths matching one of these directories are put at the top of the prefix header."
  3646. FULL_DOCS
  3647. "See target property COTIRE_PREFIX_HEADER_INCLUDE_PRIORITY_PATH."
  3648. )
  3649. define_property(
  3650. DIRECTORY PROPERTY "COTIRE_UNITY_SOURCE_PRE_UNDEFS"
  3651. BRIEF_DOCS "Preprocessor undefs to place in the generated unity source file before the inclusion of each source file."
  3652. FULL_DOCS
  3653. "See target property COTIRE_UNITY_SOURCE_PRE_UNDEFS."
  3654. )
  3655. define_property(
  3656. DIRECTORY PROPERTY "COTIRE_UNITY_SOURCE_POST_UNDEFS"
  3657. BRIEF_DOCS "Preprocessor undefs to place in the generated unity source file after the inclusion of each source file."
  3658. FULL_DOCS
  3659. "See target property COTIRE_UNITY_SOURCE_POST_UNDEFS."
  3660. )
  3661. define_property(
  3662. DIRECTORY PROPERTY "COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES"
  3663. BRIEF_DOCS "Maximum number of source files to include in a single unity source file."
  3664. FULL_DOCS
  3665. "See target property COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES."
  3666. )
  3667. define_property(
  3668. DIRECTORY PROPERTY "COTIRE_UNITY_LINK_LIBRARIES_INIT"
  3669. BRIEF_DOCS "Define strategy for setting up the unity target's link libraries."
  3670. FULL_DOCS
  3671. "See target property COTIRE_UNITY_LINK_LIBRARIES_INIT."
  3672. )
  3673. # define cotire target properties
  3674. define_property(
  3675. TARGET PROPERTY "COTIRE_ENABLE_PRECOMPILED_HEADER" INHERITED
  3676. BRIEF_DOCS "Modify this target's build command to make use of the generated precompiled header."
  3677. FULL_DOCS
  3678. "If this property is set to TRUE, cotire will modify the build command to make use of the generated precompiled header."
  3679. "Irrespective of the value of this property, cotire will setup custom commands to generate the unity source and prefix header for the target."
  3680. "For makefile based generators cotire will also set up a custom target to manually invoke the generation of the precompiled header."
  3681. "The target name will be set to this target's name with the suffix _pch appended."
  3682. "Inherited from directory."
  3683. "Defaults to TRUE."
  3684. )
  3685. define_property(
  3686. TARGET PROPERTY "COTIRE_ADD_UNITY_BUILD" INHERITED
  3687. BRIEF_DOCS "Add a new target that performs a unity build for this target."
  3688. FULL_DOCS
  3689. "If this property is set to TRUE, cotire creates a new target of the same type that uses the generated unity source file instead of the target sources."
  3690. "Most of the relevant target properties will be copied from this target to the new unity build target."
  3691. "Target dependencies and linked libraries have to be manually set up for the new unity build target."
  3692. "The unity target name will be set to this target's name with the suffix _unity appended."
  3693. "Inherited from directory."
  3694. "Defaults to TRUE."
  3695. )
  3696. define_property(
  3697. TARGET PROPERTY "COTIRE_ADD_CLEAN" INHERITED
  3698. BRIEF_DOCS "Add a new target that cleans all cotire generated files for this target."
  3699. FULL_DOCS
  3700. "If this property is set to TRUE, cotire creates a new target that clean all files (unity source, prefix header, precompiled header)."
  3701. "The clean target name will be set to this target's name with the suffix _clean_cotire appended."
  3702. "Inherited from directory."
  3703. "Defaults to FALSE."
  3704. )
  3705. define_property(
  3706. TARGET PROPERTY "COTIRE_PREFIX_HEADER_IGNORE_PATH" INHERITED
  3707. BRIEF_DOCS "Ignore headers from these directories when generating the prefix header."
  3708. FULL_DOCS
  3709. "The property can be set to a list of directories."
  3710. "If a header file is found in one of these directories or sub-directories, it will be excluded from the generated prefix header."
  3711. "Inherited from directory."
  3712. "If not set, this property is initialized to \${CMAKE_SOURCE_DIR};\${CMAKE_BINARY_DIR}."
  3713. )
  3714. define_property(
  3715. TARGET PROPERTY "COTIRE_PREFIX_HEADER_INCLUDE_PATH" INHERITED
  3716. BRIEF_DOCS "Honor headers from these directories when generating the prefix header."
  3717. FULL_DOCS
  3718. "The property can be set to a list of directories."
  3719. "If a header file is found in one of these directories or sub-directories, it will be included in the generated prefix header."
  3720. "If a header file is both selected by COTIRE_PREFIX_HEADER_IGNORE_PATH and COTIRE_PREFIX_HEADER_INCLUDE_PATH,"
  3721. "the option which yields the closer relative path match wins."
  3722. "Inherited from directory."
  3723. "If not set, this property is initialized to the empty list."
  3724. )
  3725. define_property(
  3726. TARGET PROPERTY "COTIRE_PREFIX_HEADER_INCLUDE_PRIORITY_PATH" INHERITED
  3727. BRIEF_DOCS "Header paths matching one of these directories are put at the top of prefix header."
  3728. FULL_DOCS
  3729. "The property can be set to a list of directories."
  3730. "Header file paths matching one of these directories will be inserted at the beginning of the generated prefix header."
  3731. "Header files are sorted according to the order of the directories in the property."
  3732. "If not set, this property is initialized to the empty list."
  3733. )
  3734. define_property(
  3735. TARGET PROPERTY "COTIRE_UNITY_SOURCE_PRE_UNDEFS" INHERITED
  3736. BRIEF_DOCS "Preprocessor undefs to place in the generated unity source file before the inclusion of each target source file."
  3737. FULL_DOCS
  3738. "This may be set to a semicolon-separated list of preprocessor symbols."
  3739. "cotire will add corresponding #undef directives to the generated unit source file before each target source file."
  3740. "Inherited from directory."
  3741. "Defaults to empty string."
  3742. )
  3743. define_property(
  3744. TARGET PROPERTY "COTIRE_UNITY_SOURCE_POST_UNDEFS" INHERITED
  3745. BRIEF_DOCS "Preprocessor undefs to place in the generated unity source file after the inclusion of each target source file."
  3746. FULL_DOCS
  3747. "This may be set to a semicolon-separated list of preprocessor symbols."
  3748. "cotire will add corresponding #undef directives to the generated unit source file after each target source file."
  3749. "Inherited from directory."
  3750. "Defaults to empty string."
  3751. )
  3752. define_property(
  3753. TARGET PROPERTY "COTIRE_UNITY_SOURCE_MAXIMUM_NUMBER_OF_INCLUDES" INHERITED
  3754. BRIEF_DOCS "Maximum number of source files to include in a single unity source file."
  3755. FULL_DOCS
  3756. "This may be set to an integer > 0."
  3757. "If a target contains more than that number of source files, cotire will create multiple unity build files for it."
  3758. "If not set, cotire will only create a single unity source file."
  3759. "Inherited from directory."
  3760. "Defaults to empty."
  3761. )
  3762. define_property(
  3763. TARGET PROPERTY "COTIRE_<LANG>_UNITY_SOURCE_INIT"
  3764. BRIEF_DOCS "User provided unity source file to be used instead of the automatically generated one."
  3765. FULL_DOCS
  3766. "If set, cotire will only add the given file(s) to the generated unity source file."
  3767. "If not set, cotire will add all the target source files to the generated unity source file."
  3768. "The property can be set to a user provided unity source file."
  3769. "Defaults to empty."
  3770. )
  3771. define_property(
  3772. TARGET PROPERTY "COTIRE_<LANG>_PREFIX_HEADER_INIT"
  3773. BRIEF_DOCS "User provided prefix header file to be used instead of the automatically generated one."
  3774. FULL_DOCS
  3775. "If set, cotire will add the given header file(s) to the generated prefix header file."
  3776. "If not set, cotire will generate a prefix header by tracking the header files included by the unity source file."
  3777. "The property can be set to a user provided prefix header file (e.g., stdafx.h)."
  3778. "Defaults to empty."
  3779. )
  3780. define_property(
  3781. TARGET PROPERTY "COTIRE_UNITY_LINK_LIBRARIES_INIT" INHERITED
  3782. BRIEF_DOCS "Define strategy for setting up unity target's link libraries."
  3783. FULL_DOCS
  3784. "If this property is empty or set to NONE, the generated unity target's link libraries have to be set up manually."
  3785. "If this property is set to COPY, the unity target's link libraries will be copied from this target."
  3786. "If this property is set to COPY_UNITY, the unity target's link libraries will be copied from this target with considering existing unity targets."
  3787. "Inherited from directory."
  3788. "Defaults to empty."
  3789. )
  3790. define_property(
  3791. TARGET PROPERTY "COTIRE_<LANG>_UNITY_SOURCE"
  3792. BRIEF_DOCS "Read-only property. The generated <LANG> unity source file(s)."
  3793. FULL_DOCS
  3794. "cotire sets this property to the path of the generated <LANG> single computation unit source file for the target."
  3795. "Defaults to empty string."
  3796. )
  3797. define_property(
  3798. TARGET PROPERTY "COTIRE_<LANG>_PREFIX_HEADER"
  3799. BRIEF_DOCS "Read-only property. The generated <LANG> prefix header file."
  3800. FULL_DOCS
  3801. "cotire sets this property to the full path of the generated <LANG> language prefix header for the target."
  3802. "Defaults to empty string."
  3803. )
  3804. define_property(
  3805. TARGET PROPERTY "COTIRE_<LANG>_PRECOMPILED_HEADER"
  3806. BRIEF_DOCS "Read-only property. The generated <LANG> precompiled header file."
  3807. FULL_DOCS
  3808. "cotire sets this property to the full path of the generated <LANG> language precompiled header binary for the target."
  3809. "Defaults to empty string."
  3810. )
  3811. define_property(
  3812. TARGET PROPERTY "COTIRE_UNITY_TARGET_NAME"
  3813. BRIEF_DOCS "The name of the generated unity build target corresponding to this target."
  3814. FULL_DOCS
  3815. "This property can be set to the desired name of the unity target that will be created by cotire."
  3816. "If not set, the unity target name will be set to this target's name with the suffix _unity appended."
  3817. "After this target has been processed by cotire, the property is set to the actual name of the generated unity target."
  3818. "Defaults to empty string."
  3819. )
  3820. # define cotire source properties
  3821. define_property(
  3822. SOURCE PROPERTY "COTIRE_EXCLUDED"
  3823. BRIEF_DOCS "Do not modify source file's build command."
  3824. FULL_DOCS
  3825. "If this property is set to TRUE, the source file's build command will not be modified to make use of the precompiled header."
  3826. "The source file will also be excluded from the generated unity source file."
  3827. "Source files that have their COMPILE_FLAGS property set will be excluded by default."
  3828. "Defaults to FALSE."
  3829. )
  3830. define_property(
  3831. SOURCE PROPERTY "COTIRE_DEPENDENCY"
  3832. BRIEF_DOCS "Add this source file to dependencies of the automatically generated prefix header file."
  3833. FULL_DOCS
  3834. "If this property is set to TRUE, the source file is added to dependencies of the generated prefix header file."
  3835. "If the file is modified, cotire will re-generate the prefix header source upon build."
  3836. "Defaults to FALSE."
  3837. )
  3838. define_property(
  3839. SOURCE PROPERTY "COTIRE_UNITY_SOURCE_PRE_UNDEFS"
  3840. BRIEF_DOCS "Preprocessor undefs to place in the generated unity source file before the inclusion of this source file."
  3841. FULL_DOCS
  3842. "This may be set to a semicolon-separated list of preprocessor symbols."
  3843. "cotire will add corresponding #undef directives to the generated unit source file before this file is included."
  3844. "Defaults to empty string."
  3845. )
  3846. define_property(
  3847. SOURCE PROPERTY "COTIRE_UNITY_SOURCE_POST_UNDEFS"
  3848. BRIEF_DOCS "Preprocessor undefs to place in the generated unity source file after the inclusion of this source file."
  3849. FULL_DOCS
  3850. "This may be set to a semicolon-separated list of preprocessor symbols."
  3851. "cotire will add corresponding #undef directives to the generated unit source file after this file is included."
  3852. "Defaults to empty string."
  3853. )
  3854. define_property(
  3855. SOURCE PROPERTY "COTIRE_START_NEW_UNITY_SOURCE"
  3856. BRIEF_DOCS "Start a new unity source file which includes this source file as the first one."
  3857. FULL_DOCS
  3858. "If this property is set to TRUE, cotire will complete the current unity file and start a new one."
  3859. "The new unity source file will include this source file as the first one."
  3860. "This property essentially works as a separator for unity source files."
  3861. "Defaults to FALSE."
  3862. )
  3863. define_property(
  3864. SOURCE PROPERTY "COTIRE_TARGET"
  3865. BRIEF_DOCS "Read-only property. Mark this source file as cotired for the given target."
  3866. FULL_DOCS
  3867. "cotire sets this property to the name of target, that the source file's build command has been altered for."
  3868. "Defaults to empty string."
  3869. )
  3870. message (STATUS "cotire ${COTIRE_CMAKE_MODULE_VERSION} loaded.")
  3871. endif()