[top level] Bump for xc 7.3.1 updates (886, 264.3.102)
[darwin-xtools.git] / CMakeLists.txt
blobab5ce295fda5e432db11a25978524f88f6d50043
1 # Top Level CMake file for XTOOLS.
3 cmake_minimum_required(VERSION 2.8.12.2)
5 if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
6   message(STATUS "No build type selected, default to MinSizeRel")
7   set(CMAKE_BUILD_TYPE MinSizeRel)
8   set(XTOOLS_ENABLE_ASSERTIONS 1)
9 endif()
11 if (POLICY CMP0051)
12   # CMake 3.1 and higher include generator expressions of the form
13   # $<TARGETLIB:obj> in the SOURCES property.  These need to be
14   # stripped everywhere that access the SOURCES property, so we just
15   # defer to the OLD behavior of not including generator expressions
16   # in the output for now.
17   cmake_policy(SET CMP0051 OLD)
18 endif()
20 if(CMAKE_VERSION VERSION_LESS 3.1.20141117)
21   set(cmake_3_2_USES_TERMINAL)
22 else()
23   set(cmake_3_2_USES_TERMINAL USES_TERMINAL)
24 endif()
26 project(XTOOLS)
27 include(CTest)
29 # Add path for custom modules
30 set(CMAKE_MODULE_PATH
31   ${CMAKE_MODULE_PATH}
32   "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
33   "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
34   )
36 # Keep some kind of project identifier.
38 set(XTOOLS_VERSION_MAJOR 1)
39 set(XTOOLS_VERSION_MINOR 2)
40 set(XTOOLS_VERSION_PATCH 0)
41 set(XTOOLS_VERSION_SUFFIX git)
43 set(XTOOLS_VERSION "${XTOOLS_VERSION_MAJOR}.${XTOOLS_VERSION_MINOR}.${XTOOLS_VERSION_PATCH}")
45 if (NOT PACKAGE_VERSION)
46   set(PACKAGE_VERSION "unpackaged")
47 endif()
48   
49 if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE)
50   message(FATAL_ERROR "In-source builds are not allowed. ")
51 endif()
53 string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
54 set(UNIX_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" )
56 if(CMAKE_CROSSCOMPILING)
57   message(STATUS "*Top Level* Cross compiling")
58 else()
59   message(STATUS "*Top Level* native build")
60 endif()
62 if(XTOOLS_LTO_PATH AND
63    EXISTS ${XTOOLS_LTO_PATH}/include/llvm-c/lto.h AND
64    EXISTS ${XTOOLS_LTO_PATH}/lib/libLTO.dylib)
65   configure_file(
66                 ${XTOOLS_LTO_PATH}/include/llvm-c/lto.h
67                 ${CMAKE_BINARY_DIR}/include/llvm-c/lto.h
68                 COPYONLY)
69   configure_file(
70                 ${XTOOLS_LTO_PATH}/lib/libLTO.dylib
71                 ${CMAKE_BINARY_DIR}/lib/libLTO.dylib
72                 COPYONLY)
73   option(XTOOLS_LTO_SUPPORT "Support LTO in cctools and ld64." ON)
74   message(STATUS "*Top Level* WITH LTO")
75 else()
76   option(XTOOLS_LTO_SUPPORT "Support LTO in cctools and ld64." OFF)
77   message(STATUS "*Top Level* NO LTO")
78 endif()
80 SET(CMAKE_C_FLAGS_MINSIZEREL   "-Os")
81 SET(CMAKE_CXX_FLAGS_MINSIZEREL "-Os")
82 #SET(CMAKE_C_FLAGS_DEBUG "-Og")
83 #SET(CMAKE_CXX_FLAGS_DEBUG "-Og")
85 include(config-ix)
87 set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
88 if (APPLE)
89   set(CMAKE_INSTALL_NAME_DIR "@rpath")
90   set(CMAKE_INSTALL_RPATH "@executable_path/../lib")
91 else(UNIX)
92   if(NOT DEFINED CMAKE_INSTALL_RPATH)
93     set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib${UNIX_LIBDIR_SUFFIX}")
94     if (${CMAKE_SYSTEM_NAME} MATCHES FreeBSD)
95       set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,origin")
96       set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,origin")
97     endif()
98   endif(NOT DEFINED CMAKE_INSTALL_RPATH)
99 endif()
101 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
102 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
103 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/archs)
105 #link_directories("${CMAKE_SOURCE_DIR}/host-libs")
107 # *sigh* ... re-working cctools to allow regular 'bool' is possible but quite
108 # a lot of fiddling.  For now it's simply easier to use two versions of the
109 # dyld headers, one local to cctools and the ld64 one copied from up-to-date
110 # dyld.  This include dir should NOT be used for cctools.
111 if( EXISTS ${CMAKE_SOURCE_DIR}/dyld/include/mach-o/dyld_priv.h)
112   configure_file(
113                 ${CMAKE_SOURCE_DIR}/dyld/include/mach-o/dyld_priv.h
114                 ${CMAKE_BINARY_DIR}/dyld-include/mach-o/dyld_priv.h
115                 COPYONLY)
116   configure_file(
117                 ${CMAKE_SOURCE_DIR}/dyld/include/mach-o/dyld.h
118                 ${CMAKE_BINARY_DIR}/dyld-include/mach-o/dyld.h
119                 COPYONLY)
120   configure_file(
121                ${CMAKE_SOURCE_DIR}/dyld/include/mach-o/dyld_images.h
122                 ${CMAKE_BINARY_DIR}/dyld-include/mach-o/dyld_images.h
123                 COPYONLY)
124 endif()
126 include_directories(BEFORE SYSTEM "${CMAKE_SOURCE_DIR}/macho-target-includes")
127 include_directories(BEFORE SYSTEM "${CMAKE_BINARY_DIR}/include")
128 include_directories(BEFORE SYSTEM "${CMAKE_BINARY_DIR}/host-includes")
129 if (EXISTS ${CMAKE_BINARY_DIR}/lib)
130   link_directories("${CMAKE_BINARY_DIR}/lib")
131 endif()
132 if (EXISTS ${CMAKE_BINARY_DIR}/archs)
133   link_directories("${CMAKE_BINARY_DIR}/archs")
134 endif()
136 if(XTOOLS_NEEDS_STRLIB)
137   add_subdirectory(strlib)
138   configure_file(
139                 ${CMAKE_SOURCE_DIR}/strlib/string.h
140                 ${CMAKE_BINARY_DIR}/host-includes/string.h
141                 COPYONLY)
142 endif()
144 # Darwin < 10 doesn't specify the uuid_string_t, provide it here.
145 configure_file(${CMAKE_SOURCE_DIR}/host-includes/uuid/uuid.h
146                ${CMAKE_BINARY_DIR}/host-includes/uuid/uuid.h
147                COPYONLY)
149 if (NOT XTOOLS_HAS_MODERNXAR)
150   add_subdirectory(xar-additions)
151   configure_file(
152                 ${CMAKE_SOURCE_DIR}/xar-additions/xar.h
153                 ${CMAKE_BINARY_DIR}/host-includes/xar/xar.h
154                 COPYONLY)
155 endif()
157 # Evaluate first so that we find out about libprunetrie.
158 if( EXISTS ${CMAKE_SOURCE_DIR}/ld64/CMakeLists.txt )
159   add_subdirectory(ld64)
160 endif()
162 set(XTOOLS_HAS_LIBPRUNETRIE)
163 if( EXISTS ${CMAKE_SOURCE_DIR}/ld64/src/other/PruneTrie.cpp)
164   # We need to do this here, because cctools and ld items both want it.
165   #add_library(prunetrie ${CMAKE_SOURCE_DIR}/ld64/src/other/PruneTrie.cpp)
166   #include_directories("${CMAKE_SOURCE_DIR}/ld64/src/abstraction")
167   # put the header where we can find it.
168   configure_file(
169                 ${CMAKE_SOURCE_DIR}/ld64/src/other/prune_trie.h
170                 ${CMAKE_BINARY_DIR}/include/mach-o/prune_trie.h
171                 COPYONLY)
172   set(XTOOLS_HAS_LIBPRUNETRIE YES)
173 endif()
175 if( EXISTS ${CMAKE_SOURCE_DIR}/cctools/CMakeLists.txt )
176   add_subdirectory(cctools)
177 endif()