Skip to content

Commit

Permalink
Add support for building C++ files from a LID.
Browse files Browse the repository at this point in the history
Fixes #900.

* configure.ac: Check for the presence of a C++ compiler to pass
    that into sources/jamfiles/config.jam.in.

* documentation/hacker-guide/source/build-system.rst: Update to
    mention DylanLibraryC++Sources.

* documentation/release-notes/source/2015.1.rst: Mention new support.

* sources/environment/project-wizard/project-description.dylan
  ($project-file-header-order): Add #"c++-source-files".

* sources/jamfiles/config.jam.in
  (C++, C++FLAGS): New variables.

* sources/jamfiles/mini-jambase.jam
  (rule C++, actions C++): New.

* sources/jamfiles/posix-build.jam:
  (rule DylanLibraryC++Sources): New.

* sources/jamfiles/x86-win32-pellesc-build.jam
  (C++, C++FLAGS): New variables, but PellesC has no C++ compiler.

* sources/jamfiles/x86-win32-vc6-build.jam
  (C++, C++FLAGS): New variables.
  (rule DylanLibraryC++Sources): New.

* sources/jamfiles/x86-win32-vc8-build.jam
  (C++, C++FLAGS): New variables.
  (rule DylanLibraryC++Sources): New.

* sources/lib/build-system/jam-build.dylan
  (jam-read-mkf): Add #"c++-source-files" handling.

* sources/project-manager/projects/lid-projects.dylan
  ($standard-lid-keyword, $list-build-keyword): Add #"c++-source-files".
  (copy-extra-records): Copy C++ source files.

* sources/project-manager/user-projects/add-file.dylan
  (project-other-sources): Include C++ sources.
  (project-add-file-of-type): Support C++ extensions.
  (project-remove-file-of-type): Support C++ extensions.

* sources/project-manager/user-projects/save-project.dylan
  (lid-project-build-settings): Return C++ source files.
  (save-lid-file-info): Save C++ source files.

* sources/project-manager/user-projects/user-projects.dylan
  ($c++-source-file-types): New constant for C++ file extensions.
  • Loading branch information
waywardmonkeys committed May 13, 2015
1 parent 5e36cbe commit 3185d4a
Show file tree
Hide file tree
Showing 15 changed files with 140 additions and 4 deletions.
1 change: 1 addition & 0 deletions configure.ac
Expand Up @@ -104,6 +104,7 @@ bootstrap_target=3-stage-bootstrap
AC_SUBST(bootstrap_target)

AC_PROG_CC([clang-3.5 clang gcc cc])
AC_PROG_CXX([clang++-3.5 clang++ g++ c++])

if test -n "$SUPPORT_LLVM"; then
AC_MSG_CHECKING([whether Clang is new enough])
Expand Down
3 changes: 3 additions & 0 deletions documentation/hacker-guide/source/build-system.rst
Expand Up @@ -229,6 +229,9 @@ component is the base name of the executable or shared library (from the
normally used to ensure that files of various sorts (not just C header
files) are copied into the build directory.

``DylanLibraryC++Sources *image* : *sources* ;``
Link C++ source files into the shared library.

``DylanLibraryRCFiles *image* : *rcfiles* ;``
Link Win32 resource files into the shared library and executable.

Expand Down
3 changes: 3 additions & 0 deletions documentation/release-notes/source/2015.1.rst
Expand Up @@ -37,6 +37,9 @@ Build System
back-ends. These shouldn't be changed unless you're sure you know
what you're doing.

* A new option for building C++ code, ``c++-source-files``, has been
added to LID files. This matches the ``c-source-files:`` keyword.

C-FFI
=====

Expand Down
3 changes: 2 additions & 1 deletion sources/environment/project-wizard/project-description.dylan
Expand Up @@ -547,7 +547,8 @@ define constant $project-file-header-order :: <vector>
#"Library", #"Module",
#"Synopsis", #"Author", #"Copyright", #"Version",
#"Major-Version", #"Minor-Version",
#"Files", #"C-Header-Files", #"C-Source-Files", #"RC-Files",
#"Files", #"C-Header-Files", #"C-Source-Files",
#"C++-Source-Files", #"RC-Files",
#"C-Libraries", #"C-Object-Files",
#"Linker-Options", #"Base-Address", #"Executable",
#"Debug-Command", #"Debug-Arguments"];
Expand Down
2 changes: 2 additions & 0 deletions sources/jamfiles/config.jam.in
Expand Up @@ -5,6 +5,8 @@

CC ?= @CC@ ;
CCFLAGS ?= @DISABLE_WARNINGS_CFLAGS@ @CFLAGS@ ;
C++ ?= @CXX@ ;
C++FLAGS ?= $(CCFLAGS) ;

MPS_CFLAGS ?= @MPS_CFLAGS@ -DGC_USE_MPS ;
MPS_LIBS ?= @MPS_LIBS@ ;
Expand Down
20 changes: 20 additions & 0 deletions sources/jamfiles/mini-jambase.jam
Expand Up @@ -58,6 +58,21 @@ rule Cc
CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ;
}

