Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not pass compiler executable for AppleClang if it is the default #592

Merged
merged 6 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions conan_provider.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -265,18 +265,31 @@ function(detect_build_type BUILD_TYPE)
endif()
endfunction()

macro(set_conan_compiler_if_appleclang lang command output_variable)
if(CMAKE_${lang}_COMPILER_ID STREQUAL "AppleClang")
execute_process(COMMAND xcrun --find ${command}
OUTPUT_VARIABLE _xcrun_out OUTPUT_STRIP_TRAILING_WHITESPACE)
if (_xcrun_out STREQUAL "${CMAKE_${lang}_COMPILER}")
set(${output_variable} "")
endif()
unset(_xcrun_out)
endif()
endmacro()


macro(append_compiler_executables_configuration)
set(_conan_c_compiler "")
set(_conan_cpp_compiler "")
if(CMAKE_C_COMPILER)
set(_conan_c_compiler "\"c\":\"${CMAKE_C_COMPILER}\",")
set_conan_compiler_if_appleclang(C cc _conan_c_compiler)
else()
message(WARNING "CMake-Conan: The C compiler is not defined. "
"Please define CMAKE_C_COMPILER or enable the C language.")
endif()
if(CMAKE_CXX_COMPILER)
set(_conan_cpp_compiler "\"cpp\":\"${CMAKE_CXX_COMPILER}\"")
set_conan_compiler_if_appleclang(CXX c++ _conan_cpp_compiler)
else()
message(WARNING "CMake-Conan: The C++ compiler is not defined. "
"Please define CMAKE_CXX_COMPILER or enable the C++ language.")
Expand Down
8 changes: 8 additions & 0 deletions tests/resources/autotools_dependency/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.24)
project(MyApp CXX)

set(CMAKE_CXX_STANDARD 17)

find_package(helloautotools REQUIRED)
add_executable(app main.cpp)
target_link_libraries(app helloautotools::helloautotools)
2 changes: 2 additions & 0 deletions tests/resources/autotools_dependency/conanfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[requires]
helloautotools/0.1
20 changes: 19 additions & 1 deletion tests/test_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,17 @@ def setup_conan_home(conan_home_dir, tmp_path_factory):
# Detect default profile
run("conan profile detect -vquiet")

# Create hello lib from built-in template
# Create hello lib from built-in CMake template
os.chdir(workdir.as_posix())
run("conan new cmake_lib -d name=hello -d version=0.1 -vquiet")
run("conan export . -vquiet")

# Create hello-autootols from built-in autotools template
recipe_dir = tmp_path_factory.mktemp(f"temp_autotools")
os.chdir(recipe_dir.as_posix())
run("conan new autotools_lib -d name=helloautotools -d version=0.1 -vquiet")
run("conan export . -vquiet")

# additional recipes to export from resources, overlay on top of `hello` and export
additional_recipes = ['boost', 'bye', 'cmake-module-only', 'cmake-module-with-dependency']

Expand Down Expand Up @@ -324,6 +330,18 @@ def test_propagate_non_default_compiler(self, capfd, basic_cmake_project):
assert "The C compiler is not defined." not in err
assert 'tools.build:compiler_executables={"c":"/usr/bin/clang","cpp":"/usr/bin/clang++"}' in out

@darwin
def test_propagate_compiler_mac_autotools(self, capfd, basic_cmake_project):
"""Test that if the compiler is inside an XCode installation, we don't
propagate the path if that's the compiler that would be found by default"""
source_dir, binary_dir = basic_cmake_project
shutil.copytree(src_dir / 'tests' / 'resources' / 'autotools_dependency', source_dir, dirs_exist_ok=True)
run(f"cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} -DCMAKE_BUILD_TYPE=Release", check=False)
out, err = capfd.readouterr()
assert "configure: error: C++ compiler cannot create executables" not in err
assert "-- Generating done" in out
pass

class TestProfileCustomization:
def test_profile_defaults(self, capfd, basic_cmake_project):
"""Test the defaults passed for host and build profiles"""
Expand Down
Loading