Introduce "generator expressions" to add_test()
[cmake.git] / Tests / CMakeBuildTest.cmake.in
blob9c3002bc9e4025dc7cf7d092925410bb9ce9b991
1 # create the binary directory
2 make_directory("@CMAKE_BUILD_TEST_BINARY_DIR@")
4 # remove the CMakeCache.txt file from the source dir
5 # if there is one, so that in-source cmake tests
6 # still pass
7 message("Remove: @CMAKE_BUILD_TEST_SOURCE_DIR@/CMakeCache.txt")
8 file(REMOVE "@CMAKE_BUILD_TEST_SOURCE_DIR@/CMakeCache.txt")
10 # run cmake in the binary directory 
11 message("running: ${CMAKE_COMMAND}")
12 execute_process(COMMAND "${CMAKE_COMMAND}"
13   "@CMAKE_BUILD_TEST_SOURCE_DIR@"  
14   "-G@CMAKE_TEST_GENERATOR@"
15   WORKING_DIRECTORY "@CMAKE_BUILD_TEST_BINARY_DIR@"
16   RESULT_VARIABLE RESULT)
17 if(RESULT)
18   message(FATAL_ERROR "Error running cmake command")
19 endif(RESULT)
21 # Now use the --build option to build the project
22 message("running: ${CMAKE_COMMAND} --build")
23 execute_process(COMMAND "${CMAKE_COMMAND}" 
24   --build "@CMAKE_BUILD_TEST_BINARY_DIR@" --config Debug
25   RESULT_VARIABLE RESULT)
26 if(RESULT)
27   message(FATAL_ERROR "Error running cmake --build")
28 endif(RESULT)
30 # check for configuration types
31 set(CMAKE_CONFIGURATION_TYPES @CMAKE_CONFIGURATION_TYPES@)
32 # run the executable out of the Debug directory if there 
33 # are configuration types
34 if(CMAKE_CONFIGURATION_TYPES)
35   set(RUN_TEST "@CMAKE_BUILD_TEST_BINARY_DIR@/Debug/COnly")
36 else(CMAKE_CONFIGURATION_TYPES)
37   set(RUN_TEST "@CMAKE_BUILD_TEST_BINARY_DIR@/COnly")
38 endif(CMAKE_CONFIGURATION_TYPES)
39 # run the test results
40 message("running [${RUN_TEST}]")
41 execute_process(COMMAND "${RUN_TEST}" RESULT_VARIABLE RESULT)
42 if(RESULT)
43   message(FATAL_ERROR "Error running test COnly")
44 endif(RESULT)
46 # build it again with clean and only COnly target
47 execute_process(COMMAND "${CMAKE_COMMAND}" 
48   --build "@CMAKE_BUILD_TEST_BINARY_DIR@" --config Debug 
49   --clean-first --target COnly
50   RESULT_VARIABLE RESULT)
51 if(RESULT)
52   message(FATAL_ERROR "Error running cmake --build")
53 endif(RESULT)
55 # run it again after clean 
56 execute_process(COMMAND "${RUN_TEST}" RESULT_VARIABLE RESULT)
57 if(RESULT)
58   message(FATAL_ERROR "Error running test COnly after clean ")
59 endif(RESULT)