Skip to content

Commit

Permalink
Set detect_lib_cxx variables and arguments to lower-case snake-case
Browse files Browse the repository at this point in the history
  • Loading branch information
jhol committed Jul 31, 2024
1 parent d669866 commit 100970e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
36 changes: 18 additions & 18 deletions conan_provider.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -137,65 +137,65 @@ endfunction()


macro(detect_gnu_libstdcxx)
# _CONAN_IS_GNU_LIBSTDCXX true if GNU libstdc++
# _conan_is_gnu_libstdcxx true if GNU libstdc++
check_cxx_source_compiles("
#include <cstddef>
#if !defined(__GLIBCXX__) && !defined(__GLIBCPP__)
static_assert(false);
#endif
int main(){}" _CONAN_IS_GNU_LIBSTDCXX)
int main(){}" _conan_is_gnu_libstdcxx)

# _CONAN_GNU_LIBSTDCXX_IS_CXX11_ABI true if C++11 ABI
# _conan_gnu_libstdcxx_is_cxx11_abi true if C++11 ABI
check_cxx_source_compiles("
#include <string>
static_assert(sizeof(std::string) != sizeof(void*), \"using libstdc++\");
int main () {}" _CONAN_GNU_LIBSTDCXX_IS_CXX11_ABI)
int main () {}" _conan_gnu_libstdcxx_is_cxx11_abi)

set(_CONAN_GNU_LIBSTDCXX_SUFFIX "")
if(_CONAN_GNU_LIBSTDCXX_IS_CXX11_ABI)
set(_CONAN_GNU_LIBSTDCXX_SUFFIX "11")
set(_conan_gnu_libstdcxx_suffix "")
if(_conan_gnu_libstdcxx_is_cxx11_abi)
set(_conan_gnu_libstdcxx_suffix "11")
endif()
unset (_CONAN_GNU_LIBSTDCXX_IS_CXX11_ABI)
unset (_conan_gnu_libstdcxx_is_cxx11_abi)
endmacro()


macro(detect_libcxx)
# _CONAN_IS_LIBCXX true if LLVM libc++
# _conan_is_libcxx true if LLVM libc++
check_cxx_source_compiles("
#include <cstddef>
#if !defined(_LIBCPP_VERSION)
static_assert(false);
#endif
int main(){}" _CONAN_IS_LIBCXX)
int main(){}" _conan_is_libcxx)
endmacro()


function(detect_lib_cxx LIB_CXX)
function(detect_lib_cxx lib_cxx)
if(CMAKE_SYSTEM_NAME STREQUAL "Android")
message(STATUS "CMake-Conan: android_stl=${CMAKE_ANDROID_STL_TYPE}")
set(${LIB_CXX} ${CMAKE_ANDROID_STL_TYPE} PARENT_SCOPE)
set(${lib_cxx} ${CMAKE_ANDROID_STL_TYPE} PARENT_SCOPE)
return()
endif()

include(CheckCXXSourceCompiles)

if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
detect_gnu_libstdcxx()
set(${LIB_CXX} "libstdc++${_CONAN_GNU_LIBSTDCXX_SUFFIX}" PARENT_SCOPE)
set(${lib_cxx} "libstdc++${_conan_gnu_libstdcxx_suffix}" PARENT_SCOPE)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "AppleClang")
set(${LIB_CXX} "libc++" PARENT_SCOPE)
set(${lib_cxx} "libc++" PARENT_SCOPE)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
# Check for libc++
detect_libcxx()
if(_CONAN_IS_LIBCXX)
set(${LIB_CXX} "libc++" PARENT_SCOPE)
if(_conan_is_libcxx)
set(${lib_cxx} "libc++" PARENT_SCOPE)
return()
endif()

# Check for libstdc++
detect_gnu_libstdcxx()
if(_CONAN_IS_GNU_LIBSTDCXX)
set(${LIB_CXX} "libstdc++${_CONAN_GNU_LIBSTDCXX_SUFFIX}" PARENT_SCOPE)
if(_conan_is_gnu_libstdcxx)
set(${lib_cxx} "libstdc++${_conan_gnu_libstdcxx_suffix}" PARENT_SCOPE)
return()
endif()

Expand Down
8 changes: 4 additions & 4 deletions tests/test_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,8 @@ def test_gnu_libstdcxx_linux(self, capfd, basic_cmake_project, compiler):
run(f"cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} "
f"-DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER={compiler}")
out, _ = capfd.readouterr()
assert "Performing Test _CONAN_IS_GNU_LIBSTDCXX - Success" in out
assert "Performing Test _CONAN_GNU_LIBSTDCXX_IS_CXX11_ABI - Success" in out
assert "Performing Test _conan_is_gnu_libstdcxx - Success" in out
assert "Performing Test _conan_gnu_libstdcxx_is_cxx11_abi - Success" in out
assert "compiler.libcxx=libstdc++11" in out
if compiler == "clang++":
assert "The CXX compiler identification is Clang" in out
Expand All @@ -490,8 +490,8 @@ def test_gnu_libstdcxx_old_abi_linux(self, capfd, basic_cmake_project):
run(f'cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} '
'-DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-D_GLIBCXX_USE_CXX11_ABI=0"')
out, _ = capfd.readouterr()
assert "Performing Test _CONAN_IS_GNU_LIBSTDCXX - Success" in out
assert "Performing Test _CONAN_GNU_LIBSTDCXX_IS_CXX11_ABI - Failed" in out
assert "Performing Test _conan_is_gnu_libstdcxx - Success" in out
assert "Performing Test _conan_gnu_libstdcxx_is_cxx11_abi - Failed" in out
assert "compiler.libcxx=libstdc++" in out

@linux
Expand Down

0 comments on commit 100970e

Please sign in to comment.