5

I'm just trying to get a basic CMake example up and running that can run some basic command line commands. I've been researching this for a while and I haven't had any luck. Am I completely using this wrong? Any and all input would be greatly appreciated.

cmake_minimum_required(VERSION 3.0)

add_custom_command(
  OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/test.txt
  COMMAND echo "Hello world"
  COMMENT "This is a comment. But it's not printed during the build?"
)

return() 

Edit: Using:

add_custom_target(run ALL DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/test.txt)

does not work either, as has been suggested in other posts.

Royi
  • 4,640
  • 6
  • 46
  • 64
  • 4
    Possible duplicate of [CMake add\_custom\_command not being run](https://stackoverflow.com/questions/2937128/cmake-add-custom-command-not-being-run) – Tsyvarev Nov 16 '17 at 15:53
  • 1
    Weird. Please, post complete example with `add_custom_target` included. Does file `text.txt` already exist in the source directory? – Tsyvarev Nov 16 '17 at 19:51
  • works for me with what you posted (putting `cmake_minimum_requires`, `add_custom_command` `add_custom_target` into a `CMakeLists.txt` file with nothing else) when there is no `text.txt` file in the source directory. I removed `return()`. – pseyfert Nov 17 '17 at 11:13

0 Answers0