check_cxx_compiler_flag usage

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

check_cxx_compiler_flag usage

Damien R
Hi,

I am trying to use CHECK_CXX_COMPILER_FLAG with cmake 3.9 to check if the compiler supports asan.
The CMakeLists.txt is:
cmake_minimum_required(VERSION 3.9)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-fsanitize=address" COMPILER_SUPPORT_FLAG)

I always got:
-- Performing Test COMPILER_SUPPORT_FLAG - Failed

Even if the documentation say that CHECK_CXX_COMPILER_FLAG sets CMAKE_REQUIRED_DEFINITIONS by the name of the macro I thought that it would work.
Can you tell me why CHECK_CXX_COMPILER_FLAG use CMAKE_REQUIRED_DEFINITIONS instead of CMAKE_REQUIRED_FLAGS
and what is the official way for checking this flag?

Regards,

Damien R.


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: check_cxx_compiler_flag usage

Lectem
That's probably an issue with linking because it doesn't know it has to link asan. 
Either way, settings asan flags is the job of the user, not the cmakelists.txt.
Such things should be kept in tool chain or config files IMHO. 
You can try running cmake in verbose mode for more information. 

Le jeu. 7 déc. 2017 à 09:25, Damien R <[hidden email]> a écrit :
Hi,

I am trying to use CHECK_CXX_COMPILER_FLAG with cmake 3.9 to check if the compiler supports asan.
The CMakeLists.txt is:
cmake_minimum_required(VERSION 3.9)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-fsanitize=address" COMPILER_SUPPORT_FLAG)

I always got:
-- Performing Test COMPILER_SUPPORT_FLAG - Failed

Even if the documentation say that CHECK_CXX_COMPILER_FLAG sets CMAKE_REQUIRED_DEFINITIONS by the name of the macro I thought that it would work.
Can you tell me why CHECK_CXX_COMPILER_FLAG use CMAKE_REQUIRED_DEFINITIONS instead of CMAKE_REQUIRED_FLAGS
and what is the official way for checking this flag?

Regards,

Damien R.

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: check_cxx_compiler_flag usage

Eric Noulard
In reply to this post by Damien R

Not really answering the question but 
did you try to use an existing CMake module for handling sanitizers config?

I find this one https://github.com/arsenm/sanitizers-cmake very effective, with
modern CMake target oriented features.




2017-12-07 9:24 GMT+01:00 Damien R <[hidden email]>:
Hi,

I am trying to use CHECK_CXX_COMPILER_FLAG with cmake 3.9 to check if the compiler supports asan.
The CMakeLists.txt is:
cmake_minimum_required(VERSION 3.9)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-fsanitize=address" COMPILER_SUPPORT_FLAG)

I always got:
-- Performing Test COMPILER_SUPPORT_FLAG - Failed

Even if the documentation say that CHECK_CXX_COMPILER_FLAG sets CMAKE_REQUIRED_DEFINITIONS by the name of the macro I thought that it would work.
Can you tell me why CHECK_CXX_COMPILER_FLAG use CMAKE_REQUIRED_DEFINITIONS instead of CMAKE_REQUIRED_FLAGS
and what is the official way for checking this flag?

Regards,

Damien R.


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake



--
Eric

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: check_cxx_compiler_flag usage

Eric Noulard
In reply to this post by Lectem


2017-12-07 9:35 GMT+01:00 Clément Gregoire <[hidden email]>:
That's probably an issue with linking because it doesn't know it has to link asan. 
Either way, settings asan flags is the job of the user, not the cmakelists.txt.
Such things should be kept in tool chain or config files IMHO. 

I do not agree with you.

Most of the time you will have to handle various type of build for the same toolchain: i.e. debug, optimize, profiling etc...
sanitizing is another case of build type. 
I wouldn't put it in the toolchain since it could work with various toolchain and at least with GCC or Clang.

I don't know what you mean by "config file".
 
You can try running cmake in verbose mode for more information. 

Le jeu. 7 déc. 2017 à 09:25, Damien R <[hidden email]> a écrit :
Hi,

I am trying to use CHECK_CXX_COMPILER_FLAG with cmake 3.9 to check if the compiler supports asan.
The CMakeLists.txt is:
cmake_minimum_required(VERSION 3.9)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-fsanitize=address" COMPILER_SUPPORT_FLAG)

