Having done some investigations to narrow down the issue, this is a simplified form of this earlier question.
Essentially I am creating a custom target where the command line requires some flags to be passed using the “-D” command-line option.
[For what it’s worth, the script that I’m running was generated using “configure_file”, but the context does not allow me to place the flags directly into the script at this point - hence I still need the command-line option.]
So my add_custom_target invocation looks like this:
add_custom_target(bisonparse ALL
COMMAND ${CMAKE_COMMAND} "-DFLAG_NAMES=${PROJECT_FB_FLAG_NAMES}"
"-DFLAGS=${PROJECT_FB_FLAGS}"
-P /build/path/GENERATED/bisonparse.cmake
BYPRODUCTS ${GENERATED_SOURCE_FILES} ${GENERATED_HEADER_FILES})
In Windows, this works perfectly.
In Linux however, the generated makefile fails to build. I get a peculiar error message, namely:
CMake Warning:
No source or binary directory provided. Both will be assumed to be the
same as the current working directory, but note that this warning will
become a fatal error in future CMake releases.
CMake Error: The source directory "/build/path" does not appear to contain CMakeLists.txt.
I can easily get rid of the build failure by commenting-out the two “-D” options, viz.
add_custom_target(bisonparse ALL
COMMAND ${CMAKE_COMMAND} #"-DFLAG_NAMES=${PROJECT_FB_FLAG_NAMES}"
#"-DFLAGS=${PROJECT_FB_FLAGS}"
-P /build/path/GENERATED/bisonparse.cmake
BYPRODUCTS ${GENERATED_SOURCE_FILES} ${GENERATED_HEADER_FILES})
…but then of course I don’t get the flags that I need.
Any problems I have when using CMake are usually connected with when and where to use quotations, so I’ve tried
-D"FLAG_NAMES=${PROJECT_FB_FLAG_NAMES}"
…and no quotes at all, and I find that these build successfully but no flags actually get passed.
What should I do?