0

I know ways to get CMake to generate both a Static & Dynamic library simultaneously (avoiding the mess of multiple build trees and dual-compiles), but they mainly only work on OSX & Linux (where you get a dynamic .so/.dylib, and a static .a). Windows is a bit messier, since you get a static .lib and a dynamic .dll AND .lib, and the two .lib's have the same name but are different.

In a project I'm converting over right now, that's done manually through lots of batch files and makefiles that just place the resulting files in separate subdirectories. How can I achieve this similar behavior in CMake? (e.g. How can I make CMake build the same binary twice, once static and once dynamic, but place the results into two different subdirectories).

Yeraze
  • 3,269
  • 4
  • 28
  • 42
  • This appears to be a duplicate of [this question](http://stackoverflow.com/questions/2152077/). The accepted answer doesn't (fully) cover setting `LIBRARY_OUTPUT_DIRECTORY` (for the shared lib), `ARCHIVE_OUTPUT_DIRECTORY` (for the static lib) and `OUTPUT_NAME` (for both) using `set_target_properties()`. You would need to do that if you want the shared/static targets to have different CMake target names (which they _must_), but identical file names. As the answerer of the linked question notes, though, giving shared/static libs the same (file)name on Windows can be confusing. – evadeflow Dec 31 '13 at 16:22
  • Use GCC convention for import libraries to distinguish them from real static libraries. Say you call your library as `MyLibrary`. Then DLL is `MyLibrary.dll`, import library is `MyLibrary.dll.lib`, and static library is `MyLibrary.lib`. – Alexander Shukaev Dec 31 '13 at 18:18

0 Answers0