Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • CMake CMake
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,808
    • Issues 3,808
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 8
    • Merge requests 8
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • CMake
  • CMakeCMake
  • Issues
  • #20675

Closed
Open
Created May 04, 2020 by Norbert Pfeiler@npfeiler

static and shared builds of the same library

When trying to build an all-static (Windows) application, i’m currently (mis)using setting BUILD_SHARED_LIBS=FALSE to be able to implicitly (via add_library UNKNOWN) or explicitly try to influence which flavor of a library, that has both static as well as shared flavors available, is used.

This got more complicated recently (#19804 (comment 688121)), requiring:

if(NOT BUILD_SHARED_LIBS) # try to force search for static libraries if BUILD_SHARED_LIBS was disabled
    list(PREPEND CMAKE_FIND_LIBRARY_SUFFIXES .a .lib) # prefer static (*.a) over import (*.dll.a) libraries
endif()

This is all just a hacky workaround for the fact that i can’t tell find_package (or CMake globally) conceptually that i want to link to static versions of libraries, and even if individual packages provide mechanisms for selecting that, that there is no consensus on how to do that.

I plan on contributing generated CMake package configs to at least 2 additional projects now, and it pains me that i have to »design« mechanisms for the above.

And it is intended that for every different flavor (also debug/release) the build needs to be redone?

I would prefer if the it was as easy as defining 1 global (or target specific) variable to either build both flavors or handle generating differently named export sets and include them automatically in the generated package config. Or at least provide all the necessary boilerplate in the docs.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking