Skip to content
GitLab
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 4,103
    • Issues 4,103
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 17
    • Merge requests 17
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and 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
  • CMakeCMake
  • CMakeCMake
  • Issues
  • #21889
Closed
Open
Issue created Mar 04, 2021 by Stewart D. Smith@sdsmith

Makefile generators use wrong relative path for build subdirectories under the source directory but not under the main build directory

cmake version 3.20.0-rc1

When setting FETCHCONTENT_SOURCE_DIR_<ucName> using the generators "NMake Makefile" and "Unix Makefile", the generated CMakeFiles/Makefile2 file mixes up relative path names and absolute path names when referring to the target associated with the set FETCHCONTENT_SOURCE_DIR_<ucName>.

This does not happen when using the "Visual Studio 16 2019" generator and building the resulting solution.

See my main project CMakeLists.txt (rtek_CMakeLists.txt), the dependency CMakeLists.txt (sdslib_CMakeLists.txt) and the generated Makefile2 attached.

Error:

make[1]: *** No rule to make target '../_deps/sdslib-build/CMakeFiles/sdslib.dir/all', needed by 'CMakeFiles/rtek.dir/all'.  Stop.
make: *** [Makefile:91: all] Error 2

Relevant part of my file structure:

repos/
  rtek/
    _deps/
    build/
      CMakeFiles/
        Makefile2
    CMakeLists.txt
  sdslib-cpp/
    CMakeLists.txt

Configure & build steps:

cd repos/rtek
cmake -S. -B./build -G"NMake Makefiles" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DFETCHCONTENT_SOURCE_DIR_SDSLIB="../sdslib-cpp"
cmake --build build
  • I tried using an absolute path with FETCHCONTENT_SOURCE_DIR_SDSLIB, but that had no effect.

Relevant parts of Makefile2:

# refers to sdslib.dir\all by relative path name
CMakeFiles\rtek.dir\all: ..\_deps\sdslib-build\CMakeFiles\sdslib.dir\all
# ...
# sdslib.dir\all defined by full path name
C:\Users\stewa\source\repos\rtek\_deps\sdslib-build\CMakeFiles\sdslib.dir\all:
# ...
# sdslib-build/all refers to sdslib.dir/all as absolute path
C:/Users/stewa/source/repos/rtek/_deps/sdslib-build/all: C:/Users/stewa/source/repos/rtek/_deps/sdslib-build/CMakeFiles/sdslib.dir/all

Doing the following find-and-replace in Makefile2 fixes the generated build:

  • C:/Users/stewa/source/repos/rtek/_deps/sdslib-build/CMakeFiles/sdslib.dir/all -> ../_deps/sdslib-build/CMakeFiles/sdslib.dir/all
  • C:/Users/stewa/source/repos/rtek/_deps/sdslib-build/all -> ../_deps/sdslib-build/all
Edited Mar 06, 2021 by Craig Scott
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking