You use return()
(the CMake man page here ), which returns from the function if called when in the function.
For instance:
cmake_minimum_required(VERSION 3.0) project(returntest) # note: your function syntax was wrong - the function name goes # after the parenthesis function (do_the_thing HAS_PROPERTY_A) if (HAS_PROPERTY_A) message(STATUS "Early Return") return() endif() message(STATUS "Later Return") endfunction() do_the_thing(TRUE) do_the_thing(FALSE)
Results in:
$ cmake ../returntest -- Early Return -- Later Return -- Configuring done ...
It also works outside of functions: if you call it from the include()
ed file, it returns to inclusion, if you call it from the file via add_subdirectory()
, it will return you to the parent file.
source share