How is this file subproject1 depends on generated?

I have a project where some file was generated using add_custom_command,
like this:

    add_custom_command( OUTPUT ${FILE_NAME} COMMAND ${CMD_LINE} )

So, in order to my lib to depend on this file I created a custom target

    add_custom_target( target_name, ALL DEPENDS ${FILE_NAME} )

and then added as a dependency to my lib:

    add_dependencies( my_lib_name, target_name ${FILE_NAME} )

See and try adding an explicit dependency on the generated file like this.


Em ter, 19 de mar de 2019 às 14:46, Timothy Wrona <tjwrona1...@gmail.com>
escreveu:

> Never mind... I spoke too soon. add_dependencies isn't working. It is
> correctly making the other project build first, but the header file is for
> some reason not generated until after it is needed.
>
> On Tue, Mar 19, 2019 at 1:41 PM Timothy Wrona <tjwrona1...@gmail.com>
> wrote:
>
>> Seems I might be able to answer my own question.
>>
>> It looks like "add_dependencies(subproject1_exe subproject2_lib)" worked.
>>
>> I had to do a clean first though because it didn't work the first time
>> since some old files were left around.
>>
>> Hope this helps anyone else with a similar issue!
>>
>> On Tue, Mar 19, 2019 at 1:13 PM Timothy Wrona <tjwrona1...@gmail.com>
>> wrote:
>>
>>> I am working on a complex CMake project that is part of a large legacy
>>> system that uses a top level project and "add_subdirectory" to create
>>> subprojects.
>>>
>>> I have run into an issue because now one of the subprojects is dependant
>>> on another subproject, but I can't seem to find a clear way to tell
>>> CMake about this dependency.
>>>
>>> Consider this example:
>>>
>>>     my_project/
>>>         CMakeLists.txt:
>>>           add_subdirectory('subproject1')
>>>           add_subdirectory('subproject2')
>>>
>>>     my_project/subproject1/
>>>         CMakeLists.txt:
>>>             add_executable(subproject1_exe <sources>)
>>>             target_link_libraries(subproject1_exe subproject2_lib) # <--
>>> THIS is the problem
>>>
>>>     my_project/subproject2/
>>>         CMakeLists.txt:
>>>             add_library(subproject2_lib <sources>)
>>>
>>> The actual code is much more complex than this, but this simple example
>>> illustrates the problem. The actual compilation error I am getting is
>>> caused by subproject1 including a header file that gets generated when
>>> subproject2 is built.
>>>
>>> Does anyone know how to properly tell CMake about the dependency so it
>>> will build correctly?
>>>
>> --

-- 
Rafael Vargas
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

Reply via email to