I always got:
-- Performing Test COMPILER_SUPPORT_FLAG - Failed

Even if the documentation say that CHECK_CXX_COMPILER_FLAG sets CMAKE_REQUIRED_DEFINITIONS by the name of the macro I thought that it would work.
Can you tell me why CHECK_CXX_COMPILER_FLAG use CMAKE_REQUIRED_DEFINITIONS instead of CMAKE_REQUIRED_FLAGS
and what is the official way for checking this flag?

Regards,

Damien R.

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake



--
Eric

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: check_cxx_compiler_flag usage

Lectem

Well to be honest, as long as it's done correctly I don't really have any issues with it.
The issue is that I've seen many Cmakelists.txt changing CMAKE_CXX_FLAGS directly and forcing it upon the user by adding a target_add_* which most of the time is not what you want.
Adding a new configuration type is indeed the best solution (though it forces it on all the targets), it's also what I use for my coverage builds.


Le jeu. 7 déc. 2017 à 10:38, Eric Noulard <[hidden email]> a écrit :
2017-12-07 9:35 GMT+01:00 Clément Gregoire <[hidden email]>:
That's probably an issue with linking because it doesn't know it has to link asan. 
Either way, settings asan flags is the job of the user, not the cmakelists.txt.
Such things should be kept in tool chain or config files IMHO. 

I do not agree with you.

Most of the time you will have to handle various type of build for the same toolchain: i.e. debug, optimize, profiling etc...
sanitizing is another case of build type. 
I wouldn't put it in the toolchain since it could work with various toolchain and at least with GCC or Clang.

I don't know what you mean by "config file".
 
You can try running cmake in verbose mode for more information. 

Le jeu. 7 déc. 2017 à 09:25, Damien R <[hidden email]> a écrit :
Hi,

I am trying to use CHECK_CXX_COMPILER_FLAG with cmake 3.9 to check if the compiler supports asan.
The CMakeLists.txt is:
cmake_minimum_required(VERSION 3.9)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-fsanitize=address" COMPILER_SUPPORT_FLAG)

I always got:
-- Performing Test COMPILER_SUPPORT_FLAG - Failed

Even if the documentation say that CHECK_CXX_COMPILER_FLAG sets CMAKE_REQUIRED_DEFINITIONS by the name of the macro I thought that it would work.
Can you tell me why CHECK_CXX_COMPILER_FLAG use CMAKE_REQUIRED_DEFINITIONS instead of CMAKE_REQUIRED_FLAGS
and what is the official way for checking this flag?

Regards,

Damien R.

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake



--
Eric

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: check_cxx_compiler_flag usage

Damien R
In reply to this post by Eric Noulard
Thank you for pointing that. It increments the number of people using CMAKE_REQUIRED_FLAGS "trick" to make it working with check_cxx_compiler_flag.

But my question is more about :
 - why they coded CHECK_CXX_COMPILER_FLAG this way?
 - is my usage valid or not? If not what should I do? If yes, is it a bug?

Regards,

Damien R.



On 7 December 2017 at 10:35, Eric Noulard <[hidden email]> wrote:

Not really answering the question but 
did you try to use an existing CMake module for handling sanitizers config?

I find this one https://github.com/arsenm/sanitizers-cmake very effective, with
modern CMake target oriented features.




2017-12-07 9:24 GMT+01:00 Damien R <[hidden email]>:
Hi,

I am trying to use CHECK_CXX_COMPILER_FLAG with cmake 3.9 to check if the compiler supports asan.
The CMakeLists.txt is:
cmake_minimum_required(VERSION 3.9)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-fsanitize=address" COMPILER_SUPPORT_FLAG)

I always got:
-- Performing Test COMPILER_SUPPORT_FLAG - Failed

Even if the documentation say that CHECK_CXX_COMPILER_FLAG sets CMAKE_REQUIRED_DEFINITIONS by the name of the macro I thought that it would work.
Can you tell me why CHECK_CXX_COMPILER_FLAG use CMAKE_REQUIRED_DEFINITIONS instead of CMAKE_REQUIRED_FLAGS
and what is the official way for checking this flag?