rule C++
{
Depends $(<) : $(>) ;

if $(RELOCATE)
{
CcMv $(<) : $(>) ;
}

C++FLAGS on $(<) += $(C++FLAGS) $(SUBDIRC++FLAGS) $(OPTIM) ;

CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ;
CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ;
}

rule Chmod
{
if $(CHMOD) { Chmod1 $(<) ; }
Expand Down Expand Up @@ -243,6 +258,11 @@ actions Cc
$(CC) -c -o "$(<)" $(CCFLAGS) $(CCDEFS) $(CCHDRS) "$(>)"
}

actions C++
{
$(C++) -c -o "$(<)" $(C++FLAGS) $(CCDEFS) $(CCHDRS) "$(>)"
}

actions Chmod1
{
$(CHMOD) $(MODE) "$(<)"
Expand Down
22 changes: 22 additions & 0 deletions sources/jamfiles/posix-build.jam
Expand Up @@ -322,6 +322,28 @@ rule DylanLibraryCSources image : sources {
}
}

rule DylanLibraryC++Sources image : sources {
# DylanLibraryC++Sources image : sources ;
#Echo DylanLibraryC++Sources $(image) ":" $(sources) ;

# Link C++ source files into the shared library.
if ! $(SYSTEM) {
local _dll = [ FDLLName $(image) ] ;
local _exe = [ FEXEName $(image) ] ;

local _i ;
for _i in [ FGristFiles $(sources) ] {
SEARCH on $(_i) = $(SEARCH_SOURCE) ;
local _obj = [ FGristFiles $(_i:S=$(SUFOBJ)) ] ;
MakeLocate $(_obj) : $(LOCATE_TARGET) ;

C++ $(_obj) : $(_i) ;

LinkDLL $(_dll) : $(_obj) ;
}
}
}

