I'm trying to add a custom build step in CMake that generates some files. I haven't found a description how it works.
I have an project where source, header & implementation files have to be generated by ODB for C++. ODB takes class headers as arguments and generates source files that I want to use in my project.
Right now I have the following command in my CMakeLists.txt:
add_custom_command(TARGET ${PROJECT_NAME}
PRE_BUILD
COMMAND odb -o /home/david/dev/ --std c++11 -I/home/david/dev/ -d sqlite --generate- query --generate-schema ${PROMOTER_LIB_PREFIX}/entities/person.hpp
DEPENDS ${PROJECT_NAME}
VERBATIM
)
For a file person.hpp
ODB should generate person-odb.hxx
, person-odb.cxx
, person-odb.ixx
but the CMake command I''ve used doesn't generate anything. In a terminal this command works fine.
What am I doing wrong?
EDIT: The problem can be solved by adding the following lines:
set(FAKE_TARGET fakeTarget)
add_custom_target(fakeTarget
odb -o /home/david/dev/ --std c++11 -I/home/david/dev/ -d sqlite --generate-query --generate-schema ${PROMOTER_LIB_PREFIX}/entities/person.hpp
)
add_dependencies(${PROJECT_NAME} ${FAKE_TARGET})
For me, with something similar, I just use :
We don't use
DEPENDS
orVERBATIM
.The
DEPENDS
option specify that the command must be executed only after that the project you gave to this option is built.EDIT :
Maybe that's why it doesn't work for you.
A work around could be (a bit ugly) :