Skip to content

Commit

Permalink
Prefer cc and c++ when using CMake on FreeBSD
Browse files Browse the repository at this point in the history
As of FreeBSD 10.X, clang is installed as the default compiler with "cc"
and "c++" as aliases to "clang" and "clang++" respectively.
  • Loading branch information
mudge committed Apr 9, 2024
1 parent 52fb0bc commit 337e588
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/mini_portile2/mini_portile_cmake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ def find_c_and_cxx_compilers(host)
if MiniPortile.darwin?
c_compiler ||= 'clang'
cxx_compiler ||='clang++'
elsif MiniPortile.freebsd?
c_compiler ||= 'cc'
cxx_compiler ||= 'c++'
else
c_compiler ||= 'gcc'
cxx_compiler ||= 'g++'
Expand Down
31 changes: 31 additions & 0 deletions test/test_cmake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,37 @@ def test_configure_defaults_with_macos
end
end

def test_configure_defaults_with_freebsd
recipe = init_recipe
recipe.host = 'some-host'

with_env({ "CC" => nil, "CXX" => nil }) do
MiniPortile.stub(:linux?, false) do
MiniPortile.stub(:windows?, false) do
MiniPortile.stub(:darwin?, false) do
MiniPortile.stub(:freebsd?, true) do
with_stubbed_target do
with_compilers(recipe, c_compiler: 'cc', cxx_compiler: 'c++') do
Open3.stub(:capture2, cmake_help_mock('Unix')) do
assert_equal(
[
"-DCMAKE_SYSTEM_NAME=FreeBSD",
"-DCMAKE_SYSTEM_PROCESSOR=x86_64",
"-DCMAKE_C_COMPILER=cc",
"-DCMAKE_CXX_COMPILER=c++",
"-DCMAKE_BUILD_TYPE=Release"
],
recipe.configure_defaults)
end
end
end
end
end
end
end
end
end

def test_configure_defaults_with_manual_system_name
recipe = init_recipe
recipe.system_name = 'Custom'
Expand Down

0 comments on commit 337e588

Please sign in to comment.