Regards,

Damien R.


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake



--
Eric


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: check_cxx_compiler_flag usage

Lectem
Your usage of check_cxx_compiler_flag is correct, it's probably just missing link flags or something.
Can you check the error log of cmake to know why it fails to compile ? It is in your buildfolder : CMakeFiles/CMakeError.log

Here's how I did it for coverage by the way (not perfect, but was enough for my usage):

https://github.com/Lectem/cpp-boilerplate/blob/master/cmake/Coverage.cmake#L42




2017-12-07 14:31 GMT+01:00 Damien R <[hidden email]>:
Thank you for pointing that. It increments the number of people using CMAKE_REQUIRED_FLAGS "trick" to make it working with check_cxx_compiler_flag.

But my question is more about :
 - why they coded CHECK_CXX_COMPILER_FLAG this way?
 - is my usage valid or not? If not what should I do? If yes, is it a bug?

Regards,

Damien R.



On 7 December 2017 at 10:35, Eric Noulard <[hidden email]> wrote:

Not really answering the question but 
did you try to use an existing CMake module for handling sanitizers config?

I find this one https://github.com/arsenm/sanitizers-cmake very effective, with
modern CMake target oriented features.




2017-12-07 9:24 GMT+01:00 Damien R <[hidden email]>:
Hi,

I am trying to use CHECK_CXX_COMPILER_FLAG with cmake 3.9 to check if the compiler supports asan.
The CMakeLists.txt is:
cmake_minimum_required(VERSION 3.9)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-fsanitize=address" COMPILER_SUPPORT_FLAG)

I always got:
-- Performing Test COMPILER_SUPPORT_FLAG - Failed

Even if the documentation say that CHECK_CXX_COMPILER_FLAG sets CMAKE_REQUIRED_DEFINITIONS by the name of the macro I thought that it would work.
Can you tell me why CHECK_CXX_COMPILER_FLAG use CMAKE_REQUIRED_DEFINITIONS instead of CMAKE_REQUIRED_FLAGS
and what is the official way for checking this flag?

Regards,

Damien R.


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake



--
Eric


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: check_cxx_compiler_flag usage

Damien R
check_cxx_compiler_flag uses CMAKE_REQUIRED_DEFINITIONS. For me its means that only "-DSOME_FLAG=VALUE" should be tested with this macro and I think that the name is misleading.
Some people define CMAKE_REQUIRED_FLAGS / CMAKE_REQUIRED_LIBRARIES before invoking check_cxx_compiler_flag but I think that they should use check_cxx_source_compiles.
In your case I would use CMAKE_REQUIRED_FLAGS and check_cxx_source_compiles.

But as I am not the developer which has written this cmake code there may be some points that invalidate what I just said.

Regards,

Damien R.


On 7 December 2017 at 15:13, Clément Gregoire <[hidden email]> wrote:
Your usage of check_cxx_compiler_flag is correct, it's probably just missing link flags or something.
Can you check the error log of cmake to know why it fails to compile ? It is in your buildfolder : CMakeFiles/CMakeError.log

Here's how I did it for coverage by the way (not perfect, but was enough for my usage):

https://github.com/Lectem/cpp-boilerplate/blob/master/cmake/Coverage.cmake#L42




2017-12-07 14:31 GMT+01:00 Damien R <[hidden email]>:
Thank you for pointing that. It increments the number of people using CMAKE_REQUIRED_FLAGS "trick" to make it working with check_cxx_compiler_flag.

But my question is more about :
 - why they coded CHECK_CXX_COMPILER_FLAG this way?
 - is my usage valid or not? If not what should I do? If yes, is it a bug?

Regards,

Damien R.



On 7 December 2017 at 10:35, Eric Noulard <[hidden email]> wrote:

Not really answering the question but 
did you try to use an existing CMake module for handling sanitizers config?

I find this one https://github.com/arsenm/sanitizers-cmake very effective, with
modern CMake target oriented features.




2017-12-07 9:24 GMT+01:00 Damien R <[hidden email]>:
Hi,

