[CMake] Compile same source file with different flags into the same library
Eric Noulard
eric.noulard at gmail.com
Tue Dec 8 05:20:47 EST 2009
2009/12/8 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.
>
>
> In my CMakeLists.txt I set the list of source files
>
> SET(AMD_SRC
> ${AMD_SOURCE_DIR}/Source/amd_aat.c
> ...)
>
> generate the names for the output files as follows
>
> STRING(REGEX REPLACE "amd_" "amd_i_" AMDI_SRC ${AMD_SRC})
> STRING(REGEX REPLACE "amd_" "amd_l_" AMDL_SRC ${AMD_SRC})
>
> and specify the compiler flags accordingly
>
> SET_SOURCE_FILES_PROPERTIES({AMDI_SRC} PROPERTIES COMPILE_FLAGS "-DDINT")
> SET_SOURCE_FILES_PROPERTIES({AMDL_SRC} PROPERTIES COMPILE_FLAGS "-DDLONG")
>
> However, the problem is that there are no physical source files named,
> e.g. amd_i_aat.c, and hence, CMake produces the following obvious error
> message:
>
> CMake Error in CMakeLists.txt:
> Cannot find source file "amd_i_aat.c". Tried extensions .c .C .c++
> .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx
>
>
> Is is possible to tell CMake that the name of the source file differs
> from that of the output file?
May be it would be easier to copy the actual source file,
what do you think of:
CONFIGURE_FILE(${AMD_SOURCE_DIR}/Source/amd_aat.c
${AMD_BINARY_DIR}/Source/${AMDL_SRC} COPYONLY)
CONFIGURE_FILE(${AMD_SOURCE_DIR}/Source/amd_aat.c
${AMD_BINARY_DIR}/Source/${AMDI_SRC} COPYONLY)
(may be you can build AMDx_SRC such as they have full path)
then you need to change your SET(AMD_SRC in order to
include AMDx_SRC.
with this scheme CMake should be pleased and I think you get the
functionnality you want
with may be a lot of [automatic] file copy from source tree to build tree.
--
Erk
Membre de l'April - « promouvoir et défendre le logiciel libre » -
http://www.april.org
More information about the CMake
mailing list