[CMake] Problems with auto-generated sources

Williams, Norman K norman-k-williams at uiowa.edu
Tue Oct 1 10:07:25 EDT 2013


I was under the impression that target_link_libraries implicitly mad the
target depend on all mentioned libraries.

Calling the custom command and library build twice during parallel builds
is just wrong.  If it's a known problem, it probably requires addressing
at some point.

Does this problem extend to other build systems or just gnu make?  Is
CMake generating bad Makefiles?

I would think that it should generate something like this, which will not
run into duplicate builds in parallel.

file.c : org.c
        cmake -E remove file.c
        cmake -E copy org.c file.c

libLibfile.a : file.o
        $(AR) $(ARFLAGS) libLibfile.a file.o

test1 : test.o libLibfile.a
        cc -o test1 test.o -lLibFile
test2 : test.o libLibfile.a
        cc -o test2 test.o -lLibFile


On 10/1/13 6:38 AM, "Gregor Jasny" <gjasny at googlemail.com> wrote:

>Hello,
>
>On 9/30/13 7:19 PM, Williams, Norman K wrote:
>> ========================================================================
>> cmake_minimum_required(VERSION 2.8)
>> project(Test)
>>
>> add_custom_command(OUTPUT file.c
>>      COMMAND echo "GENERATING FILE"
>>      COMMAND ${CMAKE_COMMAND} -E remove file.c
>>      COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/org.c
>> file.c
>>      DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/org.c
>>    )
>> add_library(LibFile file.c)
>>
>> add_executable(test1 test.c)
>> target_link_libraries(test1 LibFile)
>>
>> add_executable(test2 test.c)
>> target_link_libraries(test2 LibFile)
>>
>>
>> ========================================================================
>
>Please try to add these two lines:
>
>add_dependencies(test1 LibFile)
>add_dependencies(test2 LibFile)
>
>This helped to solve my dependencies problem.
>
>Thanks,
>Gregor
>
>--
>
>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:
>http://www.cmake.org/mailman/listinfo/cmake



________________________________
Notice: This UI Health Care e-mail (including attachments) is covered by the Electronic Communications Privacy Act, 18 U.S.C. 2510-2521, is confidential and may be legally privileged.  If you are not the intended recipient, you are hereby notified that any retention, dissemination, distribution, or copying of this communication is strictly prohibited.  Please reply to the sender that you have received the message in error, then delete it.  Thank you.
________________________________


More information about the CMake mailing list