2016-12-15 3 views
6

次の例のように、CMakeの関数からどのように早く戻ってきますか?cmakeの関数からどのように早く戻ってきますか?

function do_the_thing(HAS_PROPERTY_A) 
    # don't do things that have property A when property A is disabled globally 
    if (PROPERTY_A_DISABLED AND HAS_PROPERTY_A) 
     # What do you put here to return? 
    endif() 

    # do things and implement magic 
endfunction() 

答えて

5

あなたはときに、関数で呼び出される場合、関数から返しreturn()(CMakeのマニュアルページhere)を使用します。例えば

$ cmake ../returntest 
-- Early Return 
-- Later Return 
-- Configuring done 
... 

それはあまりにも、外の機能を動作します:あなたはinclude()エドファイルからそれを呼び出す場合は、呼び出した場合、それは、includerに戻っ中

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) 

結果ファイルからadd_subdirectory()を経由した場合、親ファイルに戻ります。

+3

* double facepalm * –

関連する問題