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 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")
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 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")
87 set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
89 set(CMAKE_INSTALL_NAME_DIR "@rpath")
90 set(CMAKE_INSTALL_RPATH "@executable_path/../lib")
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")
98 endif(NOT DEFINED CMAKE_INSTALL_RPATH)
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)
113 ${CMAKE_SOURCE_DIR}/dyld/include/mach-o/dyld_priv.h
114 ${CMAKE_BINARY_DIR}/dyld-include/mach-o/dyld_priv.h
117 ${CMAKE_SOURCE_DIR}/dyld/include/mach-o/dyld.h
118 ${CMAKE_BINARY_DIR}/dyld-include/mach-o/dyld.h
121 ${CMAKE_SOURCE_DIR}/dyld/include/mach-o/dyld_images.h
122 ${CMAKE_BINARY_DIR}/dyld-include/mach-o/dyld_images.h
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")
132 if (EXISTS ${CMAKE_BINARY_DIR}/archs)
133 link_directories("${CMAKE_BINARY_DIR}/archs")
136 if(XTOOLS_NEEDS_STRLIB)
137 add_subdirectory(strlib)
139 ${CMAKE_SOURCE_DIR}/strlib/string.h
140 ${CMAKE_BINARY_DIR}/host-includes/string.h
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
149 if (NOT XTOOLS_HAS_MODERNXAR)
150 add_subdirectory(xar-additions)
152 ${CMAKE_SOURCE_DIR}/xar-additions/xar.h
153 ${CMAKE_BINARY_DIR}/host-includes/xar/xar.h
157 # Evaluate first so that we find out about libprunetrie.
158 if( EXISTS ${CMAKE_SOURCE_DIR}/ld64/CMakeLists.txt )
159 add_subdirectory(ld64)
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.
169 ${CMAKE_SOURCE_DIR}/ld64/src/other/prune_trie.h
170 ${CMAKE_BINARY_DIR}/include/mach-o/prune_trie.h
172 set(XTOOLS_HAS_LIBPRUNETRIE YES)
175 if( EXISTS ${CMAKE_SOURCE_DIR}/cctools/CMakeLists.txt )
176 add_subdirectory(cctools)