[CMake] Compile same source file with different flags into the same library

Hendrik Sattler post at hendrik-sattler.de
Tue Dec 8 05:54:22 EST 2009


Zitat von Matthias Moeller <matthias.moeller at math.tu-dortmund.de>:

> I try to write a cmake file for some external library (from the sparse
> suite).
> In the provided makefile a single source file is compiled twice with
> different compiler flags, e.g.,
>
> $(C) -DDINT -c ../Source/amd_aat.c -o amd_i_aat.o
> $(C) -DDLONG -c ../Source/amd_aat.c -o amd_l_aat.o
>
> and finally all object files are combined in a single library.

That is really not good style. It is much easier and more explicit to  
do _in_the_code_ what you need. Done hide it in the build system:

amd_i_aat.c:
#define DINT
#include "amd_aat.c"

amd_l_aat.c:
#define DLONG
#include "amd_aat.c"

Then only add those two to your target.

HS




More information about the CMake mailing list