2007-12-03 20:44:42 +03:00
|
|
|
# a simple C only test case
|
2008-03-25 18:27:18 +03:00
|
|
|
cmake_minimum_required (VERSION 2.6)
|
2012-08-13 21:47:32 +04:00
|
|
|
project (FunctionTest)
|
2007-12-03 20:44:42 +03:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
function(FAILED testname)
|
|
|
|
message(SEND_ERROR "${testname} failed ${ARGN}")
|
2012-08-13 21:50:14 +04:00
|
|
|
endfunction()
|
2007-12-03 20:44:42 +03:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
function(PASS testname)
|
|
|
|
message("${testname} passed ${ARGN}")
|
2012-08-13 21:50:14 +04:00
|
|
|
endfunction()
|
2007-12-03 20:44:42 +03:00
|
|
|
|
|
|
|
|
|
|
|
# test scope
|
2012-08-13 21:47:32 +04:00
|
|
|
set(COUNT 3)
|
|
|
|
function(scope_test)
|
|
|
|
set(COUNT 4)
|
2012-08-13 21:50:14 +04:00
|
|
|
endfunction()
|
2007-12-03 20:44:42 +03:00
|
|
|
scope_test()
|
2012-08-13 21:47:32 +04:00
|
|
|
if(COUNT EQUAL "3")
|
2007-12-03 20:44:42 +03:00
|
|
|
PASS("scope")
|
2012-08-13 21:50:14 +04:00
|
|
|
else()
|
2007-12-03 20:44:42 +03:00
|
|
|
FAILED("COUNT Got: ${COUNT}")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2007-12-03 20:44:42 +03:00
|
|
|
|
|
|
|
# test ARGC
|
2012-08-13 21:47:32 +04:00
|
|
|
function(weird_name)
|
|
|
|
if("${ARGC}" EQUAL "3")
|
2007-12-03 20:44:42 +03:00
|
|
|
PASS("ARGC")
|
2012-08-13 21:50:14 +04:00
|
|
|
else()
|
2007-12-03 20:44:42 +03:00
|
|
|
FAILED("ARGC" "Got: ${ARGC}")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
|
|
|
endfunction()
|
2007-12-03 20:44:42 +03:00
|
|
|
WeIrD_nAmE(a1 a2 a3)
|
|
|
|
|
|
|
|
# test ARGN
|
2012-08-13 21:47:32 +04:00
|
|
|
function(test_argn_function argument)
|
|
|
|
if("${ARGN}" EQUAL "3")
|
2007-12-03 20:44:42 +03:00
|
|
|
PASS("ARGN")
|
2012-08-13 21:50:14 +04:00
|
|
|
else()
|
2007-12-03 20:44:42 +03:00
|
|
|
FAILED("ARGN" "Got: ${ARGN}")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
|
|
|
endfunction()
|
2007-12-03 20:44:42 +03:00
|
|
|
Test_Argn_Function(ignored 3)
|
|
|
|
|
2008-01-03 19:22:33 +03:00
|
|
|
# test argument naming and raise scope
|
|
|
|
function(track_find_variable cache_variable is_changed)
|
2008-01-18 23:52:54 +03:00
|
|
|
set("${is_changed}" changed PARENT_SCOPE)
|
2012-08-13 21:50:14 +04:00
|
|
|
endfunction()
|
2008-01-03 19:22:33 +03:00
|
|
|
track_find_variable(testvar is_changed)
|
|
|
|
if ("${is_changed}" STREQUAL changed)
|
|
|
|
pass("same argument name test")
|
2012-08-13 21:50:14 +04:00
|
|
|
else ()
|
2008-01-03 19:22:33 +03:00
|
|
|
pass("same argument name test")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif ()
|
2008-01-03 19:22:33 +03:00
|
|
|
|
|
|
|
include("Util.cmake")
|
|
|
|
tester()
|
|
|
|
if (tester_res STREQUAL "${CMAKE_CURRENT_LIST_FILE}")
|
|
|
|
pass("CMAKE_CURRENT_LIST_FILE test")
|
2012-08-13 21:50:14 +04:00
|
|
|
else ()
|
2008-01-03 19:22:33 +03:00
|
|
|
pass("CMAKE_CURRENT_LIST_FILE test")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif ()
|
2008-01-03 19:22:33 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
2008-01-18 23:52:54 +03:00
|
|
|
# test recursion and return via set(... PARENT_SCOPE)
|
2007-12-03 20:44:42 +03:00
|
|
|
function (factorial argument result)
|
|
|
|
if (argument LESS 2)
|
2008-01-03 19:22:33 +03:00
|
|
|
set (lresult 1)
|
2012-08-13 21:50:14 +04:00
|
|
|
else ()
|
2007-12-03 20:44:42 +03:00
|
|
|
math (EXPR temp "${argument} - 1")
|
|
|
|
factorial (${temp} tresult)
|
2008-01-03 19:22:33 +03:00
|
|
|
math (EXPR lresult "${argument}*${tresult}")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif ()
|
2008-01-18 23:52:54 +03:00
|
|
|
set ("${result}" "${lresult}" PARENT_SCOPE)
|
2012-08-13 21:50:14 +04:00
|
|
|
endfunction ()
|
2007-12-03 20:44:42 +03:00
|
|
|
|
|
|
|
factorial (5 fresult)
|
|
|
|
if (fresult EQUAL 120)
|
|
|
|
pass("factorial")
|
2012-08-13 21:50:14 +04:00
|
|
|
else ()
|
2007-12-03 20:44:42 +03:00
|
|
|
failed ("factorial, computed ${fresult} instead of 120")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif ()
|
2007-12-03 20:44:42 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# case test
|
2012-08-13 21:47:32 +04:00
|
|
|
function(strange_function m)
|
|
|
|
set("${m}" strange_function PARENT_SCOPE)
|
2012-08-13 21:50:14 +04:00
|
|
|
endfunction()
|
2008-01-18 23:52:54 +03:00
|
|
|
|
2007-12-03 20:44:42 +03:00
|
|
|
STRANGE_FUNCTION(var)
|
|
|
|
set(second_var "second_var")
|
2012-08-13 21:47:32 +04:00
|
|
|
if("${var}" STREQUAL "strange_function" AND "${second_var}" STREQUAL "second_var")
|
2007-12-03 20:44:42 +03:00
|
|
|
PASS("Case Test" "(${var} ${second_var})")
|
2012-08-13 21:50:14 +04:00
|
|
|
else()
|
2007-12-03 20:44:42 +03:00
|
|
|
FAILED("Case test" "(${var} ${second_var})")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2007-12-03 20:44:42 +03:00
|
|
|
|
|
|
|
# test backing up command
|
2012-08-13 21:47:32 +04:00
|
|
|
function(ADD_EXECUTABLE exec)
|
2007-12-03 20:44:42 +03:00
|
|
|
_ADD_EXECUTABLE(mini${exec} ${ARGN})
|
2012-08-13 21:50:14 +04:00
|
|
|
endfunction()
|
2007-12-03 20:44:42 +03:00
|
|
|
|
2008-01-03 01:49:16 +03:00
|
|
|
# var undef case
|
2012-08-13 21:47:32 +04:00
|
|
|
function(undef_var m)
|
|
|
|
set("${m}" PARENT_SCOPE)
|
2012-08-13 21:50:14 +04:00
|
|
|
endfunction()
|
2008-01-18 23:52:54 +03:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
set(FUNCTION_UNDEFINED 1)
|
2008-01-03 01:49:16 +03:00
|
|
|
undef_var(FUNCTION_UNDEFINED)
|
2012-08-13 21:47:32 +04:00
|
|
|
if(DEFINED FUNCTION_UNDEFINED)
|
2008-01-03 01:49:16 +03:00
|
|
|
FAILED("Function Undefine Test" "(${FUNCTION_UNDEFINED})")
|
2012-08-13 21:50:14 +04:00
|
|
|
else()
|
2008-01-03 01:49:16 +03:00
|
|
|
PASS("Function Undefine Test" "(${FUNCTION_UNDEFINED})")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2008-01-03 01:49:16 +03:00
|
|
|
|
|
|
|
# Subdirectory scope raise.
|
2012-08-13 21:47:32 +04:00
|
|
|
set(SUBDIR_UNDEFINED 1)
|
|
|
|
add_subdirectory(SubDirScope)
|
|
|
|
if(DEFINED SUBDIR_UNDEFINED)
|
2008-01-03 01:49:16 +03:00
|
|
|
FAILED("Subdir Undefine Test" "(${SUBDIR_UNDEFINED})")
|
2012-08-13 21:50:14 +04:00
|
|
|
else()
|
2008-01-03 01:49:16 +03:00
|
|
|
PASS("Subdir Undefine Test" "(${SUBDIR_UNDEFINED})")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2012-08-13 21:47:32 +04:00
|
|
|
if(DEFINED SUBDIR_DEFINED)
|
2008-01-03 01:49:16 +03:00
|
|
|
PASS("Subdir Define Test" "(${SUBDIR_DEFINED})")
|
2012-08-13 21:50:14 +04:00
|
|
|
else()
|
2008-01-03 01:49:16 +03:00
|
|
|
FAILED("Subdir Define Test" "(${SUBDIR_DEFINED})")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2008-01-03 01:49:16 +03:00
|
|
|
|
2009-09-16 17:52:04 +04:00
|
|
|
# Test function-scoped directory.
|
2012-08-13 21:47:32 +04:00
|
|
|
function(ADD_SUBDIR2 dir)
|
|
|
|
add_subdirectory("${dir}" "${dir}2")
|
2009-09-16 17:52:04 +04:00
|
|
|
# The parent scope sets in the subdir should be visible here.
|
2012-08-13 21:47:32 +04:00
|
|
|
if(DEFINED SUBDIR_UNDEFINED)
|
2009-09-16 17:52:04 +04:00
|
|
|
FAILED("Subdir Function Undefine Test 1" "(${SUBDIR_UNDEFINED})")
|
2012-08-13 21:50:14 +04:00
|
|
|
else()
|
2009-09-16 17:52:04 +04:00
|
|
|
PASS("Subdir Function Undefine Test 1" "(${SUBDIR_UNDEFINED})")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2012-08-13 21:47:32 +04:00
|
|
|
if(DEFINED SUBDIR_DEFINED)
|
2009-09-16 17:52:04 +04:00
|
|
|
PASS("Subdir Function Define Test 1" "(${SUBDIR_DEFINED})")
|
2012-08-13 21:50:14 +04:00
|
|
|
else()
|
2009-09-16 17:52:04 +04:00
|
|
|
FAILED("Subdir Function Define Test 1" "(${SUBDIR_DEFINED})")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
|
|
|
endfunction()
|
2009-09-16 17:52:04 +04:00
|
|
|
|
|
|
|
# Reset test variables.
|
2012-08-13 21:47:32 +04:00
|
|
|
set(SUBDIR_UNDEFINED 1)
|
|
|
|
set(SUBDIR_DEFINED)
|
2009-09-16 17:52:04 +04:00
|
|
|
|
|
|
|
# Run test function.
|
|
|
|
ADD_SUBDIR2(SubDirScope)
|
|
|
|
|
|
|
|
# The parent scope sets in the subdir should not be visible here.
|
2012-08-13 21:47:32 +04:00
|
|
|
if(DEFINED SUBDIR_UNDEFINED)
|
2009-09-16 17:52:04 +04:00
|
|
|
PASS("Subdir Function Undefine Test 2" "(${SUBDIR_UNDEFINED})")
|
2012-08-13 21:50:14 +04:00
|
|
|
else()
|
2009-09-16 17:52:04 +04:00
|
|
|
FAILED("Subdir Function Undefine Test 2" "(${SUBDIR_UNDEFINED})")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2012-08-13 21:47:32 +04:00
|
|
|
if(DEFINED SUBDIR_DEFINED)
|
2009-09-16 17:52:04 +04:00
|
|
|
FAILED("Subdir Function Define Test 2" "(${SUBDIR_DEFINED})")
|
2012-08-13 21:50:14 +04:00
|
|
|
else()
|
2009-09-16 17:52:04 +04:00
|
|
|
PASS("Subdir Function Define Test 2" "(${SUBDIR_DEFINED})")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2009-09-16 17:52:04 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
add_executable(FunctionTest functionTest.c)
|
2010-09-10 00:21:57 +04:00
|
|
|
|
|
|
|
# Use the PROJECT_LABEL property: in IDEs, the project label should appear
|
|
|
|
# in the UI rather than the target name. If this were a good test of the
|
|
|
|
# property rather than just a smoke test, it would verify that the label
|
|
|
|
# actually appears in the UI of the IDE... Or at least that the text appears
|
|
|
|
# somewhere in the generated project files.
|
2012-08-13 21:47:32 +04:00
|
|
|
set_property(TARGET miniFunctionTest
|
2010-09-10 00:21:57 +04:00
|
|
|
PROPERTY PROJECT_LABEL "Test de Fonctionnement")
|