Hi,

I also fell into this trap before:
Don't use MAIN_DEPENDENCY but DEPENDS.

HS


Am 15. Januar 2018 12:19:37 MEZ schrieb "[email protected]" 
<[email protected]>:
>Hi folks,
>
>we’re using a clang-based tool for co-processing a bunch of our source
>files. The benefit is, that it understands the compile_commands.json
>database and hence we do not need to pull out the include paths and the
>compile definitions by hand. However, CMake does not compile the source
>file any longer when used as input to a custom command.
>
>Here is the simplest project I could come up with to demonstrate the
>behavior:
>
>--- snip ---
># CMakeLists.txt
>cmake_minimum_required(VERSION 3.1)
>project(hello-world)
>
>add_executable(hello main.cxx hello.cxx)
>
>add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/reflections.h
>COMMAND echo "// This is a tool which creates type reflections"
>>reflections.h
>  MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/hello.cxx
>  COMMENT "Generating reflections"
>)
>--- snip ---
>
>--- snip ---
>// main.cxx
>void print_hello();
>
>int main() {
>  print_hello();
>  return 0;
>}
>--- snip ---
>
>--- snip ---
>// hello.cxx
>#include <iostream>
>
>void print_hello() {
>  std::cout << "Hello world!\n";
>}
>--- snip ---
>
>What happens is, that CMake does not compile hello.cxx any longer. It
>only executes the custom command. Consequently, the
>compile_commands.json database does not contain any information about
>hello.cxx. Tested on cmake 3.9.1 and 3.10.1.
>
>The reason for this behavior seems to be, that there can be only one
>kind for each given source file. In
>cmGeneratorTarget::ComputeKindedSources, there is an explicit check for
>not adding a source file multiple times to the KindedSources vector.
>And when checking which kind a source file is of, the first check is
>for custom commands. CMake says “Bingo, this is a custom command” and
>does not check whether it can be of any other kind as well.
>
>Is this a keep-it-simple implementation or is there any deeper
>knowledge behind this behavior?
>
>And more important: how can I force CMake to compile a source file and
>process it by a custom command?
>
>Thanks for your help,
>Christoph
>
>--
>rüdiger.engineering
>Christoph Rüdiger
>Düsseldorfer Str. 12
>45145 Essen
>Germany
>
>phone: +49 201 458 478 58

-- 
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

Reply via email to