Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a way to add_definitions for just a single language?

CMake provides add_compile_definitions() for adding compiler definitions for all targets in the current directory; and there is also target_compile_definitions() for individual targets. But – it seems to me like the general case should be language-specific, not absolutely all targets. Why would, say, C and Rust use the same definitions?

So – is there some way to add a definition to all targets of a single language, other than one-at-a-time?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try using add_definitions at the top of the top-level CMakeLists.txt file with the $<COMPILE_LANGUAGE:languages> generator expression (requires cmake_minimum_required(VERSION 3.3)). Ex.

add_compile_definitions("$<$<COMPILE_LANGUAGE:C,CXX>:-DFOO>")

If your cmake_minimum_required is less than 3.3, I suppose you could append to CMAKE_<LANG>_FLAGS. Ex.

list(APPEND CMAKE_CXX_FLAGS "-DFOO")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading