How to add a 'non-built' file to a project with C-Make

107 views Asked by At

I have been searching about this for a couple of hours but couldn't find a solution, so asking.

I have a solution of projects that includes about 10 projects. But I'm facing a dependency problem. One of my projects generates moc files (QT moc file that was generated by 'QT4_WRAP_CPP' macro of Cmake) and I would like to use this moc file in another project. For now, after running the cmake script and getting the solution, I build all projects and the project that need those moc files generated by previous project complain about linking errors(rightly because I didn't point any file to it in its c-make script in ADD_EXECUTABLE section).

My question is: is there any way to add a 'not built yet but will' file to a project in Cmake to point it meanwhile writing the cmake script?

Here is related section of the cmake script of the project:

//suppose that X projects (which is also in this solution and built before Y project) generates a moc file with the name 'moc_X.cxx'

SET(Y_WORK_STATION_UI_HEADER YWorkStation.h
        YSignInWidget.h
        YConfigurationWidget.h)

     QT4_WRAP_CPP(MOCSrcs ${Y_WORK_STATION_UI_HEADER})

ADD_EXECUTABLE(${PROJECT_NAME}
        main.cpp
        .
        .
        .
        ${MOCSrcs}
        %---------------->and here something like moc_X.cxx ?
    }

Hope it is clear enough. Thanks in advance.

2

There are 2 answers

5
Angew is no longer proud of SO On BEST ANSWER

If the file is generated by something CMake understands (that is, by a custom command in the same CMakeList), you can just list it and CMake will pick up the dependency by itself. For other cases, there is a source file property GENERATED which you can set on the source file to indicate it will be generated during build:

add_executable(${PROJECT_NAME}
        main.cpp
        .
        .
        .
        ${MOCSrcs}
        moc_X.cxx ?
    )

set_property(SOURCE moc_X.cxx PROPERTY GENERATED TRUE)
0
steveire On

You seem to be doing several wrong things.

To start:

What do you mean by 'another project'? Do you actually mean 'another target'?

Why is one project using the moc files of another project? Is it also using the source files of that project? Why?

Why don't you use a static (or other) library if that's your goal? If using the source files of the other project makes sense for some reason (I imagine creating a unit test), then you should probably re-moc the files instead of trying to grab them from another implementation-detail location.