msvc not generate moc file with CMake automoc












2















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.










share|improve this question

























  • 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











  • 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
















2















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.










share|improve this question

























  • 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











  • 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














2












2








2








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 29 '18 at 15:10







Ducksoul

















asked Nov 23 '18 at 12:59









DucksoulDucksoul

114




114













  • 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











  • 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 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












1 Answer
1






active

oldest

votes


















0














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)





share|improve this answer
























  • 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











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
});


}
});














draft saved

draft discarded


















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









0














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)





share|improve this answer
























  • 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
















0














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)





share|improve this answer
























  • 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














0












0








0







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)





share|improve this answer













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)






share|improve this answer












share|improve this answer



share|improve this answer










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



















  • 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


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Berounka

Sphinx de Gizeh

Fiat S.p.A.