Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
CMake
CMake
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,235
    • Issues 3,235
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 14
    • Merge Requests 14
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI / CD
    • Repository
    • Value Stream
  • External Wiki
    • External Wiki
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • CMake
  • CMakeCMake
  • Issues
  • #21517

Closed
Open
Opened Nov 28, 2020 by Craig Scott@craig.scottMaintainer

OPTIMIZE_DEPENDENCIES doesn't optimise basic case for Ninja

Consider the following minimal project

CMakeLists.txt

cmake_minimum_required(VERSION 3.19)
project(optdep)

add_library(myStatic STATIC func.cpp)
add_library(myShared SHARED impl.cpp)

target_link_libraries(myStatic PRIVATE myShared)

set_target_properties(myStatic PROPERTIES OPTIMIZE_DEPENDENCIES YES)

func.cpp

#include "impl.h"

int func()
{
    return 42 + impl();
}

impl.cpp

#error I should not be built

impl.h

int impl();

Running CMake on the above project and building just the myStatic target should result in func.cpp being compiled and the myStatic static library being built, but the myShared library should NOT be built due to the OPTIMIZE_DEPENDENCIES property on myStatic. This works for the Unix Makefiles, Xcode and Visual Studio generators, but not for Ninja. Ninja still tries to compile impl.cpp.

Edited Dec 27, 2020 by Craig Scott
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: cmake/cmake#21517