Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake check if library is static

Tags:

cmake

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.

like image 726
edA-qa mort-ora-y Avatar asked Mar 23 '11 14:03

edA-qa mort-ora-y


People also ask

How to make mathfunctions always be used in cmakelists?

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.

How do I set the build_shared_libs value in cmakelists?

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.

How to build a static library in Linux?

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.


1 Answers

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.

like image 63
Timmmm Avatar answered Oct 08 '22 08:10

Timmmm