msvc not generate moc file with CMake automoc
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(source_files
a.cpp
b.cpp
...
)
set(header_files
a.hpp
b.hpp
...
)
set(Qt_libs
Qt5::Core
Qt5::Gui
Qt5::Widget
...
)
add_library(demo SHARED ${header_files} ${source_files})
target_link_libraries(demo ${Qt_libs} ...)
set_properties(TARGET demo PROPERTY FOLDER "somewhere")
install(...)
I have a sample CMakeLists.txt
shows above.
The most weird thing is, it won't generate those moc files until I manually modified (like adding a empty line to the file) those header files (where Q_OBJECT
presents).
The situation not happen every time. But, once it happens, clean build nor deleting whole project file won't help.
I'm using qt 5.11
, CMake 3.7
, Visual Studio 2015
.
visual-studio qt visual-c++ cmake
|
show 1 more comment
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(source_files
a.cpp
b.cpp
...
)
set(header_files
a.hpp
b.hpp
...
)
set(Qt_libs
Qt5::Core
Qt5::Gui
Qt5::Widget
...
)
add_library(demo SHARED ${header_files} ${source_files})
target_link_libraries(demo ${Qt_libs} ...)
set_properties(TARGET demo PROPERTY FOLDER "somewhere")
install(...)
I have a sample CMakeLists.txt
shows above.
The most weird thing is, it won't generate those moc files until I manually modified (like adding a empty line to the file) those header files (where Q_OBJECT
presents).
The situation not happen every time. But, once it happens, clean build nor deleting whole project file won't help.
I'm using qt 5.11
, CMake 3.7
, Visual Studio 2015
.
visual-studio qt visual-c++ cmake
I have problems withauto_moc
as well (as a lot of others might tell you). I always run acmake configure
after adding a new file which needsmoc
– Amfasis
Nov 23 '18 at 13:09
I had similar problem and could not manage to solve it. So I decided to use the qt5_generate_moc() macro
– ni1ight
Nov 23 '18 at 13:18
stackoverflow.com/questions/37151163/…
– Mac
Nov 24 '18 at 0:52
@Mac I have both header and source files added to the target. It seems not produced by handling CMake file wrong because the problem happens only sometimes.
– Ducksoul
Nov 24 '18 at 11:35
did u try adding the headers to the solution as described there?
– Mac
Nov 25 '18 at 20:20
|
show 1 more comment
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(source_files
a.cpp
b.cpp
...
)
set(header_files
a.hpp
b.hpp
...
)
set(Qt_libs
Qt5::Core
Qt5::Gui
Qt5::Widget
...
)
add_library(demo SHARED ${header_files} ${source_files})
target_link_libraries(demo ${Qt_libs} ...)
set_properties(TARGET demo PROPERTY FOLDER "somewhere")
install(...)
I have a sample CMakeLists.txt
shows above.
The most weird thing is, it won't generate those moc files until I manually modified (like adding a empty line to the file) those header files (where Q_OBJECT
presents).
The situation not happen every time. But, once it happens, clean build nor deleting whole project file won't help.
I'm using qt 5.11
, CMake 3.7
, Visual Studio 2015
.
visual-studio qt visual-c++ cmake
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(source_files
a.cpp
b.cpp
...
)
set(header_files
a.hpp
b.hpp
...
)
set(Qt_libs
Qt5::Core
Qt5::Gui
Qt5::Widget
...
)
add_library(demo SHARED ${header_files} ${source_files})
target_link_libraries(demo ${Qt_libs} ...)
set_properties(TARGET demo PROPERTY FOLDER "somewhere")
install(...)
I have a sample CMakeLists.txt
shows above.
The most weird thing is, it won't generate those moc files until I manually modified (like adding a empty line to the file) those header files (where Q_OBJECT
presents).
The situation not happen every time. But, once it happens, clean build nor deleting whole project file won't help.
I'm using qt 5.11
, CMake 3.7
, Visual Studio 2015
.
visual-studio qt visual-c++ cmake
visual-studio qt visual-c++ cmake
edited Nov 29 '18 at 15:10
Ducksoul
asked Nov 23 '18 at 12:59
DucksoulDucksoul
114
114
I have problems withauto_moc
as well (as a lot of others might tell you). I always run acmake configure
after adding a new file which needsmoc
– Amfasis
Nov 23 '18 at 13:09
I had similar problem and could not manage to solve it. So I decided to use the qt5_generate_moc() macro
– ni1ight
Nov 23 '18 at 13:18
stackoverflow.com/questions/37151163/…
– Mac
Nov 24 '18 at 0:52
@Mac I have both header and source files added to the target. It seems not produced by handling CMake file wrong because the problem happens only sometimes.
– Ducksoul
Nov 24 '18 at 11:35
did u try adding the headers to the solution as described there?
– Mac
Nov 25 '18 at 20:20
|
show 1 more comment
I have problems withauto_moc
as well (as a lot of others might tell you). I always run acmake configure
after adding a new file which needsmoc
– Amfasis
Nov 23 '18 at 13:09
I had similar problem and could not manage to solve it. So I decided to use the qt5_generate_moc() macro
– ni1ight
Nov 23 '18 at 13:18
stackoverflow.com/questions/37151163/…
– Mac
Nov 24 '18 at 0:52
@Mac I have both header and source files added to the target. It seems not produced by handling CMake file wrong because the problem happens only sometimes.
– Ducksoul
Nov 24 '18 at 11:35
did u try adding the headers to the solution as described there?
– Mac
Nov 25 '18 at 20:20
I have problems with
auto_moc
as well (as a lot of others might tell you). I always run a cmake configure
after adding a new file which needs moc
– Amfasis
Nov 23 '18 at 13:09
I have problems with
auto_moc
as well (as a lot of others might tell you). I always run a cmake configure
after adding a new file which needs moc
– Amfasis
Nov 23 '18 at 13:09
I had similar problem and could not manage to solve it. So I decided to use the qt5_generate_moc() macro
– ni1ight
Nov 23 '18 at 13:18
I had similar problem and could not manage to solve it. So I decided to use the qt5_generate_moc() macro
– ni1ight
Nov 23 '18 at 13:18
stackoverflow.com/questions/37151163/…
– Mac
Nov 24 '18 at 0:52
stackoverflow.com/questions/37151163/…
– Mac
Nov 24 '18 at 0:52
@Mac I have both header and source files added to the target. It seems not produced by handling CMake file wrong because the problem happens only sometimes.
– Ducksoul
Nov 24 '18 at 11:35
@Mac I have both header and source files added to the target. It seems not produced by handling CMake file wrong because the problem happens only sometimes.
– Ducksoul
Nov 24 '18 at 11:35
did u try adding the headers to the solution as described there?
– Mac
Nov 25 '18 at 20:20
did u try adding the headers to the solution as described there?
– Mac
Nov 25 '18 at 20:20
|
show 1 more comment
1 Answer
1
active
oldest
votes
You are setting the global setting with set() which could be overwritten.
Please use set_target_properties, for example
project(exampleProj)
add_executable(exampleProj main.cpp)
set_target_properties(exampleProj
PROPERTIES
CMAKE_INCLUDE_CURRENT_DIR ON
CMAKE_AUTOMOC ON)
Thank you for the answer, I will try it and posting result later.
– Ducksoul
Nov 26 '18 at 14:02
@Ducksoul if you do not have success with this answer, consider updating your question with the contents of your CMakelists.txt file so that the answer may be filled with more context
– brettmichaelgreen
Nov 26 '18 at 14:09
this method seems not solving the problem after a few tries. And my Cmake file is pretty much the same as stackoverflow.com/questions/37151163/…
– Ducksoul
Nov 28 '18 at 14:46
@Ducksoul I need your snippet so I can see if set_target_properties was used on a valid target . Excluding filenames of your sources would still produce a minimum, verifiable, example if the contents are sensitive
– brettmichaelgreen
Nov 28 '18 at 17:25
I updated my answer.
– Ducksoul
Nov 29 '18 at 15:11
|
show 2 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53447187%2fmsvc-not-generate-moc-file-with-cmake-automoc%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You are setting the global setting with set() which could be overwritten.
Please use set_target_properties, for example
project(exampleProj)
add_executable(exampleProj main.cpp)
set_target_properties(exampleProj
PROPERTIES
CMAKE_INCLUDE_CURRENT_DIR ON
CMAKE_AUTOMOC ON)
Thank you for the answer, I will try it and posting result later.
– Ducksoul
Nov 26 '18 at 14:02
@Ducksoul if you do not have success with this answer, consider updating your question with the contents of your CMakelists.txt file so that the answer may be filled with more context
– brettmichaelgreen
Nov 26 '18 at 14:09
this method seems not solving the problem after a few tries. And my Cmake file is pretty much the same as stackoverflow.com/questions/37151163/…
– Ducksoul
Nov 28 '18 at 14:46
@Ducksoul I need your snippet so I can see if set_target_properties was used on a valid target . Excluding filenames of your sources would still produce a minimum, verifiable, example if the contents are sensitive
– brettmichaelgreen
Nov 28 '18 at 17:25
I updated my answer.
– Ducksoul
Nov 29 '18 at 15:11
|
show 2 more comments
You are setting the global setting with set() which could be overwritten.
Please use set_target_properties, for example
project(exampleProj)
add_executable(exampleProj main.cpp)
set_target_properties(exampleProj
PROPERTIES
CMAKE_INCLUDE_CURRENT_DIR ON
CMAKE_AUTOMOC ON)
Thank you for the answer, I will try it and posting result later.
– Ducksoul
Nov 26 '18 at 14:02
@Ducksoul if you do not have success with this answer, consider updating your question with the contents of your CMakelists.txt file so that the answer may be filled with more context
– brettmichaelgreen
Nov 26 '18 at 14:09
this method seems not solving the problem after a few tries. And my Cmake file is pretty much the same as stackoverflow.com/questions/37151163/…
– Ducksoul
Nov 28 '18 at 14:46
@Ducksoul I need your snippet so I can see if set_target_properties was used on a valid target . Excluding filenames of your sources would still produce a minimum, verifiable, example if the contents are sensitive
– brettmichaelgreen
Nov 28 '18 at 17:25
I updated my answer.
– Ducksoul
Nov 29 '18 at 15:11
|
show 2 more comments
You are setting the global setting with set() which could be overwritten.
Please use set_target_properties, for example
project(exampleProj)
add_executable(exampleProj main.cpp)
set_target_properties(exampleProj
PROPERTIES
CMAKE_INCLUDE_CURRENT_DIR ON
CMAKE_AUTOMOC ON)
You are setting the global setting with set() which could be overwritten.
Please use set_target_properties, for example
project(exampleProj)
add_executable(exampleProj main.cpp)
set_target_properties(exampleProj
PROPERTIES
CMAKE_INCLUDE_CURRENT_DIR ON
CMAKE_AUTOMOC ON)
answered Nov 26 '18 at 13:33
brettmichaelgreenbrettmichaelgreen
336111
336111
Thank you for the answer, I will try it and posting result later.
– Ducksoul
Nov 26 '18 at 14:02
@Ducksoul if you do not have success with this answer, consider updating your question with the contents of your CMakelists.txt file so that the answer may be filled with more context
– brettmichaelgreen
Nov 26 '18 at 14:09
this method seems not solving the problem after a few tries. And my Cmake file is pretty much the same as stackoverflow.com/questions/37151163/…
– Ducksoul
Nov 28 '18 at 14:46
@Ducksoul I need your snippet so I can see if set_target_properties was used on a valid target . Excluding filenames of your sources would still produce a minimum, verifiable, example if the contents are sensitive
– brettmichaelgreen
Nov 28 '18 at 17:25
I updated my answer.
– Ducksoul
Nov 29 '18 at 15:11
|
show 2 more comments
Thank you for the answer, I will try it and posting result later.
– Ducksoul
Nov 26 '18 at 14:02
@Ducksoul if you do not have success with this answer, consider updating your question with the contents of your CMakelists.txt file so that the answer may be filled with more context
– brettmichaelgreen
Nov 26 '18 at 14:09
this method seems not solving the problem after a few tries. And my Cmake file is pretty much the same as stackoverflow.com/questions/37151163/…
– Ducksoul
Nov 28 '18 at 14:46
@Ducksoul I need your snippet so I can see if set_target_properties was used on a valid target . Excluding filenames of your sources would still produce a minimum, verifiable, example if the contents are sensitive
– brettmichaelgreen
Nov 28 '18 at 17:25
I updated my answer.
– Ducksoul
Nov 29 '18 at 15:11
Thank you for the answer, I will try it and posting result later.
– Ducksoul
Nov 26 '18 at 14:02
Thank you for the answer, I will try it and posting result later.
– Ducksoul
Nov 26 '18 at 14:02
@Ducksoul if you do not have success with this answer, consider updating your question with the contents of your CMakelists.txt file so that the answer may be filled with more context
– brettmichaelgreen
Nov 26 '18 at 14:09
@Ducksoul if you do not have success with this answer, consider updating your question with the contents of your CMakelists.txt file so that the answer may be filled with more context
– brettmichaelgreen
Nov 26 '18 at 14:09
this method seems not solving the problem after a few tries. And my Cmake file is pretty much the same as stackoverflow.com/questions/37151163/…
– Ducksoul
Nov 28 '18 at 14:46
this method seems not solving the problem after a few tries. And my Cmake file is pretty much the same as stackoverflow.com/questions/37151163/…
– Ducksoul
Nov 28 '18 at 14:46
@Ducksoul I need your snippet so I can see if set_target_properties was used on a valid target . Excluding filenames of your sources would still produce a minimum, verifiable, example if the contents are sensitive
– brettmichaelgreen
Nov 28 '18 at 17:25
@Ducksoul I need your snippet so I can see if set_target_properties was used on a valid target . Excluding filenames of your sources would still produce a minimum, verifiable, example if the contents are sensitive
– brettmichaelgreen
Nov 28 '18 at 17:25
I updated my answer.
– Ducksoul
Nov 29 '18 at 15:11
I updated my answer.
– Ducksoul
Nov 29 '18 at 15:11
|
show 2 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53447187%2fmsvc-not-generate-moc-file-with-cmake-automoc%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I have problems with
auto_moc
as well (as a lot of others might tell you). I always run acmake configure
after adding a new file which needsmoc
– Amfasis
Nov 23 '18 at 13:09
I had similar problem and could not manage to solve it. So I decided to use the qt5_generate_moc() macro
– ni1ight
Nov 23 '18 at 13:18
stackoverflow.com/questions/37151163/…
– Mac
Nov 24 '18 at 0:52
@Mac I have both header and source files added to the target. It seems not produced by handling CMake file wrong because the problem happens only sometimes.
– Ducksoul
Nov 24 '18 at 11:35
did u try adding the headers to the solution as described there?
– Mac
Nov 25 '18 at 20:20