cctools
[darwin-xtools/darwin-xtools-svp.git] / CMakeLists.txt
blobd03058c10079debe7757d4d5fb854e369b9bafc1
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 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")
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 if(XTOOLS_TAPI_PATH AND
81    EXISTS ${XTOOLS_TAPI_PATH}/include/tapi AND
82    EXISTS ${XTOOLS_TAPI_PATH}/lib/libtapi.dylib)
83   configure_file(
84                 ${XTOOLS_TAPI_PATH}/lib/libtapi.dylib
85                 ${CMAKE_BINARY_DIR}/lib/libtapi.dylib
86                 COPYONLY)
87   option(XTOOLS_TAPI_SUPPORT "Support TAPI in cctools and ld64." ON)
88   message(STATUS "*Top Level* WITH TAPI")
89 else()
90   option(XTOOLS_TAPI_SUPPORT "Support TAPI in cctools and ld64." OFF)
91   message(STATUS "*Top Level* NO TAPI")
92 endif()
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")
99 include(config-ix)
101 set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
102 if (APPLE)
103   set(CMAKE_INSTALL_NAME_DIR "@rpath")
104   set(CMAKE_INSTALL_RPATH "@executable_path/../lib")
105 else(UNIX)
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")
111     endif()
112   endif(NOT DEFINED CMAKE_INSTALL_RPATH)
113 endif()
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)
126   configure_file(
127                 ${CMAKE_SOURCE_DIR}/dyld/include/mach-o/dyld_priv.h
128                 ${CMAKE_BINARY_DIR}/dyld-include/mach-o/dyld_priv.h
129                 COPYONLY)
130   configure_file(
131                 ${CMAKE_SOURCE_DIR}/dyld/include/mach-o/dyld.h
132                 ${CMAKE_BINARY_DIR}/dyld-include/mach-o/dyld.h
133                 COPYONLY)
134   configure_file(
135                ${CMAKE_SOURCE_DIR}/dyld/include/mach-o/dyld_images.h
136                 ${CMAKE_BINARY_DIR}/dyld-include/mach-o/dyld_images.h
137                 COPYONLY)
138 endif()
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")
146 endif()
148 if (EXISTS ${CMAKE_BINARY_DIR}/lib)
149   link_directories("${CMAKE_BINARY_DIR}/lib")
150 endif()
151 if (EXISTS ${CMAKE_BINARY_DIR}/archs)
152   link_directories("${CMAKE_BINARY_DIR}/archs")
153 endif()
155 if(XTOOLS_NEEDS_STRLIB)
156   add_subdirectory(strlib)
157   configure_file(
158                 ${CMAKE_SOURCE_DIR}/strlib/string.h
159                 ${CMAKE_BINARY_DIR}/host-includes/string.h
160                 COPYONLY)
161 endif()
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
166                COPYONLY)
168 if (NOT XTOOLS_HAS_MODERNXAR)
169   add_subdirectory(xar-additions)
170   configure_file(
171                 ${CMAKE_SOURCE_DIR}/xar-additions/xar.h
172                 ${CMAKE_BINARY_DIR}/host-includes/xar/xar.h
173                 COPYONLY)
174 endif()
176 # Evaluate first so that we find out about libprunetrie.
177 if( EXISTS ${CMAKE_SOURCE_DIR}/ld64/CMakeLists.txt )
178   add_subdirectory(ld64)
179 endif()
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.
187   configure_file(
188                 ${CMAKE_SOURCE_DIR}/ld64/src/other/prune_trie.h
189                 ${CMAKE_BINARY_DIR}/include/mach-o/prune_trie.h
190                 COPYONLY)
191   set(XTOOLS_HAS_LIBPRUNETRIE YES)
192 endif()
194 if( EXISTS ${CMAKE_SOURCE_DIR}/cctools/CMakeLists.txt )
195   add_subdirectory(cctools)
196 endif()