I want to create a static and a shared library using CMake to create the build environment. Furthermore it should create an ANSI
and a UNICODE
version.
I found this posting: Is it possible to get CMake to build both a static and shared version of the same library?
which told me that I can use multiple add_library
statements to achieve this. When I tried it, it creates the libraries fine, but the posting doesn't tell me how to set different -D
options depending on which version is built.
My CMakeLists.txt
currently looks like this:
list(APPEND SUPPORT_SOURCE
dll_main.cpp
)
add_definitions(-DBUILD_SUPPORT_DLL)
add_library(support SHARED ${SUPPORT_SOURCE} )
add_library(support_s STATIC ${SUPPORT_SOURCE} )
add_library(support_u SHARED ${SUPPORT_SOURCE} )
add_library(support_su STATIC ${SUPPORT_SOURCE} )
After all, when I build the DLL, the functions needs the __declspec(dllexport)
declaration which it should not have in the static versions. Furthermore to build the UNICODE
variant I need to pass -DUNICODE
.
So I need to know which version is built and use appropriate build flags for it for the various targets.
Another thing I don't understand is, how I can create debug builds with a different name. I usually use the pattern libname.lib
and libname_d.lib
so I can have all possible versions in a single directory to link against.