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,194
    • Issues 3,194
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 16
    • Merge Requests 16
  • 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
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • CMake
  • CMakeCMake
  • Issues
  • #17246

Closed
Open
Opened Aug 31, 2017 by Deception666@Deception666Contributor

target_link_libraries Generates Error On :: Targets That Are Not Dfined But Also Generates A Valid Solution

It is interesting that target_link_libraries will issue an error for target libraries expressed with double colons but still generates a valid solution. I would have expected that with CMP0028 that the target_link_libraries would have thrown a fatal error.

"The OLD behavior for this policy is to search for targets, then files on disk, even if the search term contains double-colons. The NEW behavior for this policy is to issue a FATAL_ERROR if a link dependency contains double-colons but is not an IMPORTED target or an ALIAS target."

cmake_minimum_required(VERSION 3.8.0 FATAL_ERROR)
cmake_policy(SET CMP0028 NEW)
project(cmake-target-failure-test)
add_library(test-missing-target SHARED main.cpp)
target_link_libraries(test-missing-target PUBLIC CCU::ccu)

I get the following output:

$ cmake -G "Visual Studio 15" ..
-- The C compiler identification is MSVC 19.10.25019.0
-- The CXX compiler identification is MSVC 19.10.25019.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.10.25017/bin/HostX64/x86/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.10.25017/bin/HostX64/x86/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.10.25017/bin/HostX64/x86/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.10.25017/bin/HostX64/x86/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
CMake Error at CMakeLists.txt:7 (add_library):
  Target "test-missing-target" links to target "CCU::ccu" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?


CMake Error at CMakeLists.txt:7 (add_library):
  Target "test-missing-target" links to target "CCU::ccu" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?


CMake Error at CMakeLists.txt:7 (add_library):
  Target "test-missing-target" links to target "CCU::ccu" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?


CMake Error at CMakeLists.txt:7 (add_library):
  Target "test-missing-target" links to target "CCU::ccu" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?


CMake Error at CMakeLists.txt:7 (add_library):
  Target "test-missing-target" links to target "CCU::ccu" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?


-- Generating done
-- Build files have been written to: D:/Code/TestCode/cmake-target-failure-test/build

MINGW64 /d/Code/TestCode/cmake-target-failure-test/build
$ echo $?
1

Is this expected behavior or a bug? While it appears that the return code would allow build jobs to fail correctly and notify the developer, I have many developers that do not look at the output of CMake and blindly start the build to only find out 30 to 45 minutes later that it will not complete because CCU::ccu.lib cannot be found for 2015 generators. I have had some developers show me the link properties of Visual Studio with that library defined as CCU::ccu-NOTFOUND.

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#17246