operations |
comment | "parent_author":"",<br>"parent_permlink":"cmake",<br>"author":"mtl1979",<br>"permlink":"how-to-force-cmake-to-link-against-static-version-of-library",<br>"title":"How to force cmake to link against static version of library...",<br>"body":"Sometimes it is necessary to force cmake project to link against static version of system library if available,<br> it can be done using following code snippets,<br> which are from cmake package for Ubuntu. Replace <code>Boost<\/code> with your own package name and <code>boost<\/code> with package name written in all minuscule (lower-case) letters.\n\nIn <code>FindBoost.cmake<\/code>:\n\nAdd before <code>find_library()<\/code>:\n```\nif(Boost_USE_STATIC_LIBS)\n set(_boost_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES $ CMAKE_FIND_LIBRARY_SUFFIXES )\n if(WIN32)\n list(INSERT CMAKE_FIND_LIBRARY_SUFFIXES 0 .lib .a)\n else()\n set(CMAKE_FIND_LIBRARY_SUFFIXES .a)\n endif()\nendif()\n```\nFirst it will store original contents of variable <code>CMAKE_FIND_LIBRARY_SUFFIXES<\/code> to temporary variable,<br> then it will prepend known suffixes of static libraries to the variable. Original contents of the variable will be restored in the following code block.\n\nAdd after <code>find_library()<\/code>:\n```\nif(Boost_USE_STATIC_LIBS)\n set(CMAKE_FIND_LIBRARY_SUFFIXES $ _boost_ORIG_CMAKE_LIBRARY_SUFFIXES )\nendif()\n```\n\nIn <code>CMakeLists.txt<\/code>:\n```\nif(STATIC)\n set(Boost_USE_STATIC_LIBS ON)\nendif()\nfind_package(Boost REQUIRED COMPONENTS system filesystem thread date_time chrono regex serialization program_options)\n```\n\n<code>REQUIRED<\/code> means the library must be found for project configuration to succeed.\n<code>COMPONENTS<\/code> means following package components must be available.\n",<br>"json_metadata":" \"app\":\"steempeak\/2020.07.1\",<br>\"format\":\"markdown\",<br>\"tags\":[\"cmake\",<br>\"development\",<br>\"programming\" ,<br>\"image\":[ " |
|