test_gcc.lua 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032
  1. --
  2. -- tests/test_gcc.lua
  3. -- Automated test suite for the GCC toolset interface.
  4. -- Copyright (c) 2009-2013 Jason Perkins and the Premake project
  5. --
  6. local p = premake
  7. local suite = test.declare("tools_gcc")
  8. local gcc = p.tools.gcc
  9. local project = p.project
  10. --
  11. -- Setup/teardown
  12. --
  13. local wks, prj, cfg
  14. function suite.setup()
  15. wks, prj = test.createWorkspace()
  16. system "Linux"
  17. end
  18. local function prepare()
  19. cfg = test.getconfig(prj, "Debug")
  20. end
  21. --
  22. -- Check the selection of tools based on the target system.
  23. --
  24. function suite.tools_onDefaults()
  25. prepare()
  26. test.isnil(gcc.gettoolname(cfg, "cc"))
  27. test.isnil(gcc.gettoolname(cfg, "cxx"))
  28. test.isnil(gcc.gettoolname(cfg, "ar"))
  29. test.isequal("windres", gcc.gettoolname(cfg, "rc"))
  30. end
  31. function suite.tools_withPrefix()
  32. gccprefix "test-prefix-"
  33. prepare()
  34. test.isequal("test-prefix-gcc", gcc.gettoolname(cfg, "cc"))
  35. test.isequal("test-prefix-g++", gcc.gettoolname(cfg, "cxx"))
  36. test.isequal("test-prefix-ar", gcc.gettoolname(cfg, "ar"))
  37. test.isequal("test-prefix-windres", gcc.gettoolname(cfg, "rc"))
  38. end
  39. --
  40. -- By default, the -MMD -MP are used to generate dependencies.
  41. --
  42. function suite.cppflags_defaultWithMMD()
  43. prepare()
  44. test.contains({"-MMD", "-MP"}, gcc.getcppflags(cfg))
  45. end
  46. --
  47. -- Haiku OS doesn't support the -MP flag yet (that's weird, isn't it?)
  48. --
  49. function suite.cppflagsExcludeMP_onHaiku()
  50. system "Haiku"
  51. prepare()
  52. test.excludes({ "-MP" }, gcc.getcppflags(cfg))
  53. end
  54. --
  55. -- Check the translation of CFLAGS.
  56. --
  57. function suite.cflags_onNoWarnings()
  58. warnings "Off"
  59. prepare()
  60. test.contains({ "-w" }, gcc.getcflags(cfg))
  61. end
  62. function suite.cflags_onHighWarnings()
  63. warnings "High"
  64. prepare()
  65. test.contains({ "-Wall" }, gcc.getcflags(cfg))
  66. end
  67. function suite.cflags_onExtraWarnings()
  68. warnings "Extra"
  69. prepare()
  70. test.contains({ "-Wall", "-Wextra" }, gcc.getcflags(cfg))
  71. end
  72. function suite.cflags_onEverythingWarnings()
  73. warnings "Everything"
  74. prepare()
  75. test.contains({ "-Weverything" }, gcc.getcflags(cfg))
  76. end
  77. function suite.cflags_onFatalWarnings()
  78. flags { "FatalWarnings" }
  79. prepare()
  80. test.contains({ "-Werror" }, gcc.getcflags(cfg))
  81. end
  82. function suite.cflags_onSpecificWarnings()
  83. enablewarnings { "enable" }
  84. disablewarnings { "disable" }
  85. fatalwarnings { "fatal" }
  86. prepare()
  87. test.contains({ "-Wenable", "-Wno-disable", "-Werror=fatal" }, gcc.getcflags(cfg))
  88. end
  89. function suite.cflags_onFloastFast()
  90. floatingpoint "Fast"
  91. prepare()
  92. test.contains({ "-ffast-math" }, gcc.getcflags(cfg))
  93. end
  94. function suite.cflags_onFloastStrict()
  95. floatingpoint "Strict"
  96. prepare()
  97. test.contains({ "-ffloat-store" }, gcc.getcflags(cfg))
  98. end
  99. function suite.cflags_onSSE()
  100. vectorextensions "SSE"
  101. prepare()
  102. test.contains({ "-msse" }, gcc.getcflags(cfg))
  103. end
  104. function suite.cflags_onSSE2()
  105. vectorextensions "SSE2"
  106. prepare()
  107. test.contains({ "-msse2" }, gcc.getcflags(cfg))
  108. end
  109. function suite.cflags_onSSE4_2()
  110. vectorextensions "SSE4.2"
  111. prepare()
  112. test.contains({ "-msse4.2" }, gcc.getcflags(cfg))
  113. end
  114. function suite.cflags_onAVX()
  115. vectorextensions "AVX"
  116. prepare()
  117. test.contains({ "-mavx" }, gcc.getcflags(cfg))
  118. end
  119. function suite.cflags_onAVX2()
  120. vectorextensions "AVX2"
  121. prepare()
  122. test.contains({ "-mavx2" }, gcc.getcflags(cfg))
  123. end
  124. function suite.cflags_onMOVBE()
  125. isaextensions "MOVBE"
  126. prepare()
  127. test.contains({ "-mmovbe" }, gcc.getcflags(cfg))
  128. end
  129. function suite.cflags_onPOPCNT()
  130. isaextensions "POPCNT"
  131. prepare()
  132. test.contains({ "-mpopcnt" }, gcc.getcflags(cfg))
  133. end
  134. function suite.cflags_onPCLMUL()
  135. isaextensions "PCLMUL"
  136. prepare()
  137. test.contains({ "-mpclmul" }, gcc.getcflags(cfg))
  138. end
  139. function suite.cflags_onLZCNT()
  140. isaextensions "LZCNT"
  141. prepare()
  142. test.contains({ "-mlzcnt" }, gcc.getcflags(cfg))
  143. end
  144. function suite.cflags_onBMI()
  145. isaextensions "BMI"
  146. prepare()
  147. test.contains({ "-mbmi" }, gcc.getcflags(cfg))
  148. end
  149. function suite.cflags_onBMI2()
  150. isaextensions "BMI2"
  151. prepare()
  152. test.contains({ "-mbmi2" }, gcc.getcflags(cfg))
  153. end
  154. function suite.cflags_onF16C()
  155. isaextensions "F16C"
  156. prepare()
  157. test.contains({ "-mf16c" }, gcc.getcflags(cfg))
  158. end
  159. function suite.cflags_onAES()
  160. isaextensions "AES"
  161. prepare()
  162. test.contains({ "-maes" }, gcc.getcflags(cfg))
  163. end
  164. function suite.cflags_onFMA()
  165. isaextensions "FMA"
  166. prepare()
  167. test.contains({ "-mfma" }, gcc.getcflags(cfg))
  168. end
  169. function suite.cflags_onFMA4()
  170. isaextensions "FMA4"
  171. prepare()
  172. test.contains({ "-mfma4" }, gcc.getcflags(cfg))
  173. end
  174. function suite.cflags_onRDRND()
  175. isaextensions "RDRND"
  176. prepare()
  177. test.contains({ "-mrdrnd" }, gcc.getcflags(cfg))
  178. end
  179. function suite.cflags_onMultipleISA()
  180. isaextensions {
  181. "RDRND",
  182. "FMA4"
  183. }
  184. prepare()
  185. test.contains({ "-mrdrnd", "-mfma4" }, gcc.getcflags(cfg))
  186. end
  187. function suite.cflags_onAdditionalISA()
  188. isaextensions "RDRND"
  189. isaextensions "FMA4"
  190. prepare()
  191. test.contains({ "-mrdrnd", "-mfma4" }, gcc.getcflags(cfg))
  192. end
  193. --
  194. -- Check the defines and undefines.
  195. --
  196. function suite.defines()
  197. defines "DEF"
  198. prepare()
  199. test.contains({ "-DDEF" }, gcc.getdefines(cfg.defines))
  200. end
  201. function suite.undefines()
  202. undefines "UNDEF"
  203. prepare()
  204. test.contains({ "-UUNDEF" }, gcc.getundefines(cfg.undefines))
  205. end
  206. --
  207. -- Check the optimization flags.
  208. --
  209. function suite.cflags_onNoOptimize()
  210. optimize "Off"
  211. prepare()
  212. test.contains({ "-O0" }, gcc.getcflags(cfg))
  213. end
  214. function suite.cflags_onOptimize()
  215. optimize "On"
  216. prepare()
  217. test.contains({ "-O2" }, gcc.getcflags(cfg))
  218. end
  219. function suite.cflags_onOptimizeSize()
  220. optimize "Size"
  221. prepare()
  222. test.contains({ "-Os" }, gcc.getcflags(cfg))
  223. end
  224. function suite.cflags_onOptimizeSpeed()
  225. optimize "Speed"
  226. prepare()
  227. test.contains({ "-O3" }, gcc.getcflags(cfg))
  228. end
  229. function suite.cflags_onOptimizeFull()
  230. optimize "Full"
  231. prepare()
  232. test.contains({ "-O3" }, gcc.getcflags(cfg))
  233. end
  234. function suite.cflags_onOptimizeDebug()
  235. optimize "Debug"
  236. prepare()
  237. test.contains({ "-Og" }, gcc.getcflags(cfg))
  238. end
  239. --
  240. -- Check the translation of symbols.
  241. --
  242. function suite.cflags_onDefaultSymbols()
  243. prepare()
  244. test.excludes({ "-g" }, gcc.getcflags(cfg))
  245. end
  246. function suite.cflags_onNoSymbols()
  247. symbols "Off"
  248. prepare()
  249. test.excludes({ "-g" }, gcc.getcflags(cfg))
  250. end
  251. function suite.cflags_onSymbols()
  252. symbols "On"
  253. prepare()
  254. test.contains({ "-g" }, gcc.getcflags(cfg))
  255. end
  256. --
  257. -- Check the translation of CXXFLAGS.
  258. --
  259. function suite.cflags_onNoExceptions()
  260. exceptionhandling "Off"
  261. prepare()
  262. test.contains({ "-fno-exceptions" }, gcc.getcxxflags(cfg))
  263. end
  264. function suite.cflags_onNoBufferSecurityCheck()
  265. flags { "NoBufferSecurityCheck" }
  266. prepare()
  267. test.contains({ "-fno-stack-protector" }, gcc.getcxxflags(cfg))
  268. end
  269. --
  270. -- Check the basic translation of LDFLAGS for a Posix system.
  271. --
  272. function suite.ldflags_onNoSymbols()
  273. prepare()
  274. test.contains({ "-s" }, gcc.getldflags(cfg))
  275. end
  276. function suite.ldflags_onSymbols()
  277. symbols "On"
  278. prepare()
  279. test.excludes("-s", gcc.getldflags(cfg))
  280. end
  281. function suite.ldflags_onSharedLib()
  282. kind "SharedLib"
  283. prepare()
  284. test.contains({ "-shared" }, gcc.getldflags(cfg))
  285. end
  286. --
  287. -- Check Mac OS X variants on LDFLAGS.
  288. --
  289. function suite.ldflags_onMacOSXBundle()
  290. system "MacOSX"
  291. kind "SharedLib"
  292. sharedlibtype "OSXBundle"
  293. prepare()
  294. test.contains({ "-Wl,-x", "-bundle" }, gcc.getldflags(cfg))
  295. end
  296. function suite.ldflags_onMacOSXXCTest()
  297. system "MacOSX"
  298. kind "SharedLib"
  299. sharedlibtype "XCTest"
  300. prepare()
  301. test.contains({ "-Wl,-x", "-bundle" }, gcc.getldflags(cfg))
  302. end
  303. function suite.ldflags_onMacOSXFramework()
  304. system "MacOSX"
  305. kind "SharedLib"
  306. sharedlibtype "OSXFramework"
  307. prepare()
  308. test.contains({ "-Wl,-x", "-framework" }, gcc.getldflags(cfg))
  309. end
  310. function suite.ldflags_onMacOSXNoSymbols()
  311. system "MacOSX"
  312. prepare()
  313. test.contains({ "-Wl,-x" }, gcc.getldflags(cfg))
  314. end
  315. function suite.ldflags_onMacOSXSharedLib()
  316. system "MacOSX"
  317. kind "SharedLib"
  318. prepare()
  319. test.contains({ "-dynamiclib" }, gcc.getldflags(cfg))
  320. end
  321. --
  322. -- Check Mac OS X deployment target flags
  323. --
  324. function suite.cflags_macosx_systemversion()
  325. system "MacOSX"
  326. systemversion "10.9"
  327. prepare()
  328. test.contains({ "-mmacosx-version-min=10.9" }, gcc.getcflags(cfg))
  329. end
  330. function suite.cxxflags_macosx_systemversion()
  331. system "MacOSX"
  332. systemversion "10.9:10.15"
  333. prepare()
  334. test.contains({ "-mmacosx-version-min=10.9" }, gcc.getcxxflags(cfg))
  335. end
  336. function suite.cxxflags_macosx_systemversion_unspecified()
  337. system "MacOSX"
  338. prepare()
  339. test.excludes({ "-mmacosx-version-min=10.9" }, gcc.getcxxflags(cfg))
  340. end
  341. --
  342. -- Check Windows variants on LDFLAGS.
  343. --
  344. function suite.ldflags_onWindowsharedLib()
  345. system "Windows"
  346. kind "SharedLib"
  347. prepare()
  348. test.contains({ "-shared", '-Wl,--out-implib="bin/Debug/MyProject.lib"' }, gcc.getldflags(cfg))
  349. end
  350. function suite.ldflags_onWindowsApp()
  351. system "Windows"
  352. kind "WindowedApp"
  353. prepare()
  354. test.contains({ "-mwindows" }, gcc.getldflags(cfg))
  355. end
  356. --
  357. -- Make sure system or architecture flags are added properly.
  358. --
  359. function suite.cflags_onX86()
  360. architecture "x86"
  361. prepare()
  362. test.contains({ "-m32" }, gcc.getcflags(cfg))
  363. end
  364. function suite.ldflags_onX86()
  365. architecture "x86"
  366. prepare()
  367. test.contains({ "-m32" }, gcc.getldflags(cfg))
  368. end
  369. function suite.cflags_onX86_64()
  370. architecture "x86_64"
  371. prepare()
  372. test.contains({ "-m64" }, gcc.getcflags(cfg))
  373. end
  374. function suite.ldflags_onX86_64()
  375. architecture "x86_64"
  376. prepare()
  377. test.contains({ "-m64" }, gcc.getldflags(cfg))
  378. end
  379. --
  380. -- Non-Windows shared libraries should marked as position independent.
  381. --
  382. function suite.cflags_onWindowsSharedLib()
  383. system "MacOSX"
  384. kind "SharedLib"
  385. prepare()
  386. test.contains({ "-fPIC" }, gcc.getcflags(cfg))
  387. end
  388. --
  389. -- Check the formatting of linked system libraries.
  390. --
  391. function suite.links_onSystemLibs()
  392. links { "fs_stub", "net_stub" }
  393. prepare()
  394. test.contains({ "-lfs_stub", "-lnet_stub" }, gcc.getlinks(cfg))
  395. end
  396. function suite.links_onFramework()
  397. links { "Cocoa.framework" }
  398. prepare()
  399. test.contains({ "-framework Cocoa" }, {table.implode (gcc.getlinks(cfg), '', '', ' ')})
  400. end
  401. function suite.links_onSystemLibs_onWindows()
  402. system "windows"
  403. links { "ole32" }
  404. prepare()
  405. test.contains({ "-lole32" }, gcc.getlinks(cfg))
  406. end
  407. --
  408. -- When linking to a static sibling library, the relative path to the library
  409. -- should be used instead of the "-l" flag. This prevents linking against a
  410. -- shared library of the same name, should one be present.
  411. --
  412. function suite.links_onStaticSiblingLibrary()
  413. links { "MyProject2" }
  414. test.createproject(wks)
  415. system "Linux"
  416. kind "StaticLib"
  417. targetdir "lib"
  418. prepare()
  419. test.isequal({ "lib/libMyProject2.a" }, gcc.getlinks(cfg))
  420. end
  421. --
  422. -- Use the -lname format when linking to sibling shared libraries.
  423. --
  424. function suite.links_onSharedSiblingLibrary()
  425. links { "MyProject2" }
  426. test.createproject(wks)
  427. system "Linux"
  428. kind "SharedLib"
  429. targetdir "lib"
  430. prepare()
  431. test.isequal({ "lib/libMyProject2.so" }, gcc.getlinks(cfg))
  432. end
  433. --
  434. -- Test that sibling and external links are grouped when required
  435. --
  436. function suite.linkgroups_onSiblingAndExternalLibrary()
  437. links { "MyProject2", "ExternalProj" }
  438. linkgroups "On"
  439. test.createproject(wks)
  440. system "Linux"
  441. kind "StaticLib"
  442. targetdir "lib"
  443. prepare()
  444. test.isequal({ "-Wl,--start-group", "lib/libMyProject2.a", "-lExternalProj", "-Wl,--end-group" }, gcc.getlinks(cfg))
  445. end
  446. --
  447. -- When linking object files, leave off the "-l".
  448. --
  449. function suite.links_onObjectFile()
  450. links { "generated.o" }
  451. prepare()
  452. test.isequal({ "generated.o" }, gcc.getlinks(cfg))
  453. end
  454. --
  455. -- If the object file is referenced with a path, it should be
  456. -- made relative to the project.
  457. --
  458. function suite.links_onObjectFileOutsideProject()
  459. location "MyProject"
  460. links { "obj/Debug/generated.o" }
  461. prepare()
  462. test.isequal({ "../obj/Debug/generated.o" }, gcc.getlinks(cfg))
  463. end
  464. --
  465. -- Make sure shell variables are kept intact for object file paths.
  466. --
  467. function suite.links_onObjectFileWithShellVar()
  468. location "MyProject"
  469. links { "$(IntDir)/generated.o" }
  470. prepare()
  471. test.isequal({ "$(IntDir)/generated.o" }, gcc.getlinks(cfg))
  472. end
  473. --
  474. -- Include directories should be made project relative.
  475. --
  476. function suite.includeDirsAreRelative()
  477. includedirs { "../include", "src/include" }
  478. prepare()
  479. test.isequal({ '-I../include', '-Isrc/include' }, gcc.getincludedirs(cfg, cfg.includedirs))
  480. end
  481. --
  482. -- Check handling of forced includes.
  483. --
  484. function suite.forcedIncludeFiles()
  485. forceincludes { "stdafx.h", "include/sys.h" }
  486. prepare()
  487. test.isequal({'-include stdafx.h', '-include include/sys.h'}, gcc.getforceincludes(cfg))
  488. end
  489. --
  490. -- Include directories containing spaces (or which could contain spaces)
  491. -- should be wrapped in quotes.
  492. --
  493. function suite.includeDirs_onSpaces()
  494. includedirs { "include files" }
  495. prepare()
  496. test.isequal({ '-I"include files"' }, gcc.getincludedirs(cfg, cfg.includedirs))
  497. end
  498. function suite.includeDirs_onEnvVars()
  499. includedirs { "$(IntDir)/includes" }
  500. prepare()
  501. test.isequal({ '-I"$(IntDir)/includes"' }, gcc.getincludedirs(cfg, cfg.includedirs))
  502. end
  503. --
  504. -- Check handling of strict aliasing flags.
  505. --
  506. function suite.cflags_onNoStrictAliasing()
  507. strictaliasing "Off"
  508. prepare()
  509. test.contains("-fno-strict-aliasing", gcc.getcflags(cfg))
  510. end
  511. function suite.cflags_onLevel1Aliasing()
  512. strictaliasing "Level1"
  513. prepare()
  514. test.contains({ "-fstrict-aliasing", "-Wstrict-aliasing=1" }, gcc.getcflags(cfg))
  515. end
  516. function suite.cflags_onLevel2Aliasing()
  517. strictaliasing "Level2"
  518. prepare()
  519. test.contains({ "-fstrict-aliasing", "-Wstrict-aliasing=2" }, gcc.getcflags(cfg))
  520. end
  521. function suite.cflags_onLevel3Aliasing()
  522. strictaliasing "Level3"
  523. prepare()
  524. test.contains({ "-fstrict-aliasing", "-Wstrict-aliasing=3" }, gcc.getcflags(cfg))
  525. end
  526. --
  527. -- Check handling of system search paths.
  528. --
  529. function suite.includeDirs_onSysIncludeDirs()
  530. sysincludedirs { "/usr/local/include" }
  531. prepare()
  532. test.contains("-isystem /usr/local/include", gcc.getincludedirs(cfg, cfg.includedirs, cfg.sysincludedirs))
  533. end
  534. function suite.libDirs_onSysLibDirs()
  535. syslibdirs { "/usr/local/lib" }
  536. prepare()
  537. test.contains("-L/usr/local/lib", gcc.getLibraryDirectories(cfg))
  538. end
  539. --
  540. -- Check handling of Apple frameworks search paths
  541. --
  542. function suite.includeDirs_notDarwin_onFrameworkDirs()
  543. system "Linux"
  544. frameworkdirs { "/Library/Frameworks" }
  545. prepare()
  546. test.excludes("-F/Library/Frameworks", gcc.getincludedirs(cfg, {}, {}, cfg.frameworkdirs))
  547. end
  548. function suite.libDirs_notDarwin_onFrameworkDirs()
  549. system "Windows"
  550. frameworkdirs { "/Library/Frameworks" }
  551. prepare()
  552. test.excludes("-F/Library/Frameworks", gcc.getLibraryDirectories(cfg))
  553. end
  554. function suite.includeDirs_macosx_onFrameworkDirs()
  555. system "MacOSX"
  556. location "subdir"
  557. frameworkdirs {
  558. "/Library/Frameworks",
  559. "subdir/Relative/Frameworks"
  560. }
  561. prepare()
  562. test.contains("-F/Library/Frameworks", gcc.getincludedirs(cfg, {}, {}, cfg.frameworkdirs))
  563. test.contains("-FRelative/Frameworks", gcc.getincludedirs(cfg, {}, {}, cfg.frameworkdirs))
  564. end
  565. function suite.libDirs_macosx_onFrameworkDirs()
  566. system "MacOSX"
  567. location "subdir"
  568. frameworkdirs {
  569. "/Library/Frameworks",
  570. "subdir/Relative/Frameworks"
  571. }
  572. prepare()
  573. test.contains("-F/Library/Frameworks", gcc.getLibraryDirectories(cfg))
  574. test.contains("-FRelative/Frameworks", gcc.getLibraryDirectories(cfg))
  575. end
  576. function suite.includeDirs_ios_onFrameworkDirs()
  577. system "iOS"
  578. frameworkdirs { "/Library/Frameworks" }
  579. prepare()
  580. test.contains("-F/Library/Frameworks", gcc.getincludedirs(cfg, {}, {}, cfg.frameworkdirs))
  581. end
  582. --
  583. -- Check handling of link time optimization flag.
  584. --
  585. function suite.cflags_onLinkTimeOptimization()
  586. flags "LinkTimeOptimization"
  587. prepare()
  588. test.contains("-flto", gcc.getcflags(cfg))
  589. end
  590. function suite.ldflags_onLinkTimeOptimization()
  591. flags "LinkTimeOptimization"
  592. prepare()
  593. test.contains("-flto", gcc.getldflags(cfg))
  594. end
  595. --
  596. -- Check link mode preference for system libraries.
  597. --
  598. function suite.linksModePreference_onAllStatic()
  599. links { "fs_stub:static", "net_stub:static" }
  600. prepare()
  601. test.contains({ "-Wl,-Bstatic", "-lfs_stub", "-Wl,-Bdynamic", "-lnet_stub"}, gcc.getlinks(cfg))
  602. end
  603. function suite.linksModePreference_onStaticAndShared()
  604. links { "fs_stub:static", "net_stub" }
  605. prepare()
  606. test.contains({ "-Wl,-Bstatic", "-lfs_stub", "-Wl,-Bdynamic", "-lnet_stub"}, gcc.getlinks(cfg))
  607. end
  608. function suite.linksModePreference_onAllShared()
  609. links { "fs_stub:shared", "net_stub:shared" }
  610. prepare()
  611. test.excludes({ "-Wl,-Bstatic" }, gcc.getlinks(cfg))
  612. end
  613. --
  614. -- Test language flags are added properly.
  615. --
  616. function suite.cflags_onCDefault()
  617. cdialect "Default"
  618. prepare()
  619. test.contains({ }, gcc.getcflags(cfg))
  620. test.contains({ }, gcc.getcxxflags(cfg))
  621. end
  622. function suite.cflags_onC89()
  623. cdialect "C89"
  624. prepare()
  625. test.contains({ "-std=c89" }, gcc.getcflags(cfg))
  626. test.contains({ }, gcc.getcxxflags(cfg))
  627. end
  628. function suite.cflags_onC90()
  629. cdialect "C90"
  630. prepare()
  631. test.contains({ "-std=c90" }, gcc.getcflags(cfg))
  632. test.contains({ }, gcc.getcxxflags(cfg))
  633. end
  634. function suite.cflags_onC99()
  635. cdialect "C99"
  636. prepare()
  637. test.contains({ "-std=c99" }, gcc.getcflags(cfg))
  638. test.contains({ }, gcc.getcxxflags(cfg))
  639. end
  640. function suite.cflags_onC11()
  641. cdialect "C11"
  642. prepare()
  643. test.contains({ "-std=c11" }, gcc.getcflags(cfg))
  644. test.contains({ }, gcc.getcxxflags(cfg))
  645. end
  646. function suite.cflags_ongnu89()
  647. cdialect "gnu89"
  648. prepare()
  649. test.contains({ "-std=gnu89" }, gcc.getcflags(cfg))
  650. test.contains({ }, gcc.getcxxflags(cfg))
  651. end
  652. function suite.cflags_ongnu90()
  653. cdialect "gnu90"
  654. prepare()
  655. test.contains({ "-std=gnu90" }, gcc.getcflags(cfg))
  656. test.contains({ }, gcc.getcxxflags(cfg))
  657. end
  658. function suite.cflags_ongnu99()
  659. cdialect "gnu99"
  660. prepare()
  661. test.contains({ "-std=gnu99" }, gcc.getcflags(cfg))
  662. test.contains({ }, gcc.getcxxflags(cfg))
  663. end
  664. function suite.cflags_ongnu11()
  665. cdialect "gnu11"
  666. prepare()
  667. test.contains({ "-std=gnu11" }, gcc.getcflags(cfg))
  668. test.contains({ }, gcc.getcxxflags(cfg))
  669. end
  670. function suite.cxxflags_onCppDefault()
  671. cppdialect "Default"
  672. prepare()
  673. test.contains({ }, gcc.getcxxflags(cfg))
  674. test.contains({ }, gcc.getcflags(cfg))
  675. end
  676. function suite.cxxflags_onCpp98()
  677. cppdialect "C++98"
  678. prepare()
  679. test.contains({ "-std=c++98" }, gcc.getcxxflags(cfg))
  680. test.contains({ }, gcc.getcflags(cfg))
  681. end
  682. function suite.cxxflags_onCpp11()
  683. cppdialect "C++11"
  684. prepare()
  685. test.contains({ "-std=c++11" }, gcc.getcxxflags(cfg))
  686. test.contains({ }, gcc.getcflags(cfg))
  687. end
  688. function suite.cxxflags_onCpp14()
  689. cppdialect "C++14"
  690. prepare()
  691. test.contains({ "-std=c++14" }, gcc.getcxxflags(cfg))
  692. test.contains({ }, gcc.getcflags(cfg))
  693. end
  694. function suite.cxxflags_onCpp17()
  695. cppdialect "C++17"
  696. prepare()
  697. test.contains({ "-std=c++17" }, gcc.getcxxflags(cfg))
  698. test.contains({ }, gcc.getcflags(cfg))
  699. end
  700. function suite.cxxflags_onCpp2a()
  701. cppdialect "C++2a"
  702. prepare()
  703. test.contains({ "-std=c++2a" }, gcc.getcxxflags(cfg))
  704. test.contains({ }, gcc.getcflags(cfg))
  705. end
  706. function suite.cxxflags_onCpp20()
  707. cppdialect "C++20"
  708. prepare()
  709. test.contains({ "-std=c++20" }, gcc.getcxxflags(cfg))
  710. test.contains({ }, gcc.getcflags(cfg))
  711. end
  712. function suite.cxxflags_onCppLatest()
  713. cppdialect "C++latest"
  714. prepare()
  715. test.contains({ "-std=c++20" }, gcc.getcxxflags(cfg))
  716. test.contains({ }, gcc.getcflags(cfg))
  717. end
  718. function suite.cxxflags_onCppGnu98()
  719. cppdialect "gnu++98"
  720. prepare()
  721. test.contains({ "-std=gnu++98" }, gcc.getcxxflags(cfg))
  722. test.contains({ }, gcc.getcflags(cfg))
  723. end
  724. function suite.cxxflags_onCppGnu11()
  725. cppdialect "gnu++11"
  726. prepare()
  727. test.contains({ "-std=gnu++11" }, gcc.getcxxflags(cfg))
  728. test.contains({ }, gcc.getcflags(cfg))
  729. end
  730. function suite.cxxflags_onCppGnu14()
  731. cppdialect "gnu++14"
  732. prepare()
  733. test.contains({ "-std=gnu++14" }, gcc.getcxxflags(cfg))
  734. test.contains({ }, gcc.getcflags(cfg))
  735. end
  736. function suite.cxxflags_onCppGnu17()
  737. cppdialect "gnu++17"
  738. prepare()
  739. test.contains({ "-std=gnu++17" }, gcc.getcxxflags(cfg))
  740. test.contains({ }, gcc.getcflags(cfg))
  741. end
  742. function suite.cxxflags_onCppGnu2a()
  743. cppdialect "gnu++2a"
  744. prepare()
  745. test.contains({ "-std=gnu++2a" }, gcc.getcxxflags(cfg))
  746. test.contains({ }, gcc.getcflags(cfg))
  747. end
  748. function suite.cxxflags_onCppGnu20()
  749. cppdialect "gnu++20"
  750. prepare()
  751. test.contains({ "-std=gnu++20" }, gcc.getcxxflags(cfg))
  752. test.contains({ }, gcc.getcflags(cfg))
  753. end
  754. --
  755. -- Test unsigned-char flags.
  756. --
  757. function suite.sharedflags_onUnsignedChar()
  758. unsignedchar "On"
  759. prepare()
  760. test.contains({ "-funsigned-char" }, gcc.getcxxflags(cfg))
  761. test.contains({ "-funsigned-char" }, gcc.getcflags(cfg))
  762. end
  763. function suite.sharedflags_onNoUnsignedChar()
  764. unsignedchar "Off"
  765. prepare()
  766. test.contains({ "-fno-unsigned-char" }, gcc.getcxxflags(cfg))
  767. test.contains({ "-fno-unsigned-char" }, gcc.getcflags(cfg))
  768. end
  769. --
  770. -- Test omit-frame-pointer flags.
  771. --
  772. function suite.sharedflags_onOmitFramePointerDefault()
  773. omitframepointer "Default"
  774. prepare()
  775. test.excludes({ "-fomit-frame-pointer", "-fno-omit-frame-pointer" }, gcc.getcxxflags(cfg))
  776. test.excludes({ "-fomit-frame-pointer", "-fno-omit-frame-pointer" }, gcc.getcflags(cfg))
  777. end
  778. function suite.sharedflags_onOmitFramePointer()
  779. omitframepointer "On"
  780. prepare()
  781. test.contains({ "-fomit-frame-pointer" }, gcc.getcxxflags(cfg))
  782. test.contains({ "-fomit-frame-pointer" }, gcc.getcflags(cfg))
  783. end
  784. function suite.sharedflags_onNoOmitFramePointer()
  785. omitframepointer "Off"
  786. prepare()
  787. test.contains({ "-fno-omit-frame-pointer" }, gcc.getcxxflags(cfg))
  788. test.contains({ "-fno-omit-frame-pointer" }, gcc.getcflags(cfg))
  789. end
  790. --
  791. -- Test visibility.
  792. --
  793. function suite.cxxflags_onVisibilityDefault()
  794. visibility "Default"
  795. prepare()
  796. test.excludes({ "-fvisibility=default" }, gcc.getcflags(cfg))
  797. test.contains({ "-fvisibility=default" }, gcc.getcxxflags(cfg))
  798. end
  799. function suite.cxxflags_onVisibilityHidden()
  800. visibility "Hidden"
  801. prepare()
  802. test.excludes({ "-fvisibility=hidden" }, gcc.getcflags(cfg))
  803. test.contains({ "-fvisibility=hidden" }, gcc.getcxxflags(cfg))
  804. end
  805. function suite.cxxflags_onVisibilityInternal()
  806. visibility "Internal"
  807. prepare()
  808. test.excludes({ "-fvisibility=internal" }, gcc.getcflags(cfg))
  809. test.contains({ "-fvisibility=internal" }, gcc.getcxxflags(cfg))
  810. end
  811. function suite.cxxflags_onVisibilityProtected()
  812. visibility "Protected"
  813. prepare()
  814. test.excludes({ "-fvisibility=protected" }, gcc.getcflags(cfg))
  815. test.contains({ "-fvisibility=protected" }, gcc.getcxxflags(cfg))
  816. end
  817. --
  818. -- Test inlines visibility flags.
  819. --
  820. function suite.cxxflags_onInlinesVisibilityDefault()
  821. inlinesvisibility "Default"
  822. prepare()
  823. test.excludes({ "-fvisibility-inlines-hidden" }, gcc.getcflags(cfg))
  824. test.excludes({ "-fvisibility-inlines-hidden" }, gcc.getcxxflags(cfg))
  825. end
  826. function suite.cxxflags_onInlinesVisibilityHidden()
  827. inlinesvisibility "Hidden"
  828. prepare()
  829. test.excludes({ "-fvisibility-inlines-hidden" }, gcc.getcflags(cfg))
  830. test.contains({ "-fvisibility-inlines-hidden" }, gcc.getcxxflags(cfg))
  831. end