Search code examples
c++cmakestatic-linkingpoco-librariesnmake

Building POCO libraries with CMake in Windows


I am currently building POCO libraries with CMake like this:

cmake -DCMAKE_BUILD_TYPE=Debug -G "NMake Makefiles" -DPOCO_STATIC .
nmake

It all works fine, except for the fact that libraries aren't created with suffix mtd.lib or mdd.lib, just d.lib. Because of this, then my application fails to link to PocoFoundationsmdd.lib since the file doesn't exist.

Is there any keyword to pass in the cmake command so that it builds with the right prefix? I know that from Visual Studio there are configurations like debug_static_md one can select, but is it possible to do it through cmake without modifying the CMakelists.txt?


Solution

  • It was as simple as adding add_definitions( -DPOCO_STATIC -DPOCO_NO_AUTOMATIC_LIBS) to the CMakelists.txt that is consuming the POCO libraries compiled with cmake. That effectively disables the header (*.h) definitions that attempt to link from the code:

    #if defined(_MSC_VER)
        #if !defined(POCO_NO_AUTOMATIC_LIBS) && !defined(Crypto_EXPORTS)
            #pragma comment(lib, "PocoXXX" POCO_LIB_SUFFIX)
        #endif
    #endif