How to Run a Basic `add_custom_command` in CMake

2019-07-24 03:18发布

问题:

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.