2005-06-16 22:56:28 +04: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 (MacroTest)
|
2005-06-16 22:56:28 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
macro(FAILED testname)
|
|
|
|
message(SEND_ERROR "${testname} failed ${ARGN}")
|
2012-08-13 21:50:14 +04:00
|
|
|
endmacro()
|
2005-06-16 22:56:28 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
macro(PASS testname)
|
|
|
|
message("${testname} passed ${ARGN}")
|
2012-08-13 21:50:14 +04:00
|
|
|
endmacro()
|
2005-06-16 22:56:28 +04:00
|
|
|
|
|
|
|
# test ARGC
|
2012-08-13 21:47:32 +04:00
|
|
|
macro(weird_name)
|
|
|
|
if("${ARGC}" EQUAL "3")
|
2005-06-16 22:56:28 +04:00
|
|
|
PASS("ARGC")
|
2012-08-13 21:50:14 +04:00
|
|
|
else()
|
2005-06-16 22:56:28 +04:00
|
|
|
FAILED("ARGC" "Got: ${ARGC}")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
|
|
|
endmacro()
|
2005-06-16 22:56:28 +04:00
|
|
|
WeIrD_nAmE(a1 a2 a3)
|
|
|
|
|
|
|
|
# test ARGN
|
2012-08-13 21:47:32 +04:00
|
|
|
macro(test_argn_macro argument)
|
|
|
|
if("${ARGN}" EQUAL "3")
|
2005-06-16 22:56:28 +04:00
|
|
|
PASS("ARGN")
|
2012-08-13 21:50:14 +04:00
|
|
|
else()
|
2005-06-16 22:56:28 +04:00
|
|
|
FAILED("ARGN" "Got: ${ARGN}")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
|
|
|
endmacro()
|
2005-06-16 22:56:28 +04:00
|
|
|
Test_Argn_Macro(ignored 3)
|
|
|
|
|
|
|
|
# case test
|
2012-08-13 21:47:32 +04:00
|
|
|
macro(strange_macro m)
|
|
|
|
set("${m}" strange_macro)
|
2012-08-13 21:50:14 +04:00
|
|
|
endmacro()
|
2005-06-16 22:56:28 +04:00
|
|
|
STRANGE_MACRO(var)
|
|
|
|
set(second_var "second_var")
|
2012-08-13 21:47:32 +04:00
|
|
|
if("${var}" STREQUAL "strange_macro" AND "${second_var}" STREQUAL "second_var")
|
2005-06-16 22:56:28 +04:00
|
|
|
PASS("Case Test" "(${var} ${second_var})")
|
2012-08-13 21:50:14 +04:00
|
|
|
else()
|
2005-06-16 22:56:28 +04:00
|
|
|
FAILED("Case test" "(${var} ${second_var})")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2005-06-16 22:56:28 +04:00
|
|
|
|
|
|
|
# test backing up command
|
2012-08-13 21:47:32 +04:00
|
|
|
macro(ADD_EXECUTABLE exec)
|
2005-06-16 22:56:28 +04:00
|
|
|
_ADD_EXECUTABLE("mini${exec}" ${ARGN})
|
2012-08-13 21:50:14 +04:00
|
|
|
endmacro()
|
2005-08-01 07:02:22 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
include(CheckCSourceCompiles)
|
2005-08-01 07:02:22 +04:00
|
|
|
Check_C_Source_Compiles(
|
|
|
|
"
|
|
|
|
#include <stdio.h>
|
|
|
|
#ifdef __CLASSIC_C__
|
|
|
|
int main(){
|
|
|
|
int ac;
|
|
|
|
char*av[];
|
|
|
|
#else
|
|
|
|
int main(int ac, char*av[]){
|
|
|
|
#endif
|
|
|
|
if(ac > 1000){return *av[0];}
|
|
|
|
return 0;
|
|
|
|
}"
|
|
|
|
SOME_CHECK)
|
2012-08-13 21:47:32 +04:00
|
|
|
if(SOME_CHECK)
|
|
|
|
message("CheckCSourceCompiles works")
|
2012-08-13 21:50:14 +04:00
|
|
|
else()
|
2012-08-13 21:47:32 +04:00
|
|
|
message(FATAL_ERROR "CheckCSourceCompiles does not work")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2005-08-01 07:02:22 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
include(CheckCXXSourceCompiles)
|
2005-08-01 07:05:05 +04:00
|
|
|
Check_CXX_Source_Compiles(
|
|
|
|
"
|
|
|
|
#include <stdio.h>
|
|
|
|
int main(int ac, char*av[]){
|
|
|
|
if(ac > 1000){return *av[0];}
|
|
|
|
return 0;
|
|
|
|
}"
|
|
|
|
SOME_CHECK)
|
2012-08-13 21:47:32 +04:00
|
|
|
if(SOME_CHECK)
|
|
|
|
message("CheckCXXSourceCompiles works")
|
2012-08-13 21:50:14 +04:00
|
|
|
else()
|
2012-08-13 21:47:32 +04:00
|
|
|
message(FATAL_ERROR "CheckCXXSourceCompiles does not work")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2005-08-01 07:05:05 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
add_executable(MacroTest macroTest.c)
|
2009-03-25 17:37:04 +03:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
macro(GET_CURRENT_FILE var)
|
|
|
|
set(${var} ${CMAKE_CURRENT_LIST_FILE})
|
2012-08-13 21:50:14 +04:00
|
|
|
endmacro()
|
2012-08-13 21:47:32 +04:00
|
|
|
include(context.cmake)
|