Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define compiler flags at compile time using CMake?

add_definitions adds definition that is fixed at time when cmake (not make) is executed. How to define them when make (not cmake) is executed? The value of the definition will be an output of a custom command.

like image 488
Łukasz Lew Avatar asked Dec 11 '09 21:12

Łukasz Lew


People also ask

How do you define a flag in CMake?

Add -D define flags to the compilation of source files. Adds definitions to the compiler command line for targets in the current directory, whether added before or after this command is invoked, and for the ones in sub-directories added after.

How do I force CMake to use a specific compiler?

If you want, e.g., to use clang instead of defaulted gcc , then either: Pass -DCMAKE_C_COMPILER=<compiler> to cmake when configure the project. That way CMake will use this compiler instead of default one and on the project() call it will adjust all flags for the specified compiler.

What is Flag in compiling?

Compiler flags are options you give to gcc when it compiles a file or set of files. You may provide these directly on the command line, or your development tools may generate them when they invoke gcc. This section describes just the flags that are specific to Objective-C.


1 Answers

You may find some useful tricks here: How to run a command at compile time within Makefile generated by CMake?

like image 177
JesperE Avatar answered Oct 13 '22 12:10

JesperE