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,924
    • Issues 3,924
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 17
    • Merge requests 17
  • 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
  • #18815
Closed
Open
Created Jan 18, 2019 by Peter Wu@LekensteynContributor

AUTOMOC: generated files include full relative path, breaking certain reproducible builds

CMake currently invokes moc in a way such that the relative path between the source and build directory affects the build. Steps to reproduce:

  1. Put the following project in the src directory.
  2. mkdir ../build && cd ../build
  3. cmake -GNinja ../src
  4. ninja
  5. grep 'my_label.h"' qtui_autogen/IMAN36LHMA/moc_my_label.cpp

Expected result: The included header is relative, for example widgets/my_label.h or my_label.h (depending on the include directories).

Actual result: #include "../../../src/widgets/my_label.h"

Further information: The command invoked by cmake -E cmake_autogen /tmp/x/build/CMakeFiles/qtui_autogen.dir/AutogenInfo.cmake "" is:

/usr/bin/moc
 -I/usr/include/qt
 -I/usr/include/qt/QtWidgets
 -I/usr/include/qt/QtGui
 -I/usr/include/qt/QtCore
 -I/usr/lib/qt/mkspecs/linux-g++
 -I/usr/include
 -DQT_CORE_LIB
 -DQT_GUI_LIB
 -DQT_NO_DEBUG
 -DQT_WIDGETS_LIB
 --include
 /tmp/x/build/qtui_autogen/moc_predefs.h
 -o
 /tmp/x/build/qtui_autogen/IMAN36LHMA/moc_my_label.cpp
 /tmp/x/src/widgets/my_label.h

It appears that (for at least Qt 5, I did not check older versions), the include prefix can be controlled with the -p option. The special value ./ will avoid adding any prefix at all (#include "my_label.h"). Any other prefix will be displayed verbatim (-pwidgets results in #include "widgets/my_label.h").

Could CMake be modified to avoid Qt moc from calculating such relative paths (by using the -p option)? Would there be any issues if this happened by default?

This issue is now documented at https://reproducible-builds.org/docs/deterministic-build-systems/#cmake-notes

Reproducer

CMakeLists.txt

cmake_minimum_required(VERSION 3.5)
project(TestMoc LANGUAGES CXX)
set(CMAKE_AUTOMOC ON)
find_package(Qt5 COMPONENTS Widgets REQUIRED)
add_library(qtui widgets/my_label.cpp)
target_link_libraries(qtui Qt5::Widgets)

widgets/my_label.h

#ifndef MY_LABEL_H
#define MY_LABEL_H
#include <QLabel>
class MyLabel : public QLabel {
    Q_OBJECT
public:
    MyLabel();
};
#endif // MY_LABEL_H

widgets/my_label.cpp

#include "my_label.h"
MyLabel::MyLabel() : QLabel() {
}

Cc @sebholt

Edited Jan 18, 2019 by Peter Wu
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking