Hooray! Thanks!

Could a future version of cmake provide a nicer way to do this, without these 
error messages?

0 Fri 12:29:25 yost DaveBook ~/p/c++/cmake/custom-command-target/build
391 Z% make foo.cc
Scanning dependencies of target foo.cc
make[3]: Circular CMakeFiles/foo.cc <- foo.cc dependency dropped.
make[3]: Circular foo.cc <- foo.cc dependency dropped.
[100%] Generating foo.cc
[100%] Built target foo.cc
0 Fri 12:29:27 yost DaveBook ~/p/c++/cmake/custom-command-target/build
392 Z% 

> On 2015-06-12, at 8:40 AM, Glenn Coombs <glenn.coo...@gmail.com> wrote:
> 
> If you run "make help" it will list targets it understands.  And as you 
> pointed out there is no target for foo.cc.  You can "make foo" but if you 
> really want a target for foo.cc you can add one yourself:
> 
> cmake_minimum_required(VERSION 3.0.0)
> 
> project(custom-command-target)
> 
> add_custom_command (
>   OUTPUT  foo.cc
>   COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/genFoo > foo.cc
>   )
> 
> add_custom_target(foo.cc DEPENDS ${CMAKE_BINARY_DIR}/foo.cc)
> 
> add_executable (foo foo.cc)
> 
> That should create a foo.cc target that you can run that will do the right 
> thing.
> 
> --
> Glenn
> 
> On 12 June 2015 at 14:20, Dave Yost <d...@yost.com <mailto:d...@yost.com>> 
> wrote:
> I’m not doing it wrong. Remember, this is a simplified example.
> 
> We want to be able to make foo.cc <http://foo.cc/> so we can look at it and 
> compare it. Yes, we could make foo and then look at foo.cc <http://foo.cc/>, 
> but until foo.cc <http://foo.cc/> is right, we will suffer a lot of compiler 
> error clutter. When foo.cc <http://foo.cc/> looks right, then we will make 
> foo.
> 
> BTW, changing add_custom_command to add_custom_target has no apparent effect 
> and doesn’t help.
> 
>> On 2015-06-12, at 12:24 AM, Nagy-Egri Máté Ferenc <csiga.b...@aol.com 
>> <mailto:csiga.b...@aol.com>> wrote:
>> 
>> You’re doing it all wrong. You do not name source files as make targets, but 
>> the target name (or project name, I have no idea, because it rarely makes 
>> sense to name them differently). Try simply “foo” or 
>> “custom-command-target”. You would never say “make foo.cpp”, not even in an 
>> ordinary GNU Make script.
>> 
>> Feladó: Dave Yost <mailto:d...@yost.com>
>> Elküldve: ‎péntek‎, ‎2015‎. ‎június‎ ‎12‎. ‎2‎:‎00
>> Címzett: cmake@cmake.org <mailto:cmake@cmake.org>
>> 
>> In this example, how do I get
>>    make foo.cc <http://foo.cc/>
>> to work?
>> 
>> 0 Thu 16:56:19 yost DaveBook ~/p/c++/cmake/custom-command-target
>> 369 Z% bundle CMakeLists.txt genFoo
>> #!/usr/bin/env unbundle
>> # See http://yost.com/computers/bundle/ <http://yost.com/computers/bundle/>
>> ======== CMakeLists.txt
>> cmake_minimum_required(VERSION 3.3.0)
>> 
>> project(custom-command-target)
>> 
>> 
>> add_custom_command (
>>   OUTPUT  foo.cc <http://foo.cc/>
>>   COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/genFoo > foo.cc <http://foo.cc/>
>>   )
>> 
>> add_executable (foo foo.cc <http://foo.cc/>)
>> 
>> ======== genFoo
>> #!/bin/bash
>> 
>> echo "
>> int main() {
>>   return 0;
>> }"
>> ========
>> 0 Thu 16:56:23 yost DaveBook ~/p/c++/cmake/custom-command-target
>> 370 Z% cd build                                                
>> 0 Thu 16:56:36 yost DaveBook ~/p/c++/cmake/custom-command-target/build
>> 371 Z% cmake ..                                                
>> -- Configuring done
>> -- Generating done
>> -- Build files have been written to: 
>> /Users/yost/p/c++/cmake/custom-command-target/build
>> 0 Thu 16:56:41 yost DaveBook ~/p/c++/cmake/custom-command-target/build
>> 372 Z% make clean                                              
>> 0 Thu 16:56:45 yost DaveBook ~/p/c++/cmake/custom-command-target/build
>> 373 Z% make foo.cc <http://foo.cc/>                                          
>>    
>> make: *** No rule to make target 'foo.cc <http://foo.cc/>'.  Stop.
>> 2 Thu 16:56:49 yost DaveBook ~/p/c++/cmake/custom-command-target/build
>> 374 Z% 
> 
> 
> --
> 
> Powered by www.kitware.com <http://www.kitware.com/>
> 
> Please keep messages on-topic and check the CMake FAQ at: 
> http://www.cmake.org/Wiki/CMake_FAQ <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 
> <http://cmake.org/cmake/help/support.html>
> CMake Consulting: http://cmake.org/cmake/help/consulting.html 
> <http://cmake.org/cmake/help/consulting.html>
> CMake Training Courses: http://cmake.org/cmake/help/training.html 
> <http://cmake.org/cmake/help/training.html>
> 
> Visit other Kitware open-source projects at 
> http://www.kitware.com/opensource/opensource.html 
> <http://www.kitware.com/opensource/opensource.html>
> 
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake 
> <http://public.kitware.com/mailman/listinfo/cmake>
> 

-- 

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:
http://public.kitware.com/mailman/listinfo/cmake

Reply via email to