[CMake] Problems with auto-generated sources

Williams, Norman K norman-k-williams at uiowa.edu
Mon Sep 30 13:19:54 EDT 2013


I don't see the problem you're having.

I re-wrote your CMakeLists.txt slightly to not use Unix commands:

========================================================================
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)


========================================================================

I only see GENERATING FILE once, even after the touch command.

Could you be using an old version of CMake? I tested with the current
development head, i.e. post-2.8.11.2


developer 116% cmake ../src
-- The C compiler identification is Clang 4.2.0
-- The CXX compiler identification is Clang 4.2.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /scratch/kent/cmake/test/build
developer 117% make
[ 25%] Generating file.c
GENERATING FILE
Scanning dependencies of target LibFile
[ 50%] Building C object CMakeFiles/LibFile.dir/file.c.o
Linking C static library libLibFile.a
/usr/bin/ranlib: file: libLibFile.a(file.c.o) has no symbols
/usr/bin/ranlib: file: libLibFile.a(file.c.o) has no symbols
/usr/bin/ranlib: warning for library: libLibFile.a the table of contents
is empty (no object file members in the library define global symbols)
[ 50%] Built target LibFile
Scanning dependencies of target test1
[ 75%] Building C object CMakeFiles/test1.dir/test.c.o
Linking C executable test1
[ 75%] Built target test1
Scanning dependencies of target test2
[100%] Building C object CMakeFiles/test2.dir/test.c.o
Linking C executable test2
[100%] Built target test2
developer 123% touch ../src/org.c
developer 124% make
[ 25%] Generating file.c
GENERATING FILE
Scanning dependencies of target LibFile
[ 50%] Building C object CMakeFiles/LibFile.dir/file.c.o
Linking C static library libLibFile.a
/usr/bin/ranlib: file: libLibFile.a(file.c.o) has no symbols
/usr/bin/ranlib: file: libLibFile.a(file.c.o) has no symbols
/usr/bin/ranlib: warning for library: libLibFile.a the table of contents
is empty (no object file members in the library define global symbols)
[ 50%] Built target LibFile
Linking C executable test1
[ 75%] Built target test1
Linking C executable test2
[100%] Built target test2





--
Kent Williams norman-k-williams at uiowa.edu



________________________________
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