> Is there a way to specify that foo.o depends on tab.c?  For some

> reason cmake's scan does not seem to find this.

Does the following work for you?  The first bit is just putting some fixed 
files for convenience.  The second bit is the interesting bit.  In your build 
directory you won't have a data.c file until you compile.  When it compiles, 
data.c will first be generated, placed in your build directory, then compiled 
into data.c.o and archived into libdata.a.  Finally the executable links 
against libdata.a


cmake_minimum_required( VERSION 3.0 )

# Files that exist before the build starts:

# Header file with with no matching .c file
file( WRITE ${CMAKE_CURRENT_SOURCE_DIR}/data.h "extern int somevalue;" )
# main() that references the header
file( WRITE ${CMAKE_CURRENT_SOURCE_DIR}/hello.c "
#include \"data.h\"
#include <stdio.h>
int main()
{
   printf( \"Magic data: %d\\n\", somevalue );
}
" )



# This file is generated at build time and is relative to the binary dir
add_custom_command( OUTPUT data.c
 COMMAND echo "int somevalue = 42; " > data.c
 VERBATIM
)

add_library( data ${CMAKE_CURRENT_BINARY_DIR}/data.c )
add_executable( hello hello.c )

target_link_libraries( hello
 PRIVATE data
)


-- 

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://public.kitware.com/mailman/listinfo/cmake

Reply via email to