[CMake] Using cmake to build a static library

Denis Carniel denis.carniel at loginpeople.com
Thu Sep 15 02:49:44 EDT 2011


Hi,

I came across cmake few weeks ago as a very interesting way to build projects for multiple platforms. It allows us at work to use a common code base for multiple platforms without actual duplication which is really neat.

Though we're facing an issue related to the fact cmake isn't the only tool involved in our build process. We have split our code between the core logic which is compiled in C++ for multiple platforms (windows x86 and x86_64, Mac OSX and in the future linux) then based on that core logic we would like to produce SDKs for each platform using their specific features (for easier integration in projects).

The problem is the following: The core logic is meant to be a static library (.lib on windows, .a on Mac / Linux) and then another project should pick up that library and include it into an executable. That final project is (a) not linked with the original cmake project (b) potentially not even built by cmake. For those reasons we'd like that the generated static library include its own dependencies in order to avoid dragging a long list of dependencies, unfortunately that does not seem to be be case in the current state of things.

If I set the type of my output to "SHARED" (through the "ADD_LIBRARY" command), I see all dependencies appear in the Visual Studio project and the produced DLL seems correct. Though if the type is set to "STATIC" (the one we want), the dependencies are simply not passed to the Visual Studio project (AdditionalDependencies & AdditionalLibraryDirectories are not set for VCLibrarianTool).

Hence my overall question: How can I have cmake produce a static library in which dependencies are linked ?

Thanks in advance for your help.
Denis

PS: I know DLLs work on windows but those are not an option, because of deployment constraints we need to produce a single executable file in the end.



More information about the CMake mailing list