rule DylanLibraryCHeaders image : headers {
# DylanLibraryCHeaders image : headers ;
#Echo DylanLibraryCHeaders $(image) ":" $(headers) ;
Expand Down
2 changes: 2 additions & 0 deletions sources/jamfiles/x86-win32-pellesc-build.jam
Expand Up @@ -6,6 +6,8 @@ CC ?= pocc ;
CCFLAGS ?= -DWIN32 -D_WIN32 -D_MT -D_DLL -MD -Ze
-DOPEN_DYLAN_PLATFORM_WINDOWS
-DOPEN_DYLAN_ARCH_X86 ;
C++ ?= pellesc-has-no-c++compiler ;
C++FLAGS ?= $(CCFLAGS);
RC ?= porc ;
LINK ?= polink ;

Expand Down
26 changes: 26 additions & 0 deletions sources/jamfiles/x86-win32-vc6-build.jam
Expand Up @@ -6,6 +6,8 @@ CC ?= cl /nologo ;
CCFLAGS ?= -DWIN32 -D_WIN32 -D_MT -D_DLL -MD -Z7 -Od
-DOPEN_DYLAN_PLATFORM_WINDOWS
-DOPEN_DYLAN_ARCH_X86 ;
C++ ?= $(CC) ;
C++FLAGS ?= $(CCFLAGS) ;
CP ?= copy /y ;
RC ?= rc ;
RM ?= del/f/q ;
Expand Down Expand Up @@ -272,6 +274,30 @@ rule DylanLibraryCHeaders image : headers {
# TODO: The original build-system didn't do anything with this either.
}

rule DylanLibraryC++Sources image : sources {
# DylanLibraryC++Sources image : sources ;
#Echo DylanLibraryC++Sources $(image) ":" $(sources) ;

# Link C source files into the shared library.
if ! $(SYSTEM) {
local _dll = [ FDLLName $(image) ] ;
local _lib = [ FLIBName $(image) ] ;
local _exe = [ FEXEName $(image) ] ;

local _i ;
for _i in [ FGristFiles $(sources) ] {
SEARCH on $(_i) = $(SEARCH_SOURCE) ;
local _obj = [ FGristFiles $(_i:S=$(SUFOBJ)) ] ;
MakeLocate $(_obj) : $(LOCATE_TARGET) ;

C++ $(_obj) : $(_i) ;

LinkDLL $(_dll) $(_lib) : $(_obj) ;
LinkEXE $(_exe) : $(_obj) ;
}
}
}

rule DylanLibraryRCFiles image : rcfiles {
# DylanLibraryRCFiles image : rcfiles ;
#Echo DylanLibraryRCFiles $(image) ":" $(rcfiles) ;
Expand Down
29 changes: 29 additions & 0 deletions sources/jamfiles/x86-win32-vc8-build.jam
Expand Up @@ -6,6 +6,8 @@ CC ?= cl /nologo ;
CCFLAGS ?= -DWIN32 -D_WIN32 -D_MT -D_DLL -MD -Z7 -Od
-DOPEN_DYLAN_PLATFORM_WINDOWS
-DOPEN_DYLAN_ARCH_X86 ;
C++ ?= $(CC) ;
C++FLAGS ?= $(CCFLAGS) ;
CP ?= copy /y ;
RC ?= rc ;
RM ?= del/f/q ;
Expand Down Expand Up @@ -292,6 +294,33 @@ rule DylanLibraryCHeaders image : headers {
# TODO: The original build-system didn't do anything with this either.
}

rule DylanLibraryC++Sources image : sources {
# DylanLibraryC++Sources image : sources ;
#Echo DylanLibraryC++Sources $(image) ":" $(sources) ;

# Link C source files into the shared library.
if ! $(SYSTEM) {
local _dll = [ FDLLName $(image) ] ;
local _lib = [ FLIBName $(image) ] ;
local _exe = [ FEXEName $(image) ] ;

local _dlm = $(_dll).manifest ;
local _exm = $(_exe).manifest ;

local _i ;
for _i in [ FGristFiles $(sources) ] {
SEARCH on $(_i) = $(SEARCH_SOURCE) ;
local _obj = [ FGristFiles $(_i:S=$(SUFOBJ)) ] ;
MakeLocate $(_obj) : $(LOCATE_TARGET) ;

C++ $(_obj) : $(_i) ;

LinkDLL $(_dll) $(_dlm) $(_lib) : $(_obj) ;
LinkEXE $(_exe) $(_exm) : $(_obj) ;
}
}
}

rule DylanLibraryRCFiles image : rcfiles {
# DylanLibraryRCFiles image : rcfiles ;
#Echo DylanLibraryRCFiles $(image) ":" $(rcfiles) ;
Expand Down
2 changes: 2 additions & 0 deletions sources/lib/build-system/jam-build.dylan
Expand Up @@ -24,6 +24,7 @@ define method jam-read-mkf
// DylanLibraryCObjects image : objects ;
// DylanLibraryCSources image : sources ;
// DylanLibraryCHeaders image : headers ;
// DylanLibraryC++Sources image ; sources ;
// DylanLibraryRCFiles image : rcfiles ;
// DylanLibraryJamIncludes image : includes ;
let rule-specs
Expand All @@ -35,6 +36,7 @@ define method jam-read-mkf
#["DylanLibraryCObjects", #"c-object-files", #f],
#["DylanLibraryCSources", #"c-source-files", #f],
#["DylanLibraryCHeaders", #"c-header-files", #f],
#["DylanLibraryC++Sources", #"c++-source-files", #f],
#["DylanLibraryRCFiles", #"rc-files", #f]];
for (spec in rule-specs)
let value = element(variables, spec[1], default: #());
Expand Down
8 changes: 7 additions & 1 deletion sources/project-manager/projects/lid-projects.dylan
Expand Up @@ -23,6 +23,7 @@ define constant $standard-lid-keyword = #[#"comment",
#"c-header-files",
#"c-object-files",
#"c-libraries",
#"c++-source-files",
#"rc-files",
#"major-version",
#"minor-version",
Expand All @@ -46,6 +47,7 @@ define constant $list-build-keyword = #[#"linker-options",
#"c-header-files",
#"c-object-files",
#"c-libraries",
#"c++-source-files",
#"rc-files",
#"other-files",
#"broken-files",
Expand Down Expand Up @@ -504,6 +506,8 @@ define function lid-build-settings (source-loc, properties)
if (o-names) add-setting(c-object-files: map(source-dir, o-names)) end;
let c-libs = element(properties, #"c-libraries", default: #f);
if (c-libs) add-setting(c-libraries: c-libs) end;
let c++-names = element(properties, #"c++-source-files", default: #f);
if (c++-names) add-setting(c++-source-files: map(source-dir, c++-names)) end;
let rc-names = element(properties, #"rc-files", default: #f);
if (rc-names) add-setting(rc-files: map(source-dir, rc-names)) end;
let jam-names = element(properties, #"jam-includes", default: #f);
Expand Down Expand Up @@ -616,6 +620,7 @@ define method copy-extra-records (project :: <lid-project>,
c-source-files = #(),
c-header-files = #(),
c-object-files = #(),
c++-source-files = #(),
rc-files = #(),
jam-includes = #(),
c-libraries = #())
Expand All @@ -637,13 +642,14 @@ define method copy-extra-records (project :: <lid-project>,
end for
end method do-one-set;
if (~empty?(c-source-files) | ~empty?(c-header-files) | ~empty?(c-object-files)
| ~empty?(rc-files) | ~empty?(jam-includes))
| ~empty?(c++-source-files) | ~empty?(rc-files) | ~empty?(jam-includes))
debug-out(#"project-manager",
"Copying extra files for: %s",
project);
do-one-set(c-source-files);
do-one-set(c-header-files);
do-one-set(c-object-files);
do-one-set(c++-source-files);
do-one-set(rc-files);
do-one-set(jam-includes);
end
Expand Down
16 changes: 15 additions & 1 deletion sources/project-manager/user-projects/add-file.dylan
Expand Up @@ -25,7 +25,8 @@ define method project-other-sources (project :: <lid-project>)
add-sources(filenames)
end method add-project-filenames;
for (key in #[#"c-source-files", #"c-header-files", #"jam-includes", #"c-object-files",
#"c-libraries", #"rc-files", #"other-files", #"broken-files"])
#"c-libraries", #"c++-source-files", #"rc-files", #"other-files",
#"broken-files"])
add-project-filenames(key)
end;
sources
Expand Down Expand Up @@ -102,6 +103,12 @@ define method project-add-file-of-type
project-add-list-property(p, #"c-libraries", as(<string>, shorten-pathname(file-locator)))
end;

define method project-add-file-of-type
(type :: $c++-source-file-types, p :: <user-project>,
file-locator :: <file-locator>)
project-add-list-property(p, #"c++-source-files", as(<string>, file-locator))
end;

define method project-add-file-of-type
(type == $rc-file-type, p :: <user-project>,
file-locator :: <file-locator>)
Expand Down Expand Up @@ -226,6 +233,13 @@ define method project-remove-file-of-type
project-remove-list-property(p, #"c-libraries", as(<string>, file-locator))
end;

define method project-remove-file-of-type
(type :: $c++-source-file-types, p :: <user-project>,
file-locator :: <file-locator>)
project-remove-list-property(p, #"c++-source-files",
project-relative-file(p, file-locator))
end;

define method project-remove-file-of-type
(type == $rc-file-type, p :: <user-project>,
file-locator :: <file-locator>)
Expand Down
6 changes: 5 additions & 1 deletion sources/project-manager/user-projects/save-project.dylan
Expand Up @@ -21,6 +21,7 @@ define function lid-project-build-settings
c-header-files :: <sequence>,
c-object-files :: <sequence>,
c-libraries :: <sequence>,
c++-source-files :: <sequence>,
rc-files :: <sequence>,
jam-includes :: <sequence>)

Expand All @@ -39,6 +40,7 @@ define function lid-project-build-settings
project-build-property(p, #"c-header-files") | #[],
project-build-property(p, #"c-object-files") | #[],
project-build-property(p, #"c-libraries") | #[],
project-build-property(p, #"c++-source-files") | #[],
project-build-property(p, #"rc-files") | #[],
project-build-property(p, #"jam-includes") | #[])
end function lid-project-build-settings;
Expand Down Expand Up @@ -140,7 +142,8 @@ define function save-lid-info
let (executable, base-address-string,
debug-command, debug-arguments-string, debug-machine, debug-directory,
start-function, linker-options, c-source-files,
c-header-files, c-object-files, c-libraries, rc-files, jam-includes)
c-header-files, c-object-files, c-libraries,
c++-source-files, rc-files, jam-includes)
= lid-project-build-settings(p);
let relative = if (flatten-extras?)
curry(map, convert-path-to-filename)
Expand All @@ -161,6 +164,7 @@ define function save-lid-info
save-list-value(stream, #"c-header-files", relative(c-header-files));
save-list-value(stream, #"c-object-files", relative(c-object-files));
save-list-value(stream, #"c-libraries", c-libraries);
save-list-value(stream, #"c++-source-files", relative(c++-source-files));
save-list-value(stream, #"rc-files", relative(rc-files));
save-list-value(stream, #"jam-includes", relative(jam-includes));
save-single-value(stream, #"major-version", p.project-major-version);
Expand Down
1 change: 1 addition & 0 deletions sources/project-manager/user-projects/user-projects.dylan
Expand Up @@ -16,6 +16,7 @@ define constant $C-source-file-type = #"C";
define constant $C-header-file-type = #"h";
define constant $C-object-file-type = #"obj";
define constant $C-libraries-file-type = #"lib";
define constant $c++-source-file-types = one-of(#"cpp", #"cxx", #"cc", #"c++");
define constant $rc-file-type = #"rc";
define constant $ico-file-type = #"ico";
define constant $bmp-file-type = #"bmp";
Expand Down

0 comments on commit 3185d4a

Please sign in to comment.