title: CMake and FindProtobuf
body: <p>I'm using the FindProtobuf module in a project where the protocol buffer files are in a sub-directory. I want the CMakeLists.txt file in that sub-directory to invoke protoc to generate the CPP Files. My project folder structure is like this:</p>
  
  <pre><code>cammy/CMakeLists.txt   # Root CMakeLists.txt
  cammy/protofiles/test.proto # protofile
  cammy/protofiles/CMakeLists.txt
  </code></pre>
  
  <p>I have the include(FindProtobuf), the find_package invocation and the call to PROTOBUF_GENERATE_CPP in the CMakeLists.txt file in protobuf folder. </p>
  
  <p>The executable build step is in the Root CMakeLists.txt file and I add the generated files
  to the target executable in this file
  ie. </p>
  
  <pre><code>add_executable( ${EXEC} ${SRCS} ${PROTO_SRC} ${PROTO_HEADER} )
  target_link_libraries( ${EXEC} ${PROTOBUF_LIBRARIES} )
  </code></pre>
  
  <p>are both defined in the root CMakeLists.txt</p>
  
  <p>When I run cmake, it does not run protoc to generate the Source files even though I expilicitly tie generated sources to the executable thereby creating a dependency.</p>
  
  <p>When I move all the contents of CMakeLists.txt in the protofiles folder into the root CMakeLists.txt, the proto files are compiled. </p>
  
  <p>Can anyone help me with this? I want all the protocol buffer building stuff to go in the CMakeLists.txt file created in the protofiles folder. </p>
  
  <p>I also noticed that variables generated in the inner CMakeLists.txt ( like PROTO_SRC ) are defined in the inner file when printed ( ie I get the correct generated CPP filename ) but when I print the same variable in the root file.. it is empty. Its almost as though I need to "export" (if there were a way in cmake ) the variables out to the root folder.</p>
  
  <p>Any help would be much appreciated.</p>
  
  <p>Thanks
  Kartik</p>