[CMake] no convenience target for generated files?

Dave Yost Dave at Yost.com
Mon Jun 1 22:45:23 EDT 2015


0 Mon 19:44:33 yost DaveBook ~/p/c++/cmake/target-for-generate/build
261 Z% make help
The following are some of the valid targets for this Makefile:
... all (the default if no target is provided)
... clean
... depend
... edit_cache
... rebuild_cache
... foo
... genBar
... bar
... foo.o
... foo.i
... foo.s
0 Mon 19:44:35 yost DaveBook ~/p/c++/cmake/target-for-generate/build
262 Z% 

> On 2015-04-08, at 8:05 PM, David Cole <DLRdave at aol.com> wrote:
> 
> Does
> 
>     cd bar
>     make help
> 
> Tell you anything?
> 
> 
> On Wednesday, April 8, 2015, Dave Yost <Dave at yost.com <mailto:Dave at yost.com>> wrote:
> I’m using add_custom_command to generate a file, “bar.cc <http://bar.cc/>”.
> 
> It would be convenient if I could say
>   make bar.cc <http://bar.cc/>
> or
>   make bar/bar.cc <http://bar.cc/>
> but neither of these work, and I can’t see a target in the Makefiles that I can use.
> 
> There is a way to make bar.cc.o, but not bar.cc <http://bar.cc/>
> 
> 0 Wed 14:15:54 yost DaveBook ~/p/c++/cmake/target-for-generate
> 241 Z% bundle `findf *`
> [ find CMakeLists.txt bar foo.cc <http://foo.cc/> -type f ]
> #!/usr/bin/env unbundle
> # See http://yost.com/computers/bundle/ <http://yost.com/computers/bundle/>
> ======== CMakeLists.txt
> cmake_minimum_required(VERSION 3.2.1)
> 
> project(yost-cmake-example)
> 
> add_subdirectory(bar)
> 
> add_executable       (foo foo.cc <http://foo.cc/>)
> target_link_libraries(foo bar)
> 
> ======== bar/bar.hh
> extern char* str1;
> 
> ======== bar/CMakeLists.txt
> 
> add_executable(genBar genBar.cc <http://genbar.cc/>)
> 
> add_custom_command(
>   OUTPUT  bar.cc <http://bar.cc/>
>   COMMAND genBar > bar.cc <http://bar.cc/>
>   DEPENDS genBar)
> 
> add_library               (bar SHARED bar.cc <http://bar.cc/>)
> target_include_directories(bar PUBLIC .)
> 
> ======== bar/genBar.cc <http://genbar.cc/>
> #include <iostream>
> 
> int main(int argc, char** argv) {
>     std::cout
>     << "#include \"bar.hh\"\n\n"
>        "char         str1array[] = \"Hello!\";\n"
>        "char* str1 = str1array;\n";
>     return 0;
> }
> 
> ======== foo.cc <http://foo.cc/>
> #include <iostream>
> #include <bar.hh>
> 
> int main(int argc, char** argv) {
>   std::cout << str1 << std::endl;
>   return 0;
> }
> 
> ========
> 0 Wed 14:15:57 yost DaveBook ~/p/c++/cmake/target-for-generate
> 242 Z% mkdir build
> 0 Wed 14:16:02 yost DaveBook ~/p/c++/cmake/target-for-generate
> 243 Z% cd build
> 0 Wed 14:16:03 yost DaveBook ~/p/c++/cmake/target-for-generate/build
> 244 Z% cmake ..
> -- The C compiler identification is AppleClang 6.0.0.6000057
> -- The CXX compiler identification is AppleClang 6.0.0.6000057
> -- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
> -- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
> -- Detecting C compiler ABI info
> -- Detecting C compiler ABI info - done
> -- Detecting C compile features
> -- Detecting C compile features - done
> -- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
> -- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
> -- Detecting CXX compiler ABI info
> -- Detecting CXX compiler ABI info - done
> -- Detecting CXX compile features
> -- Detecting CXX compile features - done
> -- Configuring done
> -- Generating done
> -- Build files have been written to: /Users/yost/p/c++/cmake/target-for-generate/build
> 0 Wed 14:16:07 yost DaveBook ~/p/c++/cmake/target-for-generate/build
> 245 Z% make
> Scanning dependencies of target genBar
> [ 14%] Building CXX object bar/CMakeFiles/genBar.dir/genBar.cc.o
> [ 28%] Linking CXX executable genBar
> [ 28%] Built target genBar
> [ 42%] Generating bar.cc <http://bar.cc/>
> Scanning dependencies of target bar
> [ 57%] Building CXX object bar/CMakeFiles/bar.dir/bar.cc.o
> [ 71%] Linking CXX shared library libbar.dylib
> [ 71%] Built target bar
> Scanning dependencies of target foo
> [ 85%] Building CXX object CMakeFiles/foo.dir/foo.cc.o
> [100%] Linking CXX executable foo
> [100%] Built target foo
> 0 Wed 14:16:09 yost DaveBook ~/p/c++/cmake/target-for-generate/build
> 246 Z% rm bar/bar.cc <http://bar.cc/>
> 0 Wed 14:16:15 yost DaveBook ~/p/c++/cmake/target-for-generate/build
> 247 Z% make bar/bar.cc <http://bar.cc/>
> make: *** No rule to make target `bar/bar.cc <http://bar.cc/>'.  Stop.
> 2 Wed 14:16:24 yost DaveBook ~/p/c++/cmake/target-for-generate/build
> 248 Z% make bar.cc <http://bar.cc/>
> make: *** No rule to make target `bar.cc <http://bar.cc/>'.  Stop.
> 2 Wed 14:16:27 yost DaveBook ~/p/c++/cmake/target-for-generate/build
> 249 Z% cd bar
> 0 Wed 14:19:20 yost DaveBook ~/p/c++/cmake/target-for-generate/build/bar
> 253 Z% make bar.cc <http://bar.cc/>
> make: *** No rule to make target `bar.cc <http://bar.cc/>'.  Stop.
> 2 Wed 14:19:22 yost DaveBook ~/p/c++/cmake/target-for-generate/build/bar
> 254 Z% make bar.cc.o
> Generating bar.cc <http://bar.cc/>
> Building CXX object bar/CMakeFiles/bar.dir/bar.cc.o
> 0 Wed 14:19:25 yost DaveBook ~/p/c++/cmake/target-for-generate/build/bar
> 255 Z% 
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150601/5a74a89e/attachment-0001.html>


More information about the CMake mailing list