cmake-conan
cmake-conan copied to clipboard
conan_cmake_detect_libcxx doesn't treat cmake definitions correctly
If I use the following set up to set compiler.libcxx=libstdc++11, then it works correctly:
set(_GLIBCXX_USE_CXX11_ABI 1)
conan_cmake_run(
CONANFILE conanfile.py
BUILD all)
Partial output:
-- Conan: Automatic detection of conan settings from cmake
-- Conan: Settings= -s;build_type=RelWithDebInfo;-s;compiler=gcc;-s;compiler.version=7;-s;compiler.libcxx=libstdc++11
-- Conan: checking conan executable
-- Conan: Found program /usr/local/bin/conan
-- Conan: Version found Conan version 1.26.1
-- Conan executing: /usr/local/bin/conan install /root/cryfs/conanfile.py -s build_type=RelWithDebInfo -s compiler=gcc -s compiler.version=7 -s compiler.libcxx=libstdc++11 -g=cmake --build
However, if I use add_definitions instead of set, then it doesn't work:
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=1)
conan_cmake_run(
CONANFILE conanfile.py
BUILD all)
Partial output:
-- Conan: Automatic detection of conan settings from cmake
-- Conan: Settings= -s;build_type=RelWithDebInfo;-s;compiler=gcc;-s;compiler.version=7;-s;compiler.libcxx=libstdc++
-- Conan: checking conan executable
-- Conan: Found program /usr/local/bin/conan
-- Conan: Version found Conan version 1.26.1
-- Conan executing: /usr/local/bin/conan install /root/cryfs/conanfile.py -s build_type=RelWithDebInfo -s compiler=gcc -s compiler.version=7 -s compiler.libcxx=libstdc++ -g=cmake --build
My guess is that this is because this line sets compile_options, but forgets to set the libcxx variable into the PARENT_SCOPE. If specified by a cmake variable instead of a definition, then it does set libcxx into the PARENT_SCOPE, see here.
Hi @smessmer,
Thanks a lot for the feedback.
I have been trying to reproduce your example (using gcc7, inside conanio/gcc7 docker image) but it works fine for me for both cases setting the value of the definition to 1 to use libcxx=libstdc++11 or to 0 to use libcxx=libstdc++
Could you please give me more details on how you are testing this, the environment... (are you using 0.15v from cmake-conan or the develop branch?) or even a reproducible example?
The logic behind those lines is to output all the macros defined by the compile options executing the compiler and then if the _GLIBCXX_USE_CXX11_ABI macro is found set libcxx=libstdc++11.
Thanks for your fast reply.
I have a local copy of cmake-conan v0.15 in my repository at https://github.com/cryfs/cryfs/blob/develop/cmake-utils/conan.cmake.
Here are the steps to repro:
- Set up docker image and install requirements
$ sudo docker run -ti centos:centos7 /bin/bash
[root@a0098fc49d53]# yum install git wget make centos-release-scl python3 libcurl-devel fuse-devel
[root@a0098fc49d53]# yum install devtoolset-7
[root@a0098fc49d53]# scl enable devtoolset-7 bash
[root@a0098fc49d53]# pip3 install conan
[root@a0098fc49d53]# cd ~
[root@a0098fc49d53]# wget https://github.com/Kitware/CMake/releases/download/v3.14.6/cmake-3.14.6-Linux-x86_64.sh
[root@a0098fc49d53]# chmod +x cmake-3.14.6-Linux-x86_64.sh
[root@a0098fc49d53]# ./cmake-3.14.6-Linux-x86_64.sh
/* say "y" when asked to accept the license and say "n" to the second question so that it installs into /root */
[root@a0098fc49d53]# export PATH=$PATH:/root/bin
- Clone and build CryFS
[root@a0098fc49d53]# git clone https://github.com/cryfs/cryfs
[root@a0098fc49d53]# cd cryfs
[root@a0098fc49d53]# git checkout 6f94834c90d40f2d1261471213416ffe605ece54
[root@a0098fc49d53]# mkdir build
[root@a0098fc49d53]# cd build
[root@a0098fc49d53]# cmake ..
Notice that it correctly sets up libstdc++11. Log excerpt:
-- Conan executing: /usr/local/bin/conan install /root/cryfs/conanfile.py -s build_type=RelWithDebInfo -s compiler=gcc -s compiler.version=7 -s compiler.libcxx=libstdc++ -g=cmake --build
- Check out this other commit, which just changes
set(_GLIBCXX_USE_CXX11_ABI 1)toadd_definitions(-D_GLIBCXX_USE_CXX11_ABI=1)and rebuild:
/* we're still in the `build` directory */
[root@a0098fc49d53]# git checkout 145880e1f843ac23429453c38a6cc30987e69382
[root@a0098fc49d53]# rm -rf *
[root@a0098fc49d53]# cmake ..
Notice that it now uses libstdc++ and not libstdc++11. Log excerpt:
-- Conan executing: /usr/local/bin/conan install /root/cryfs/conanfile.py -s build_type=RelWithDebInfo -s compiler=gcc -s compiler.version=7 -s compiler.libcxx=libstdc++ -g=cmake --build
Note also that CentOS7 has some weirdness when it comes to libstdc++11, its compiler just seems to ignore the setting (see https://github.com/conan-io/conan/issues/7264), but that's likely unrelated.
Hi @smessmer,
Now I have been able to reproduce the issue, as said in the comments in the other issue there's not much that can be done here in the conan side because the compiler will always ignore that definition.
So, whatever you pass you are always compiling with the old ABI. And as the compiler is ignoring that always, in fact, what is working correctly is the case where you add add_definitions(-D_GLIBCXX_USE_CXX11_ABI=1) because when you get the definitions from the output of the compiler here: https://github.com/conan-io/cmake-conan/blob/4ea2603339e3145c88387eaa3f274202dbf11f41/conan.cmake#L267-L271 the line #define _GLIBCXX_USE_CXX11_ABI 1 won't be found (is set to 0) and will detect in fact the correct configuration.
conan_cmake could throw a warning but that would not solve the issue, it has to be adressed in the compiler side.
Oh I see, so it actually is related to the other issue. That makes sense. Thanks for investigating.
On July 2, 2020 00:09:35 Carlos Zoido [email protected] wrote:
Hi @smessmer, Now I have been able to reproduce the issue, as said in the comments in the other issue there's not much that can be done here in the conan side because the compiler will always ignore that definition. So, whatever you pass you are always compiling with the old ABI. And as the compiler is ignoring that always, in fact, what is working correctly is the case where you add add_definitions(-D_GLIBCXX_USE_CXX11_ABI=1) because when you get the definitions from the output of the compiler here: https://github.com/conan-io/cmake-conan/blob/4ea2603339e3145c88387eaa3f274202dbf11f41/conan.cmake#L267-L271 the line #define _GLIBCXX_USE_CXX11_ABI 1 won't be found (is set to 0) and will detect in fact the correct configuration. conan_cmake could throw a warning but that would not solve the issue, it has to be adressed in the compiler side. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.