From 22c70def2bad0b0eb49c19fe8c37afa1590dc9d2 Mon Sep 17 00:00:00 2001 From: Paul Mucur Date: Tue, 9 Apr 2024 08:31:01 +0100 Subject: [PATCH] Prefer cc and c++ when using CMake on FreeBSD As of FreeBSD 10.X, clang is installed as the default compiler with "cc" and "c++" as aliases to "clang" and "clang++" respectively. --- lib/mini_portile2/mini_portile_cmake.rb | 3 +++ test/test_cmake.rb | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/mini_portile2/mini_portile_cmake.rb b/lib/mini_portile2/mini_portile_cmake.rb index 41e1ad1..9fcfb4c 100644 --- a/lib/mini_portile2/mini_portile_cmake.rb +++ b/lib/mini_portile2/mini_portile_cmake.rb @@ -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++' diff --git a/test/test_cmake.rb b/test/test_cmake.rb index 7a3483c..6d5ffa0 100644 --- a/test/test_cmake.rb +++ b/test/test_cmake.rb @@ -107,6 +107,29 @@ 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 + with_stubbed_target(os: 'freebsd14') 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 + def test_configure_defaults_with_manual_system_name recipe = init_recipe recipe.system_name = 'Custom'