Commit a6e427ac authored by Alex Washburn's avatar Alex Washburn

Initial attempt at adding seperate C++ compilation sources and compiler flags.

parent e2cacc17
......@@ -1018,6 +1018,7 @@ checkPaths pkg =
++ [ (path, "license-file") | path <- licenseFiles pkg ]
++ concat
[ [ (path, "c-sources") | path <- cSources bi ]
++ [ (path, "cxx-sources") | path <- cxxSources bi ]
++ [ (path, "js-sources") | path <- jsSources bi ]
++ [ (path, "install-includes") | path <- installIncludes bi ]
++ [ (path, "hs-source-dirs") | path <- hsSourceDirs bi ]
......
......@@ -441,6 +441,9 @@ binfoFieldDescrs =
, spaceListField "cc-options"
showToken parseTokenQ'
ccOptions (\val binfo -> binfo{ccOptions=val})
, spaceListField "cxx-options"
showToken parseTokenQ'
cxxOptions (\val binfo -> binfo{cxxOptions=val})
, spaceListField "ld-options"
showToken parseTokenQ'
ldOptions (\val binfo -> binfo{ldOptions=val})
......@@ -456,6 +459,9 @@ binfoFieldDescrs =
, listFieldWithSep vcat "c-sources"
showFilePath parseFilePathQ
cSources (\paths binfo -> binfo{cSources=paths})
, listFieldWithSep vcat "cxx-sources"
showFilePath parseFilePathQ
cxxSources (\paths binfo -> binfo{cxxSources=paths})
, listFieldWithSep vcat "js-sources"
showFilePath parseFilePathQ
jsSources (\paths binfo -> binfo{jsSources=paths})
......
......@@ -438,10 +438,13 @@ binfoFieldDescrs =
mixins (\xs binfo -> binfo{mixins=xs})
, spaceListField "cpp-options"
showToken parsecToken'
cppOptions (\val binfo -> binfo{cppOptions=val})
cppOptions (\val binfo -> binfo{cppOptions=val})
, spaceListField "cc-options"
showToken parsecToken'
ccOptions (\val binfo -> binfo{ccOptions=val})
, spaceListField "cxx-options"
showToken parsecToken'
cxxOption (\val binfo -> binfo{cxxOptions=val})
, spaceListField "ld-options"
showToken parsecToken'
ldOptions (\val binfo -> binfo{ldOptions=val})
......@@ -457,6 +460,9 @@ binfoFieldDescrs =
, listFieldWithSep vcat "c-sources"
showFilePath parsecFilePath
cSources (\paths binfo -> binfo{cSources=paths})
, listFieldWithSep vcat "cxx-sources"
showFilePath parsecFilePath
cxxSources (\paths binfo -> binfo{cxxSources=paths})
, listFieldWithSep vcat "js-sources"
showFilePath parsecFilePath
jsSources (\paths binfo -> binfo{jsSources=paths})
......
......@@ -329,6 +329,15 @@ addExtraCSources bi extras = bi { cSources = new }
exs = Set.fromList extras
-- | Add extra C++ sources generated by preprocessing to build
-- information.
addExtraCxxSources :: BuildInfo -> [FilePath] -> BuildInfo
addExtraCxxSources bi extras = bi { cxxSources = new }
where new = Set.toList $ old `Set.union` exs
old = Set.fromList $ cxxSources bi
exs = Set.fromList extras
replComponent :: Verbosity
-> PackageDescription
-> LocalBuildInfo
......
......@@ -642,6 +642,39 @@ buildOrReplLib forRepl verbosity numJobs pkg_descr lbi lib clbi = do
else do vanilla; shared
when has_code $ whenProfLib (runGhcProg profOpts)
-- build any C++ sources seperately
unless (not has_code || null (cxxSources libBi)) $ do
info verbosity "Building C++ Sources..."
sequence_
[ do let baseCxxOpts = Internal.componentCxxGhcOptions verbosity implInfo
lbi libBi clbi libTargetDir filename
vanillaCxxOpts = if isGhcDynamic
then baseCxxOpts { ghcOptFPic = toFlag True }
else baseCxxOpts
profCxxOpts = vanillaCxxOpts `mappend` mempty {
ghcOptProfilingMode = toFlag True,
ghcOptObjSuffix = toFlag "p_o"
}
sharedCxxOpts = vanillaCxxOpts `mappend` mempty {
ghcOptFPic = toFlag True,
ghcOptDynLinkMode = toFlag GhcDynamicOnly,
ghcOptObjSuffix = toFlag "dyn_o"
}
odir = fromFlag (ghcOptObjDir vanillaCxxOpts)
createDirectoryIfMissingVerbose verbosity True odir
let runGhcProgIfNeeded cxxOpts = do
needsRecomp <- checkNeedsRecompilation filename cxxOpts
when needsRecomp $ runGhcProg cxxOpts
runGhcProgIfNeeded vanillaCxxOpts
unless forRepl $
whenSharedLib forceSharedLib (runGhcProgIfNeeded sharedCxxOpts)
unless forRepl $ whenProfLib (runGhcProgIfNeeded profCxxOpts)
| filename <- cxxSources libBi]
when has_code . ifReplLib $ do
when (null (allLibModules lib clbi)) $ warn verbosity "No exposed modules"
ifReplLib (runGhcProg replOpts)
-- build any C sources
unless (not has_code || null (cSources libBi)) $ do
info verbosity "Building C Sources..."
......@@ -677,10 +710,6 @@ buildOrReplLib forRepl verbosity numJobs pkg_descr lbi lib clbi = do
-- with ghci, but .c files can depend on .h files generated by ghc by ffi
-- exports.
when has_code . ifReplLib $ do
when (null (allLibModules lib clbi)) $ warn verbosity "No exposed modules"
ifReplLib (runGhcProg replOpts)
-- link:
when has_code . unless forRepl $ do
info verbosity "Linking..."
......
......@@ -19,6 +19,7 @@ module Distribution.Simple.GHC.Internal (
targetPlatform,
getGhcInfo,
componentCcGhcOptions,
componentCxxGhcOptions,
componentGhcOptions,
mkGHCiLibName,
filterGhciFlags,
......@@ -290,6 +291,40 @@ componentCcGhcOptions verbosity _implInfo lbi bi clbi odir filename =
ghcOptObjDir = toFlag odir
}
componentCxxGhcOptions :: Verbosity -> GhcImplInfo -> LocalBuildInfo
-> BuildInfo -> ComponentLocalBuildInfo
-> FilePath -> FilePath
-> GhcOptions
componentCxxGhcOptions verbosity _implInfo lbi bi cxxlbi odir filename =
mempty {
-- Respect -v0, but don't crank up verbosity on GHC if
-- Cabal verbosity is requested. For that, use --ghc-option=-v instead!
ghcOptVerbosity = toFlag (min verbosity normal),
ghcOptMode = toFlag GhcModeCompile,
ghcOptInputFiles = toNubListR [filename],
ghcOptCppIncludePath = toNubListR $ [autogenComponentModulesDir lbi cxxlbi
,autogenPackageModulesDir lbi
,odir]
++ PD.includeDirs bi,
ghcOptHideAllPackages= toFlag True,
ghcOptPackageDBs = withPackageDB lbi,
ghcOptPackages = toNubListR $ mkGhcOptPackages cxxlbi,
ghcOptCxxOptions = toNubListR $
(case withOptimization lbi of
NoOptimisation -> []
_ -> ["-O2"]) ++
(case withDebugInfo lbi of
NoDebugInfo -> []
MinimalDebugInfo -> ["-g1"]
NormalDebugInfo -> ["-g"]
MaximalDebugInfo -> ["-g3"]) ++
PD.ccOptions bi,
ghcOptObjDir = toFlag odir
}
componentGhcOptions :: Verbosity -> GhcImplInfo -> LocalBuildInfo
-> BuildInfo -> ComponentLocalBuildInfo -> FilePath
-> GhcOptions
......
......@@ -152,6 +152,9 @@ data GhcOptions = GhcOptions {
-- | Options to pass through to the C compiler; the @ghc -optc@ flag.
ghcOptCcOptions :: NubListR String,
-- | Options to pass through to the C++ compiler.
ghcOptCxxOptions :: NubListR String,
-- | Options to pass through to CPP; the @ghc -optP@ flag.
ghcOptCppOptions :: NubListR String,
......
......@@ -49,11 +49,13 @@ data BuildInfo = BuildInfo {
buildToolDepends :: [ExeDependency],
cppOptions :: [String], -- ^ options for pre-processing Haskell code
ccOptions :: [String], -- ^ options for C compiler
cxxOptions :: [String], -- ^ options for C++ compiler
ldOptions :: [String], -- ^ options for linker
pkgconfigDepends :: [PkgconfigDependency], -- ^ pkg-config packages that are used
frameworks :: [String], -- ^support frameworks for Mac OS X
extraFrameworkDirs:: [String], -- ^ extra locations to find frameworks.
cSources :: [FilePath],
cxxSources :: [FilePath],
jsSources :: [FilePath],
hsSourceDirs :: [FilePath], -- ^ where to look for the Haskell module hierarchy
otherModules :: [ModuleName], -- ^ non-exposed or non-main modules
......@@ -91,11 +93,13 @@ instance Monoid BuildInfo where
buildToolDepends = [],
cppOptions = [],
ccOptions = [],
cxxOptions = [],
ldOptions = [],
pkgconfigDepends = [],
frameworks = [],
extraFrameworkDirs = [],
cSources = [],
cxxSources = [],
jsSources = [],
hsSourceDirs = [],
otherModules = [],
......@@ -127,11 +131,13 @@ instance Semigroup BuildInfo where
buildToolDepends = combine buildToolDepends,
cppOptions = combine cppOptions,
ccOptions = combine ccOptions,
cxxOptions = combine cxxOptions,
ldOptions = combine ldOptions,
pkgconfigDepends = combine pkgconfigDepends,
frameworks = combineNub frameworks,
extraFrameworkDirs = combineNub extraFrameworkDirs,
cSources = combineNub cSources,
cxxSources = combineNub cxxSources,
jsSources = combineNub jsSources,
hsSourceDirs = combineNub hsSourceDirs,
otherModules = combineNub otherModules,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment