Skip to content

Commit

Permalink
refactor handling of compiler list
Browse files Browse the repository at this point in the history
  • Loading branch information
jcar87 committed Jul 12, 2024
1 parent 6aa2da3 commit 779ff3d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
18 changes: 13 additions & 5 deletions conan_provider.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -289,30 +289,38 @@ endmacro()
macro(append_compiler_executables_configuration)
set(_conan_c_compiler "")
set(_conan_cpp_compiler "")
set(_conan_rc_compiler "")
set(_conan_compilers_list "")
if(CMAKE_C_COMPILER)
set(_conan_c_compiler "\"c\":\"${CMAKE_C_COMPILER}\",")
set(_conan_c_compiler "\"c\":\"${CMAKE_C_COMPILER}\"")
set_conan_compiler_if_appleclang(C cc _conan_c_compiler)
message("_conan_c_compiler ${_conan_c_compiler}")
list(APPEND _conan_compilers_list ${_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_cpp_compiler "\"cpp\":\"${CMAKE_CXX_COMPILER}\"")
set_conan_compiler_if_appleclang(CXX c++ _conan_cpp_compiler)
list(APPEND _conan_compilers_list ${_conan_cpp_compiler})
else()
message(WARNING "CMake-Conan: The C++ compiler is not defined. "
"Please define CMAKE_CXX_COMPILER or enable the C++ language.")
endif()
if(CMAKE_RC_COMPILER)
set(_conan_rc_compiler "\"rc\":\"${CMAKE_RC_COMPILER}\"")
list(APPEND _conan_compilers_list ${_conan_rc_compiler})
# Not necessary to warn if RC not defined
endif()

if(NOT "x${_conan_c_compiler}${_conan_cpp_compiler}${_conan_rc_compiler}" STREQUAL "x")
string(APPEND PROFILE "tools.build:compiler_executables={${_conan_c_compiler}${_conan_cpp_compiler}${_conan_rc_compiler}}\n")
if(NOT "x${_conan_compilers_list}" STREQUAL "x")
string(REPLACE ";" "," _conan_compilers_list "${_conan_compilers_list}")
string(APPEND PROFILE "tools.build:compiler_executables={${_conan_compilers_list}}\n")
endif()
unset(_conan_c_compiler)
unset(_conan_cpp_compiler)
unset(_conan_rc_compiler)
unset(_conan_compilers_list)
endmacro()


Expand Down
6 changes: 3 additions & 3 deletions tests/test_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def test_propagate_cxx_compiler(self, capfd, basic_cmake_project):
out, err = capfd.readouterr()
assert "The CXX compiler identification is GNU" in out
assert "CMake-Conan: The C compiler is not defined." in err
assert 'tools.build:compiler_executables={"cpp":"/usr/bin/c++",}' in out
assert 'tools.build:compiler_executables={"cpp":"/usr/bin/c++"}' in out

@linux
def test_propagate_c_compiler(self, capfd, basic_cmake_project):
Expand All @@ -318,7 +318,7 @@ def test_propagate_c_compiler(self, capfd, basic_cmake_project):
out, err = capfd.readouterr()
assert "The CXX compiler identification is GNU" in out
assert "The C compiler is not defined." not in err
assert 'tools.build:compiler_executables={"c":"/usr/bin/cc","cpp":"/usr/bin/c++",}' in out
assert 'tools.build:compiler_executables={"c":"/usr/bin/cc","cpp":"/usr/bin/c++"}' in out

@linux
def test_propagate_non_default_compiler(self, capfd, basic_cmake_project):
Expand All @@ -328,7 +328,7 @@ def test_propagate_non_default_compiler(self, capfd, basic_cmake_project):
out, err = capfd.readouterr()
assert "The CXX compiler identification is Clang" in out
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
assert 'tools.build:compiler_executables={"c":"/usr/bin/clang","cpp":"/usr/bin/clang++"}' in out

@darwin
@pytest.mark.parametrize("cmake_generator", ["Unix Makefiles", "Xcode"])
Expand Down

0 comments on commit 779ff3d

Please sign in to comment.