How to compile additional source files in cmake after the build process

I have a project in cmake for windows which contains a Pro*C source file called database.proc, my goal is to generate a C source file from the .proc file and add it to the project to be linked along the other source files, I've tried to add a custom command to achieve this without success

add_custom_command(TARGET myproj OUTPUT PRE_LINK
    COMMAND ${PROC} iname=${PROJECT_SOURCE_DIR}/connection.proc SQLCHECK=SYNTAX
        MODE=ANSI IRECLEN=255 ORECLEN=255
        ONAME=${PROJECT_SOURCE_DIR}/connection.c
    COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS}
            ${PROJECT_SOURCE_DIR}/connection.c )

Is there some way to do this?

Answers


I'm not familiar with Pro*C, but it looks like you're mixing together the two different versions of add_custom_command.

The first version add_custom_command(OUTPUT ...) is used to generate a file which is then added as a dependency of another CMake target. When that target is built, the custom command is executed first in order to generate the output file.

The second version add_custom_command(TARGET ...) is used to define a pre-build, pre-link or post-build command; one which does not necessarily create a file, but which executes in conjunction with building the associated target.

If you only have one target which depends on the output of Pro*C, then the first version is probably your best bet:

add_custom_command(OUTPUT ${PROJECT_SOURCE_DIR}/connection.c
    COMMAND ${PROC} iname=${PROJECT_SOURCE_DIR}/connection.proc SQLCHECK=SYNTAX
        MODE=ANSI IRECLEN=255 ORECLEN=255
        ONAME=${PROJECT_SOURCE_DIR}/connection.c)
add_executable(myproj ${PROJECT_SOURCE_DIR}/connection.c <other sources>)

Need Your Help

How do I set an array of jQuery mobile flip toggle switches?

javascript jquery jquery-mobile local-storage jquery-mobile-flipswitch

I am working with jQuery mobile and have a set of 8 select flip switches with on and off values. What I need to do is set the value for each switch in localStorage when changed by the user. In tur...

Why does socket.io require a new listener

node.js sockets express

I know this ia probably a stupid question, but i sure hope i get the noob pass but I'm using the express framework with node js and mongo db. Why do you always have to create a new server in order ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.