I am learning cmake on windows.
I read and run this example so that I can build both static and shared libraries from one visual studio project.
I found this command:
add_library(math SHARED ${MATH_SOURCES} ${SIMPLE_FUNCTION_SOURCES} ${ADVANCED_FUNCTION_SOURCES})
According to my understanding, this command is building shared library. Also, from here, if I want to build static and shared library, I have to do it by two projects.
So, why the first example I used can build both libraries from one Visual Studio project?
Edit
Thanks for Florian
, the key point is in MathExports.h
. To let people easier to see, I put the file here:
#ifndef MathExports_h
#define MathExports_h
#ifdef _WIN32
#ifdef math_EXPORTS
#define MATH_EXPORT __declspec( dllexport )
#else
#define MATH_EXPORT __declspec( dllimport )
#endif
#else
#define MATH_EXPORT
#endif
#endif // MathExports_h