1 cmake_minimum_required(VERSION 2.6)
4 function(test_for_xcode4 result_var)
5 set(${result_var} 0 PARENT_SCOPE)
7 execute_process(COMMAND xcodebuild -version
8 OUTPUT_VARIABLE ov RESULT_VARIABLE rv
10 if("${rv}" STREQUAL "0")
11 if(ov MATCHES "^Xcode 4.[0-9].*$")
12 set(${result_var} 1 PARENT_SCOPE)
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)
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)
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
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
42 # Add a generated header that does NOT regenerate when the generator
45 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/noregen.h
46 COMMAND generator ${CMAKE_CURRENT_BINARY_DIR}/noregen.h noregen
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")
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
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)
67 IMPLICIT_DEPENDS CXX ${CMAKE_CURRENT_SOURCE_DIR}/dep_custom.cxx
68 CXX ${CMAKE_CURRENT_SOURCE_DIR}/dep_custom2.cxx )
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)
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
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
89 add_custom_target(zot_custom ALL DEPENDS
90 ${CMAKE_CURRENT_BINARY_DIR}/zot_custom.hxx)
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)
96 # Test the #include line macro transformation rule support.
99 PROPERTY IMPLICIT_DEPENDS_INCLUDE_TRANSFORM "ZOT_TGT(%)=<zot_%_tgt.hxx>"
104 PROPERTY IMPLICIT_DEPENDS_INCLUDE_TRANSFORM "ZOT_DIR(%)=<zot_%_dir.hxx>"
107 if(TEST_LINK_DEPENDS)
108 add_executable(linkdep linkdep.cxx)
109 set_property(TARGET linkdep PROPERTY LINK_DEPENDS ${TEST_LINK_DEPENDS})
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
125 add_dependencies(link_depends_no_shared_check link_depends_no_shared_exe)