I had to rebuild CMocka the other day for one of my projects, and I was initially pretty confused as to why the CMocka build system was only generating dynamic libraries. The documentation didn’t mention anything obvious about static libraries either.
I’m still new to CMake and wasn’t aware of the DefineOptions.cmake
file, which clearly indicates the static library option. Instead I poked around and discovered the WITH_STATIC_LIB
option had to be defined in order for a static library to be generated.
For others who may also be confused, simply define the WITH_STATIC_LIB
option during the initial cmake
build step:
cmake ../ -DWITH_STATIC_LIB=true
2023 Update
The option has since changed to BUILD_SHARED_LIBS
with the opposite polarity:
cmake ../ -DBUILD_SHARED_LIBS=OFF
Happy hacking!
Thank you!
… and to others landing here with version 1.1.7, it is now:
-DBUILD_SHARED_LIBS=OFF