How to compile additional source files in cmake after build process
I have a project in cmake for windows that contains a Pro * C source file called database.proc, my goal is to create a C source file from a .proc file and add it to a project that will link differently source files, I tried to add a custom team 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 a way to do this?
source to share
I'm not familiar with Pro * C, but it looks like you are mixing two different versions add_custom_command
.
The first version is add_custom_command(OUTPUT ...)
used to create a file, which is then added as a dependency of another CMake target. When this target is built, the custom command is executed first to create the output file.
The second version is add_custom_command(TARGET ...)
used to define the pre-build, pre-link, or post-build command; which does not necessarily create a file, but which runs alongside the creation of the linked target.
If you only have one goal that depends on Pro * C coming out, then the first version is probably the best choice:
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>)
source to share