Skip to content

Commit

Permalink
Add support for the .cc extension for C++ sources
Browse files Browse the repository at this point in the history
It's now quite easy to add support after introducing the C module

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
  • Loading branch information
rgrinberg committed May 27, 2019
1 parent 841c2c3 commit 9b8ab0e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ unreleased
- Fix `chdir` on external and source paths. Dune will also fail gracefully if
the external or source path does not exist (#2165, fixes #2158, @rgrinberg)

- Support the `.cc` extension fro C++ sources (#2195, fixes #83, @rgrinberg)

1.9.3 (06/05/2019)
------------------

Expand Down
15 changes: 11 additions & 4 deletions src/c.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@ module Kind = struct
| Not_allowed_until of Syntax.Version.t
| Recognized of string * t

let cxx_version_introduced ~obj ~dune_version ~version_introduced =
if dune_version >= version_introduced then
Recognized (obj, Cxx)
else
Not_allowed_until version_introduced

let split_extension fn ~dune_version =
match String.rsplit2 fn ~on:'.' with
| Some (obj, "c") -> Recognized (obj, C)
| Some (obj, "cpp") -> Recognized (obj, Cxx)
| Some (obj, "cxx") ->
if dune_version >= (1, 8) then
Recognized (obj, Cxx)
else
Not_allowed_until (1, 8)
cxx_version_introduced ~obj ~dune_version ~version_introduced:(1, 8)
| Some (obj, "cc") ->
cxx_version_introduced ~obj ~dune_version ~version_introduced:(1, 10)
| _ -> Unrecognized

let possible_fns t fn ~dune_version =
Expand All @@ -34,6 +39,8 @@ module Kind = struct
let cxx = [fn ^ ".cpp"] in
if dune_version >= (1, 8) then
(fn ^ ".cxx") :: cxx
else if dune_version >= (1, 10) then
(fn ^ ".cxx") :: (fn ^ ".cc") :: cxx
else
cxx

Expand Down

0 comments on commit 9b8ab0e

Please sign in to comment.