Is there a way to check if a found library is a static library? In order to find the library I do this:
IF(WIN32)
SET(CMAKE_FIND_LIBRARY_SUFFIXES .lib)
ELSE()
SET(CMAKE_FIND_LIBRARY_SUFFIXES .a)
ENDIF()
find_library(QUANTLIB_LIBRARY NAMES QuantLib PATHS ${QUANTLIB_LIBRARY_SEARCH})
But on windows a .lib
could be the symbol file for a DLL. I need to ensure this is actually the static form of the library, otherwise linking later will result in hard-to-understand error messages.
In case you're wondering, I don't really want to use a satic library, but QuantLib is broken with respect to multithreading and shared libraries. This is my best chance at getting it working correctly: statically link to one of my shared libraries.
The first step is to update the starting section of the top-level CMakeLists.txt to look like: Now that we have made MathFunctions always be used, we will need to update the logic of that library. So, in MathFunctions/CMakeLists.txt we need to create a SqrtLibrary that will conditionally be built and installed when USE_MYMATH is enabled.
To accomplish this we need to add BUILD_SHARED_LIBS to the top-level CMakeLists.txt. We use the option () command as it allows users to optionally select if the value should be ON or OFF.
Moreover, to build a static library, you need not only a compiler, but also a linker and other auxiliary programs, although we do not see them in the logs, but if you look at the created file ./build/CMakeCache.txt then there you will find more complete information on which auxiliary programs were exhibited.
If the library is added as a target properly you should be able to do something like this.
get_target_property(target_type your_target_name TYPE)
if (target_type STREQUAL STATIC_LIBRARY)
...
See TYPE
for details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With