I am trying to use CHECK_CXX_COMPILER_FLAG with cmake 3.9 to check if the compiler supports asan.
The CMakeLists.txt is:
cmake_minimum_required(VERSION 3.9)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-fsanitize=address" COMPILER_SUPPORT_FLAG)

I always got:
-- Performing Test COMPILER_SUPPORT_FLAG - Failed

Even if the documentation say that CHECK_CXX_COMPILER_FLAG sets CMAKE_REQUIRED_DEFINITIONS by the name of the macro I thought that it would work.
Can you tell me why CHECK_CXX_COMPILER_FLAG use CMAKE_REQUIRED_DEFINITIONS instead of CMAKE_REQUIRED_FLAGS
and what is the official way for checking this flag?

Regards,

Damien R.


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake



--
Eric


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake



--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: check_cxx_compiler_flag usage

Lectem
Sorry I got confused in what you were trying to say.
It indeed seems to be an error, as checking if a compiler supports some defines does not make sense. Might be that an error occurred when COMPILE_FLAGS became COMPILE_OPTIONS or something. 
I would suggest opening an issue on cmake gitlab about it. (I also added the cmake-dev list to cc)  

However, it does indeed work for me, the script I linked before really tries to use the - -coverage, and fails accordingly when using msvc, and works with GCC. It wouldn't surprise me if cmake had some fallback when detecting options in the definition variable. 


I still think that checking the CMakeError.log to see what command is used for the test in your case would be interesting to know what really happens in your case. 

Regards, 
Lectem. 

Le jeu. 7 déc. 2017 à 22:04, Damien R <[hidden email]> a écrit :
check_cxx_compiler_flag uses CMAKE_REQUIRED_DEFINITIONS. For me its means that only "-DSOME_FLAG=VALUE" should be tested with this macro and I think that the name is misleading.
Some people define CMAKE_REQUIRED_FLAGS / CMAKE_REQUIRED_LIBRARIES before invoking check_cxx_compiler_flag but I think that they should use check_cxx_source_compiles.
In your case I would use CMAKE_REQUIRED_FLAGS and check_cxx_source_compiles.

But as I am not the developer which has written this cmake code there may be some points that invalidate what I just said.

Regards,

Damien R.


On 7 December 2017 at 15:13, Clément Gregoire <[hidden email]> wrote:
Your usage of check_cxx_compiler_flag is correct, it's probably just missing link flags or something.
Can you check the error log of cmake to know why it fails to compile ? It is in your buildfolder : CMakeFiles/CMakeError.log

Here's how I did it for coverage by the way (not perfect, but was enough for my usage):

https://github.com/Lectem/cpp-boilerplate/blob/master/cmake/Coverage.cmake#L42




2017-12-07 14:31 GMT+01:00 Damien R <[hidden email]>:
Thank you for pointing that. It increments the number of people using CMAKE_REQUIRED_FLAGS "trick" to make it working with check_cxx_compiler_flag.

But my question is more about :
 - why they coded CHECK_CXX_COMPILER_FLAG this way?
 - is my usage valid or not? If not what should I do? If yes, is it a bug?

Regards,

Damien R.



On 7 December 2017 at 10:35, Eric Noulard <[hidden email]> wrote:

Not really answering the question but 
did you try to use an existing CMake module for handling sanitizers config?

I find this one https://github.com/arsenm/sanitizers-cmake very effective, with
modern CMake target oriented features.




2017-12-07 9:24 GMT+01:00 Damien R <[hidden email]>:
Hi,

I am trying to use CHECK_CXX_COMPILER_FLAG with cmake 3.9 to check if the compiler supports asan.
The CMakeLists.txt is:
cmake_minimum_required(VERSION 3.9)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-fsanitize=address" COMPILER_SUPPORT_FLAG)

I always got:
-- Performing Test COMPILER_SUPPORT_FLAG - Failed

Even if the documentation say that CHECK_CXX_COMPILER_FLAG sets CMAKE_REQUIRED_DEFINITIONS by the name of the macro I thought that it would work.
Can you tell me why CHECK_CXX_COMPILER_FLAG use CMAKE_REQUIRED_DEFINITIONS instead of CMAKE_REQUIRED_FLAGS
and what is the official way for checking this flag?

Regards,

Damien R.


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake



--
Eric


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake



--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake