1
votes

How to tell CMake that directory is generated so that it doesn't complain before building process that directory doesn't exist?

My library project is used by many clients and for every client I have client-specific configuration generated by scripts and placed into generated/[client-name]/generated.h header. So for every client there's is folder generated. But parent project source files (*.cpp) include just generated.h. I wanted to add generated/[client-name] interface include directory for my library by using:

set_target_properties(mylib PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "generated/myclient" ...)

but CMake complains even before starting compilation - Imported target "xxx" includes non-existent path. So I guess CMake doesn't like that include directory is missing when it starts building process although target depends on other targets which should create correct directory & header file within it.

1

1 Answers

2
votes

You can create the directory first with CMake:

file(MAKE_DIRECTORY "generated/myclient")

This will have no effect if the directory exists already.