Den 09-07-2010 16:48, Michael Hertling skrev:
On 07/09/2010 03:48 PM, Bo Thorsen wrote:
Hi all,

Is there an elegant way of copying two files into one?

Right now, I have this:

ADD_CUSTOM_COMMAND(OUTPUT privilege_tables.sql
                     COMMAND copy /b
                       ${CMAKE_CURRENT_SOURCE_DIR}/system_tables.sql
                       + ${CMAKE_CURRENT_SOURCE_DIR}/tables_fix.sql
                       fix_privilege_tables.sql
                     DEPENDS
                     ${CMAKE_CURRENT_SOURCE_DIR}/system_tables.sql
                     ${CMAKE_CURRENT_SOURCE_DIR}/tables_fix.sql)

That's hardly elegant and it doesn't work :(

The problem with this is that the Windows copy command wants \ instead of /.

So, one of two fixes are possible for me: Either there is a much cleaner
way to do this, or I have to replace / with \ in the path.

If I have to do the replacement, is there a better way to do this than
to use the STRING command with a char replace?

Look at the following CMakeLists.txt:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
PROJECT(CONCAT C)
FILE(WRITE ${CMAKE_BINARY_DIR}/f1.c.in "void f1(void){}\n")
FILE(WRITE ${CMAKE_BINARY_DIR}/f2.c.in "void f2(void){}\n")
FILE(WRITE ${CMAKE_BINARY_DIR}/main.c
"int main(void){f1(); f2(); return 0;}\n"
)
FILE(WRITE ${CMAKE_BINARY_DIR}/concat.cmake "
FILE(READ \${SRC1} S1)
FILE(READ \${SRC2} S2)
FILE(WRITE \${DST} \${S1}\${S2})
")
ADD_CUSTOM_COMMAND(
     OUTPUT f.c
     COMMAND ${CMAKE_COMMAND} -D SRC1=${CMAKE_BINARY_DIR}/f1.c.in
                              -D SRC2=${CMAKE_BINARY_DIR}/f2.c.in
                              -D DST=${CMAKE_BINARY_DIR}/f.c
                              -P ${CMAKE_BINARY_DIR}/concat.cmake
     DEPENDS ${CMAKE_BINARY_DIR}/f1.c.in ${CMAKE_BINARY_DIR}/f2.c.in
)
ADD_EXECUTABLE(main main.c f.c)

Does this also work with binary files? From the documentation on FILE, this isn't really clear to me.

Bo.
_______________________________________________
Powered by www.kitware.com

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

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

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

Reply via email to