I'm a fairly new CMake user, so I apologize in advance if this question is answered trivially elsewhere. I searched through the docs and Google already to no avail.

In a project I am working on, I need to build our Win32 libraries in both cdecl and stdcall variants. The calling conventions can be controlled through a -D variable, but I am having a hard time getting CMake to modify definitions between builds of the same set of source files.

I have tried 2 techniques:

1) Use SET_SOURCE_FILES_PROPERTIES() to change the -D settings between builds.

# cdecl (default) build
ADD_LIBRARY(my_lib SHARED src/lib.c)

SET_SOURCE_FILES_PROPERTIES(src/lib.c COMPILE_FLAGS -DTURN_ON_STDCALL)
ADD_LIBRARY(my_lib_stdcall SHARED src/lib.c)

On my machine, SET_SOURCE_FILE_PROPERTIES() has the effect of setting TURN_ON_STDCALL for every build that uses src/lib.c.


2) Use ADD_DEFINITIONS() and REMOVE_DEFINITIONS().

REMOVE_DEFINITIONS(-DTURN_ON_STDCALL)
ADD_LIBRARY(my_lib SHARED src/lib.c)

ADD_DEFINITIONS(-DTURN_ON_STDCALL)
ADD_LIBRARY(my_lib_stdcall SHARED src/lib.c)

The effect of this was no different then when I used SET_SOURCE_FILES_PROPERTIES().

If I had to guess, I would suppose that lib.obj is really only being built once and simply linked twice to create the two libraries I want. What I really need is to force lib.c to be built (and linked) twice with the different -D options. Any suggestions on how I might do this? (It could also be that I'm doing this the hard way and there is a more idiomatic way to create these two libraries that doesn't involve CMake. I'll take those suggestions too :)

Thanks in advance,
Patrick
_______________________________________________
CMake mailing list
[email protected]
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to