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)
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)
20 if(CMAKE_VERSION VERSION_LESS 3.1.20141117)
21 set(cmake_3_2_USES_TERMINAL)
23 set(cmake_3_2_USES_TERMINAL USES_TERMINAL)
29 # Add path for custom modules
32 "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
33 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
36 # Keep some kind of project identifier.
38 set(XTOOLS_VERSION_MAJOR 2)
39 set(XTOOLS_VERSION_MINOR 2)
40 set(XTOOLS_VERSION_PATCH 4)
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")
49 if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE)
50 message(FATAL_ERROR "In-source builds are not allowed. ")
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")
59 message(STATUS "*Top Level* native build")
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)
66 ${XTOOLS_LTO_PATH}/include/llvm-c/lto.h
67 ${CMAKE_BINARY_DIR}/include/llvm-c/lto.h
70 ${XTOOLS_LTO_PATH}/lib/libLTO.dylib
71 ${CMAKE_BINARY_DIR}/lib/libLTO.dylib
73 option(XTOOLS_LTO_SUPPORT "Support LTO in cctools and ld64." ON)
74 message(STATUS "*Top Level* WITH LTO")
76 option(XTOOLS_LTO_SUPPORT "Support LTO in cctools and ld64." OFF)
77 message(STATUS "*Top Level* NO LTO")
80 if(XTOOLS_TAPI_PATH AND
81 EXISTS ${XTOOLS_TAPI_PATH}/include/tapi AND
82 EXISTS ${XTOOLS_TAPI_PATH}/lib/libtapi.dylib)
84 ${XTOOLS_TAPI_PATH}/lib/libtapi.dylib
85 ${CMAKE_BINARY_DIR}/lib/libtapi.dylib
87 option(XTOOLS_TAPI_SUPPORT "Support TAPI in cctools and ld64." ON)
88 message(STATUS "*Top Level* WITH TAPI")
90 option(XTOOLS_TAPI_SUPPORT "Support TAPI in cctools and ld64." OFF)
91 message(STATUS "*Top Level* NO TAPI")
94 SET(CMAKE_C_FLAGS_MINSIZEREL "-Os")
95 SET(CMAKE_CXX_FLAGS_MINSIZEREL "-Os")
96 #SET(CMAKE_C_FLAGS_DEBUG "-Og")
97 #SET(CMAKE_CXX_FLAGS_DEBUG "-Og")
101 set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
103 set(CMAKE_INSTALL_NAME_DIR "@rpath")
104 set(CMAKE_INSTALL_RPATH "@executable_path/../lib")
106 if(NOT DEFINED CMAKE_INSTALL_RPATH)
107 set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib${UNIX_LIBDIR_SUFFIX}")
108 if (${CMAKE_SYSTEM_NAME} MATCHES FreeBSD)
109 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,origin")
110 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,origin")
112 endif(NOT DEFINED CMAKE_INSTALL_RPATH)
115 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
116 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
117 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/archs)
119 #link_directories("${CMAKE_SOURCE_DIR}/host-libs")
121 # *sigh* ... re-working cctools to allow regular 'bool' is possible but quite
122 # a lot of fiddling. For now it's simply easier to use two versions of the
123 # dyld headers, one local to cctools and the ld64 one copied from up-to-date
124 # dyld. This include dir should NOT be used for cctools.
125 if( EXISTS ${CMAKE_SOURCE_DIR}/dyld/include/mach-o/dyld_priv.h)
127 ${CMAKE_SOURCE_DIR}/dyld/include/mach-o/dyld_priv.h
128 ${CMAKE_BINARY_DIR}/dyld-include/mach-o/dyld_priv.h
131 ${CMAKE_SOURCE_DIR}/dyld/include/mach-o/dyld.h
132 ${CMAKE_BINARY_DIR}/dyld-include/mach-o/dyld.h
135 ${CMAKE_SOURCE_DIR}/dyld/include/mach-o/dyld_images.h
136 ${CMAKE_BINARY_DIR}/dyld-include/mach-o/dyld_images.h
140 include_directories(BEFORE SYSTEM "${CMAKE_SOURCE_DIR}/macho-target-includes")
141 include_directories(BEFORE SYSTEM "${CMAKE_BINARY_DIR}/include")
142 include_directories(BEFORE SYSTEM "${CMAKE_BINARY_DIR}/host-includes")
143 if(XTOOLS_TAPI_SUPPORT)
144 include_directories(BEFORE SYSTEM "${XTOOLS_TAPI_PATH}/include")
145 message(STATUS "*Top Level* including ${XTOOLS_TAPI_PATH}/include")
148 if (EXISTS ${CMAKE_BINARY_DIR}/lib)
149 link_directories("${CMAKE_BINARY_DIR}/lib")
151 if (EXISTS ${CMAKE_BINARY_DIR}/archs)
152 link_directories("${CMAKE_BINARY_DIR}/archs")
155 if(XTOOLS_NEEDS_STRLIB)
156 add_subdirectory(strlib)
158 ${CMAKE_SOURCE_DIR}/strlib/string.h
159 ${CMAKE_BINARY_DIR}/host-includes/string.h
163 # Darwin < 10 doesn't specify the uuid_string_t, provide it here.
164 configure_file(${CMAKE_SOURCE_DIR}/host-includes/uuid/uuid.h
165 ${CMAKE_BINARY_DIR}/host-includes/uuid/uuid.h
168 if (NOT XTOOLS_HAS_MODERNXAR)
169 add_subdirectory(xar-additions)
171 ${CMAKE_SOURCE_DIR}/xar-additions/xar.h
172 ${CMAKE_BINARY_DIR}/host-includes/xar/xar.h
176 # Evaluate first so that we find out about libprunetrie.
177 if( EXISTS ${CMAKE_SOURCE_DIR}/ld64/CMakeLists.txt )
178 add_subdirectory(ld64)
181 set(XTOOLS_HAS_LIBPRUNETRIE)
182 if( EXISTS ${CMAKE_SOURCE_DIR}/ld64/src/other/PruneTrie.cpp)
183 # We need to do this here, because cctools and ld items both want it.
184 #add_library(prunetrie ${CMAKE_SOURCE_DIR}/ld64/src/other/PruneTrie.cpp)
185 #include_directories("${CMAKE_SOURCE_DIR}/ld64/src/abstraction")
186 # put the header where we can find it.
188 ${CMAKE_SOURCE_DIR}/ld64/src/other/prune_trie.h
189 ${CMAKE_BINARY_DIR}/include/mach-o/prune_trie.h
191 set(XTOOLS_HAS_LIBPRUNETRIE YES)
194 if( EXISTS ${CMAKE_SOURCE_DIR}/cctools/CMakeLists.txt )
195 add_subdirectory(cctools)