[CMake] output of add_custom_command as target in Makefile

Nagy-Egri Máté Ferenc csiga.biga at aol.com
Fri Jun 12 03:24:42 EDT 2015


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
Elküldve: ‎péntek‎, ‎2015‎. ‎június‎ ‎12‎. ‎2‎:‎00
Címzett: cmake at cmake.org





In this example, how do I get

   make 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/

======== CMakeLists.txt

cmake_minimum_required(VERSION 3.3.0)




project(custom-command-target)







add_custom_command (

  OUTPUT  foo.cc

  COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/genFoo > foo.cc

  )




add_executable (foo 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                                             

make: *** No rule to make target 'foo.cc'.  Stop.

2 Thu 16:56:49 yost DaveBook ~/p/c++/cmake/custom-command-target/build

374 Z%
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150612/4750017f/attachment.html>


More information about the CMake mailing list