Imported Upstream version 2.8.11.2
[platform/upstream/cmake.git] / Tests / BuildDepends / Project / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.6)
2 project(testRebuild)
3
4 function(test_for_xcode4 result_var)
5   set(${result_var} 0 PARENT_SCOPE)
6   if(APPLE)
7     execute_process(COMMAND xcodebuild -version
8       OUTPUT_VARIABLE ov RESULT_VARIABLE rv
9       )
10     if("${rv}" STREQUAL "0")
11       if(ov MATCHES "^Xcode 4.[0-9].*$")
12         set(${result_var} 1 PARENT_SCOPE)
13       endif()
14     endif()
15   endif()
16 endfunction()
17
18 if(APPLE)
19   # only use multi-arch if the sysroot exists on this machine
20   # Ninja needs -M which could not be used with multiple -arch flags
21   if(EXISTS "${CMAKE_OSX_SYSROOT}" AND NOT "${CMAKE_GENERATOR}" MATCHES "Ninja")
22     set(CMAKE_OSX_ARCHITECTURES "ppc;i386")
23     test_for_xcode4(is_xcode4)
24     if(is_xcode4)
25       # Xcode 4, use modern architectures as defaults
26       # Arch 'ppc' no longer works: tools no longer available starting with Xcode 4
27       set(CMAKE_OSX_ARCHITECTURES i386 x86_64)
28     endif()
29   endif()
30 endif()
31
32 add_library(foo STATIC ${testRebuild_BINARY_DIR}/foo.cxx)
33 set_target_properties(foo PROPERTIES OUTPUT_NAME "foolib")
34 # Add a generated header that regenerates when the generator is
35 # rebuilt.
36 add_custom_command(
37   OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/regen.h
38   COMMAND generator ${CMAKE_CURRENT_BINARY_DIR}/regen.h regen
39   DEPENDS generator # adds file-level dependency to re-run rule
40   )
41
42 # Add a generated header that does NOT regenerate when the generator
43 # is rebuilt.
44 add_custom_command(
45   OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/noregen.h
46   COMMAND generator ${CMAKE_CURRENT_BINARY_DIR}/noregen.h noregen
47   )
48
49 # Test that the generator rebuilds when the static library source file
50 # changes.  This should cause regen.h to be recreated also.
51 add_executable(generator generator.cxx)
52 target_link_libraries(generator foo)
53 set_target_properties(generator PROPERTIES OUTPUT_NAME "gen")
54
55 # Build an executable to drive the build and rebuild.
56 include_directories(${CMAKE_CURRENT_BINARY_DIR})
57 add_executable(bar bar.cxx
58   ${CMAKE_CURRENT_BINARY_DIR}/regen.h
59   ${CMAKE_CURRENT_BINARY_DIR}/noregen.h
60   )
61
62 #-----------------------------------------------------------------------------
63 if("${CMAKE_GENERATOR}" MATCHES "Make")
64   # Test the IMPLICIT_DEPENDS feature.
65   set(ZOT_DEPENDS IMPLICIT_DEPENDS CXX ${CMAKE_CURRENT_SOURCE_DIR}/dep.cxx)
66   set(ZOT_CUSTOM_DEP
67     IMPLICIT_DEPENDS CXX ${CMAKE_CURRENT_SOURCE_DIR}/dep_custom.cxx
68                      CXX ${CMAKE_CURRENT_SOURCE_DIR}/dep_custom2.cxx )
69 else()
70   # No IMPLICIT_DEPENDS...just depend directly.
71   set(ZOT_DEPENDS DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/zot.hxx.in)
72   set(ZOT_CUSTOM_DEP DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/zot_custom.hxx.in)
73 endif()
74 add_custom_command(
75   OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zot.hxx
76   COMMAND ${CMAKE_COMMAND} -E copy
77   ${CMAKE_CURRENT_BINARY_DIR}/zot.hxx.in
78   ${CMAKE_CURRENT_BINARY_DIR}/zot.hxx
79   ${ZOT_DEPENDS}
80   )
81
82 add_custom_command(
83   OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zot_custom.hxx
84   COMMAND ${CMAKE_COMMAND} -E copy
85   ${CMAKE_CURRENT_BINARY_DIR}/zot_custom.hxx.in
86   ${CMAKE_CURRENT_BINARY_DIR}/zot_custom.hxx
87   ${ZOT_CUSTOM_DEP}
88   )
89 add_custom_target(zot_custom ALL DEPENDS
90   ${CMAKE_CURRENT_BINARY_DIR}/zot_custom.hxx)
91
92 add_executable(zot zot.cxx ${CMAKE_CURRENT_BINARY_DIR}/zot.hxx
93   zot_macro_dir.cxx zot_macro_tgt.cxx)
94 add_dependencies(zot zot_custom)
95
96 # Test the #include line macro transformation rule support.
97 set_property(
98   TARGET zot
99   PROPERTY IMPLICIT_DEPENDS_INCLUDE_TRANSFORM "ZOT_TGT(%)=<zot_%_tgt.hxx>"
100   )
101
102 set_property(
103   DIRECTORY
104   PROPERTY IMPLICIT_DEPENDS_INCLUDE_TRANSFORM "ZOT_DIR(%)=<zot_%_dir.hxx>"
105   )
106
107 if(TEST_LINK_DEPENDS)
108   add_executable(linkdep linkdep.cxx)
109   set_property(TARGET linkdep PROPERTY LINK_DEPENDS ${TEST_LINK_DEPENDS})
110 endif()
111
112 add_library(link_depends_no_shared_lib SHARED link_depends_no_shared_lib.c
113   ${CMAKE_CURRENT_BINARY_DIR}/link_depends_no_shared_lib.h)
114 add_executable(link_depends_no_shared_exe link_depends_no_shared_exe.c
115   ${CMAKE_CURRENT_BINARY_DIR}/link_depends_no_shared_exe.h)
116 target_link_libraries(link_depends_no_shared_exe link_depends_no_shared_lib)
117 set_property(TARGET link_depends_no_shared_exe PROPERTY LINK_DEPENDS_NO_SHARED 1)
118 add_custom_target(link_depends_no_shared_check ALL
119   COMMAND ${CMAKE_COMMAND}
120    -Dlib=$<TARGET_FILE:link_depends_no_shared_lib>
121    -Dexe=$<TARGET_FILE:link_depends_no_shared_exe>
122    -Dout=${CMAKE_CURRENT_BINARY_DIR}/link_depends_no_shared_check.txt
123    -P ${CMAKE_CURRENT_SOURCE_DIR}/link_depends_no_shared_check.cmake
124   )
125 add_dependencies(link_depends_no_shared_check link_depends_no_shared_exe)