2009-05-12 21:44:45 +00:00
|
|
|
--
|
|
|
|
-- tests/test_gcc.lua
|
|
|
|
-- Automated test suite for the GCC toolset interface.
|
2013-05-16 15:40:47 +00:00
|
|
|
-- Copyright (c) 2009-2013 Jason Perkins and the Premake project
|
2009-05-12 21:44:45 +00:00
|
|
|
--
|
|
|
|
|
2013-09-11 14:57:44 +00:00
|
|
|
local suite = test.declare("tools_gcc")
|
2012-02-17 00:51:14 +00:00
|
|
|
|
|
|
|
local gcc = premake.tools.gcc
|
2013-09-13 15:15:36 +00:00
|
|
|
local project = premake.project
|
2012-02-17 00:51:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Setup/teardown
|
|
|
|
--
|
|
|
|
|
|
|
|
local sln, prj, cfg
|
2009-05-12 21:44:45 +00:00
|
|
|
|
2009-12-31 22:46:45 +00:00
|
|
|
function suite.setup()
|
2012-07-23 21:21:06 +00:00
|
|
|
sln = test.createsolution()
|
2012-02-17 00:51:14 +00:00
|
|
|
system "Linux"
|
|
|
|
end
|
|
|
|
|
|
|
|
local function prepare()
|
2013-09-13 15:52:00 +00:00
|
|
|
prj = premake.solution.getproject(sln, 1)
|
2013-09-13 15:15:36 +00:00
|
|
|
cfg = project.getconfig(prj, "Debug")
|
2009-05-12 21:44:45 +00:00
|
|
|
end
|
|
|
|
|
2009-12-31 22:46:45 +00:00
|
|
|
|
2012-09-27 16:18:03 +00:00
|
|
|
--
|
|
|
|
-- Check the selection of tools based on the target system.
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.tools_onDefaults()
|
|
|
|
prepare()
|
|
|
|
test.isnil(gcc.gettoolname(cfg, "cc"))
|
|
|
|
test.isnil(gcc.gettoolname(cfg, "cxx"))
|
|
|
|
test.isnil(gcc.gettoolname(cfg, "ar"))
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.tools_onPS3()
|
|
|
|
system "PS3"
|
|
|
|
prepare()
|
|
|
|
test.isequal("ppu-lv2-g++", gcc.gettoolname(cfg, "cc"))
|
|
|
|
test.isequal("ppu-lv2-g++", gcc.gettoolname(cfg, "cxx"))
|
|
|
|
test.isequal("ppu-lv2-ar", gcc.gettoolname(cfg, "ar"))
|
|
|
|
end
|
2013-01-31 14:38:45 +00:00
|
|
|
|
2012-09-27 16:18:03 +00:00
|
|
|
|
2011-02-10 17:24:51 +00:00
|
|
|
--
|
2012-02-17 00:51:14 +00:00
|
|
|
-- By default, the -MMD -MP are used to generate dependencies.
|
2011-02-10 17:24:51 +00:00
|
|
|
--
|
|
|
|
|
2012-02-17 00:51:14 +00:00
|
|
|
function suite.cppflags_defaultWithMMD()
|
|
|
|
prepare()
|
2012-06-20 20:15:45 +00:00
|
|
|
test.isequal({"-MMD", "-MP"}, gcc.getcppflags(cfg))
|
2009-05-12 21:44:45 +00:00
|
|
|
end
|
|
|
|
|
2012-02-17 00:51:14 +00:00
|
|
|
|
|
|
|
--
|
|
|
|
-- Haiku OS doesn't support the -MP flag yet (that's weird, isn't it?)
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.cppflagsExcludeMP_onHaiku()
|
|
|
|
system "Haiku"
|
|
|
|
prepare()
|
|
|
|
test.isequal({ "-MMD" }, gcc.getcppflags(cfg))
|
2011-02-10 17:24:51 +00:00
|
|
|
end
|
2009-12-31 22:46:45 +00:00
|
|
|
|
2011-02-10 17:24:51 +00:00
|
|
|
|
|
|
|
--
|
2012-02-17 00:51:14 +00:00
|
|
|
-- Check the translation of CFLAGS.
|
2011-02-10 17:24:51 +00:00
|
|
|
--
|
|
|
|
|
2013-09-27 18:49:21 +00:00
|
|
|
function suite.cflags_onExtraWarnings()
|
|
|
|
flags { "ExtraWarnings" }
|
2013-09-27 18:25:10 +00:00
|
|
|
prepare()
|
2013-09-27 18:49:21 +00:00
|
|
|
test.isequal({ "-Wall -Wextra" }, gcc.getcflags(cfg))
|
2013-09-27 18:25:10 +00:00
|
|
|
end
|
|
|
|
|
2012-02-17 00:51:14 +00:00
|
|
|
function suite.cflags_onFatalWarnings()
|
|
|
|
flags { "FatalWarnings" }
|
|
|
|
prepare()
|
|
|
|
test.isequal({ "-Werror" }, gcc.getcflags(cfg))
|
|
|
|
end
|
|
|
|
|
2013-09-27 18:49:21 +00:00
|
|
|
function suite.cflags_onFloastFast()
|
|
|
|
floatingpoint "Fast"
|
2012-07-30 11:12:01 +00:00
|
|
|
prepare()
|
2013-09-27 18:49:21 +00:00
|
|
|
test.isequal({ "-ffast-math" }, gcc.getcflags(cfg))
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.cflags_onFloastStrict()
|
|
|
|
floatingpoint "Strict"
|
|
|
|
prepare()
|
|
|
|
test.isequal({ "-ffloat-store" }, gcc.getcflags(cfg))
|
2012-07-30 11:12:01 +00:00
|
|
|
end
|
2009-09-29 20:28:13 +00:00
|
|
|
|
2012-07-30 12:52:35 +00:00
|
|
|
function suite.cflags_onNoWarnings()
|
2012-07-30 11:12:01 +00:00
|
|
|
flags { "NoWarnings" }
|
|
|
|
prepare()
|
|
|
|
test.isequal({ "-w" }, gcc.getcflags(cfg))
|
|
|
|
end
|
2013-09-27 18:49:21 +00:00
|
|
|
|
|
|
|
function suite.cflags_onSSE()
|
|
|
|
vectorextensions "SSE"
|
|
|
|
prepare()
|
|
|
|
test.isequal({ "-msse" }, gcc.getcflags(cfg))
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.cflags_onSSE2()
|
|
|
|
vectorextensions "SSE2"
|
|
|
|
prepare()
|
|
|
|
test.isequal({ "-msse2" }, gcc.getcflags(cfg))
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-02-17 00:51:14 +00:00
|
|
|
--
|
|
|
|
-- Check the translation of CXXFLAGS.
|
|
|
|
--
|
2009-12-31 22:46:45 +00:00
|
|
|
|
2012-02-17 00:51:14 +00:00
|
|
|
function suite.cflags_onNoExceptions()
|
|
|
|
flags { "NoExceptions" }
|
|
|
|
prepare()
|
|
|
|
test.isequal({ "-fno-exceptions" }, gcc.getcxxflags(cfg))
|
2009-09-29 20:28:13 +00:00
|
|
|
end
|
|
|
|
|
2013-08-15 22:22:23 +00:00
|
|
|
function suite.cflags_onNoBufferSecurityCheck()
|
|
|
|
flags { "NoBufferSecurityCheck" }
|
|
|
|
prepare()
|
|
|
|
test.isequal({ "-fno-stack-protector" }, gcc.getcxxflags(cfg))
|
|
|
|
end
|
2009-12-31 22:46:45 +00:00
|
|
|
|
2013-09-27 18:49:21 +00:00
|
|
|
|
2012-02-17 00:51:14 +00:00
|
|
|
--
|
|
|
|
-- Check the basic translation of LDFLAGS for a Posix system.
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.ldflags_defaultOnLinux()
|
|
|
|
prepare()
|
|
|
|
test.isequal({ "-s" }, gcc.getldflags(cfg))
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.ldflags_onSymbols()
|
|
|
|
flags { "Symbols" }
|
|
|
|
prepare()
|
|
|
|
test.isequal({}, gcc.getldflags(cfg))
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.ldflags_onSharedLib()
|
|
|
|
kind "SharedLib"
|
|
|
|
prepare()
|
|
|
|
test.isequal({ "-s", "-shared" }, gcc.getldflags(cfg))
|
2009-09-29 20:28:13 +00:00
|
|
|
end
|
2009-12-31 22:46:45 +00:00
|
|
|
|
|
|
|
|
2011-02-10 17:24:51 +00:00
|
|
|
--
|
2012-02-17 00:51:14 +00:00
|
|
|
-- Check Mac OS X variants on LDFLAGS.
|
2011-02-10 17:24:51 +00:00
|
|
|
--
|
|
|
|
|
2012-02-17 00:51:14 +00:00
|
|
|
function suite.ldflags_onMacOSXStrip()
|
|
|
|
system "MacOSX"
|
|
|
|
prepare()
|
|
|
|
test.isequal({ "-Wl,-x" }, gcc.getldflags(cfg))
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.ldflags_onMacOSXSharedLib()
|
|
|
|
system "MacOSX"
|
|
|
|
kind "SharedLib"
|
|
|
|
prepare()
|
2012-10-18 21:58:41 +00:00
|
|
|
test.isequal({ "-Wl,-x", "-dynamiclib" }, gcc.getldflags(cfg))
|
2011-02-10 17:24:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-02-17 00:51:14 +00:00
|
|
|
--
|
|
|
|
-- Check Windows variants on LDFLAGS.
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.ldflags_onWindowsharedLib()
|
|
|
|
system "Windows"
|
|
|
|
kind "SharedLib"
|
|
|
|
prepare()
|
|
|
|
test.isequal({ "-s", "-shared", '-Wl,--out-implib="MyProject.lib"' }, gcc.getldflags(cfg))
|
2009-12-31 22:46:45 +00:00
|
|
|
end
|
2012-02-17 00:51:14 +00:00
|
|
|
|
|
|
|
function suite.ldflags_onWindowsApp()
|
|
|
|
system "Windows"
|
|
|
|
kind "WindowedApp"
|
|
|
|
prepare()
|
|
|
|
test.isequal({ "-s", "-mwindows" }, gcc.getldflags(cfg))
|
|
|
|
end
|
2013-01-31 14:38:45 +00:00
|
|
|
|
|
|
|
|
2012-02-17 00:51:14 +00:00
|
|
|
|
|
|
|
--
|
|
|
|
-- Make sure system or architecture flags are added properly.
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.cflags_onX32()
|
|
|
|
architecture "x32"
|
|
|
|
prepare()
|
|
|
|
test.isequal({ "-m32" }, gcc.getcflags(cfg))
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.ldflags_onX32()
|
|
|
|
architecture "x32"
|
|
|
|
prepare()
|
|
|
|
test.isequal({ "-s", "-m32", "-L/usr/lib32" }, gcc.getldflags(cfg))
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.cflags_onX64()
|
|
|
|
architecture "x64"
|
|
|
|
prepare()
|
|
|
|
test.isequal({ "-m64" }, gcc.getcflags(cfg))
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.ldflags_onX64()
|
|
|
|
architecture "x64"
|
|
|
|
prepare()
|
|
|
|
test.isequal({ "-s", "-m64", "-L/usr/lib64" }, gcc.getldflags(cfg))
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Non-Windows shared libraries should marked as position independent.
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.cflags_onWindowsSharedLib()
|
|
|
|
system "MacOSX"
|
|
|
|
kind "SharedLib"
|
|
|
|
prepare()
|
|
|
|
test.isequal({ "-fPIC" }, gcc.getcflags(cfg))
|
|
|
|
end
|
|
|
|
|
2012-02-28 21:15:46 +00:00
|
|
|
|
|
|
|
--
|
|
|
|
-- Check the formatting of linked system libraries.
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.links_onSystemLibs()
|
|
|
|
links { "fs_stub", "net_stub" }
|
|
|
|
prepare()
|
|
|
|
test.isequal({ "-lfs_stub", "-lnet_stub" }, gcc.getlinks(cfg))
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.links_onFramework()
|
|
|
|
links { "Cocoa.framework" }
|
|
|
|
prepare()
|
|
|
|
test.isequal({ "-framework Cocoa" }, gcc.getlinks(cfg))
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- When linking to a static sibling library, the relative path to the library
|
|
|
|
-- should be used instead of the "-l" flag. This prevents linking against a
|
|
|
|
-- shared library of the same name, should one be present.
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.links_onStaticSiblingLibrary()
|
|
|
|
links { "MyProject2" }
|
2012-06-28 19:48:05 +00:00
|
|
|
|
2012-02-28 21:15:46 +00:00
|
|
|
test.createproject(sln)
|
2012-06-28 19:48:05 +00:00
|
|
|
system "Linux"
|
2012-02-28 21:15:46 +00:00
|
|
|
kind "StaticLib"
|
|
|
|
targetdir "lib"
|
2012-06-28 19:48:05 +00:00
|
|
|
|
2012-02-28 21:15:46 +00:00
|
|
|
prepare()
|
|
|
|
test.isequal({ "lib/libMyProject2.a" }, gcc.getlinks(cfg))
|
|
|
|
end
|
2012-02-29 21:05:45 +00:00
|
|
|
|
|
|
|
|
2012-06-13 19:21:22 +00:00
|
|
|
--
|
|
|
|
-- Use the -lname format when linking to sibling shared libraries.
|
|
|
|
--
|
|
|
|
|
2013-05-16 15:40:47 +00:00
|
|
|
function suite.links_onSharedSiblingLibrary()
|
2012-06-13 19:21:22 +00:00
|
|
|
links { "MyProject2" }
|
2012-06-28 19:48:05 +00:00
|
|
|
|
2012-06-13 19:21:22 +00:00
|
|
|
test.createproject(sln)
|
2012-06-28 19:48:05 +00:00
|
|
|
system "Linux"
|
2012-06-13 19:21:22 +00:00
|
|
|
kind "SharedLib"
|
|
|
|
targetdir "lib"
|
2012-06-28 19:48:05 +00:00
|
|
|
|
2012-06-13 19:21:22 +00:00
|
|
|
prepare()
|
2013-05-16 15:40:47 +00:00
|
|
|
test.isequal({ "lib/libMyProject2.so" }, gcc.getlinks(cfg))
|
2012-06-13 19:21:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-02-29 21:05:45 +00:00
|
|
|
--
|
|
|
|
-- When linking object files, leave off the "-l".
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.links_onObjectFile()
|
|
|
|
links { "generated.o" }
|
|
|
|
prepare()
|
|
|
|
test.isequal({ "generated.o" }, gcc.getlinks(cfg))
|
|
|
|
end
|
|
|
|
|
2012-06-28 18:17:19 +00:00
|
|
|
|
2013-01-31 14:38:45 +00:00
|
|
|
--
|
|
|
|
-- If the object file is referenced with a path, it should be
|
|
|
|
-- made relative to the project.
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.links_onObjectFileOutsideProject()
|
|
|
|
location "MyProject"
|
|
|
|
links { "obj/Debug/generated.o" }
|
|
|
|
prepare()
|
|
|
|
test.isequal({ "../obj/Debug/generated.o" }, gcc.getlinks(cfg))
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Make sure shell variables are kept intact for object file paths.
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.links_onObjectFileWithShellVar()
|
|
|
|
location "MyProject"
|
|
|
|
links { "$(IntDir)/generated.o" }
|
|
|
|
prepare()
|
|
|
|
test.isequal({ "$(IntDir)/generated.o" }, gcc.getlinks(cfg))
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-06-28 18:17:19 +00:00
|
|
|
--
|
|
|
|
-- Include directories should be made project relative.
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.includeDirsAreRelative()
|
|
|
|
includedirs { "../include", "src/include" }
|
|
|
|
prepare()
|
2013-09-11 14:57:44 +00:00
|
|
|
test.isequal({ '-I../include', '-Isrc/include' }, gcc.getincludedirs(cfg, cfg.includedirs))
|
2012-06-28 18:17:19 +00:00
|
|
|
end
|
|
|
|
|
2012-06-30 12:25:30 +00:00
|
|
|
|
|
|
|
--
|
|
|
|
-- Skip external projects when building the list of linked
|
|
|
|
-- libraries, since I don't know the actual output target.
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.skipsExternalProjectRefs()
|
|
|
|
links { "MyProject2" }
|
2013-01-31 14:38:45 +00:00
|
|
|
|
2012-06-30 12:25:30 +00:00
|
|
|
external "MyProject2"
|
|
|
|
kind "StaticLib"
|
|
|
|
language "C++"
|
2013-01-31 14:38:45 +00:00
|
|
|
|
2012-06-30 12:25:30 +00:00
|
|
|
prepare()
|
|
|
|
test.isequal({}, gcc.getlinks(cfg, false))
|
|
|
|
end
|
2012-11-06 21:42:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Check handling of forced includes.
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.forcedIncludeFiles()
|
|
|
|
forceincludes { "stdafx.h", "include/sys.h" }
|
|
|
|
prepare()
|
2013-09-11 14:57:44 +00:00
|
|
|
test.isequal({'-include stdafx.h', '-include include/sys.h'}, gcc.getforceincludes(cfg))
|
2012-11-06 21:42:44 +00:00
|
|
|
end
|
2013-09-11 14:57:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Include directories containing spaces (or which could contain spaces)
|
|
|
|
-- should be wrapped in quotes.
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.includeDirs_onSpaces()
|
|
|
|
includedirs { "include files" }
|
|
|
|
prepare()
|
|
|
|
test.isequal({ '-I"include files"' }, gcc.getincludedirs(cfg, cfg.includedirs))
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.includeDirs_onEnvVars()
|
|
|
|
includedirs { "$(IntDir)/includes" }
|
|
|
|
prepare()
|
|
|
|
test.isequal({ '-I"$(IntDir)/includes"' }, gcc.getincludedirs(cfg, cfg.includedirs))
|
|
|
|
end
|
|
|
|
|