top-level - (macho-target-includes) Import libunwind.h and compact_unwind_encoding...
[darwin-xtools.git] / CMakeLists.txt
blobdff3e39b0df0e583b9ebd988d52ccf7f0a051573
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 0)
39 set(XTOOLS_VERSION_MINOR 0)
40 set(XTOOLS_VERSION_PATCH 1)
41 set(XTOOLS_VERSION_SUFFIX git)
43 if (NOT PACKAGE_VERSION)
44   set(PACKAGE_VERSION
45     "${XTOOLS_VERSION_MAJOR}.${XTOOLS_VERSION_MINOR}.${XTOOLS_VERSION_PATCH}${XTOOLS_VERSION_SUFFIX}")
46 endif()
48 if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE)
49   message(FATAL_ERROR "In-source builds are not allowed. ")
50 endif()
52 string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
53 set(UNIX_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" )
55 if(CMAKE_CROSSCOMPILING)
56   message(STATUS "*Top Level* Cross compiling")
57 else()
58   message(STATUS "*Top Level* native build")
59 endif()
61 set(LTO_PATH /compilers/clang-legacy-trunk-s1g)
62 if(EXISTS ${LTO_PATH}/include/llvm-c/lto.h AND
63    EXISTS ${LTO_PATH}/lib/libLTO.dylib)
64   configure_file(
65                 ${LTO_PATH}/include/llvm-c/lto.h
66                 ${CMAKE_BINARY_DIR}/lto-include/llvm-c/lto.h
67                 COPYONLY)
68   configure_file(
69                 ${LTO_PATH}/lib/libLTO.dylib
70                 ${CMAKE_BINARY_DIR}/lib/libLTO.dylib
71                 COPYONLY)
72   include_directories("${CMAKE_BINARY_DIR}/lto-include")
73   link_directories("${CMAKE_BINARY_DIR}/lib")
74   option(XTOOLS_LTO_SUPPORT "Support LTO in cctools and ld64." ON)
75   message(STATUS "*Top Level* WITH LTO")
76 else()
77   option(XTOOLS_LTO_SUPPORT "Support LTO in cctools and ld64." OFF)
78   message(STATUS "*Top Level* NO LTO")
79 endif()
81 set(XTOOLS_HOST_IS_64B YES)
83 SET(CMAKE_C_FLAGS_MINSIZEREL   "-Os")
84 SET(CMAKE_CXX_FLAGS_MINSIZEREL "-Os")
85 #SET(CMAKE_C_FLAGS "-Os -g")
86 #SET(CMAKE_CXX_FLAGS "-Os -g")
88 include(config-ix)
90 set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
91 if (APPLE)
92   set(CMAKE_INSTALL_NAME_DIR "@rpath")
93   set(CMAKE_INSTALL_RPATH "@executable_path/../lib")
94 else(UNIX)
95   if(NOT DEFINED CMAKE_INSTALL_RPATH)
96     set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib${UNIX_LIBDIR_SUFFIX}")
97     if (${CMAKE_SYSTEM_NAME} MATCHES FreeBSD)
98       set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,origin")
99       set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,origin")
100     endif()
101   endif(NOT DEFINED CMAKE_INSTALL_RPATH)
102 endif()
104 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
105 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
106 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/archs)
108 #include_directories("${CMAKE_SOURCE_DIR}/host-includes")
109 #link_directories("${CMAKE_SOURCE_DIR}/host-libs")
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 # Evaluate first so that we find out about libprunetrie.
127 if( EXISTS ${CMAKE_SOURCE_DIR}/ld64/CMakeLists.txt )
128   add_subdirectory(ld64)
129 endif()
131 set(XTOOLS_HAS_LIBPRUNETRIE)
132 if( EXISTS ${CMAKE_SOURCE_DIR}/ld64/src/other/PruneTrie.cpp)
133   # We need to do this here, because cctools and ld items both want it.
134   #add_library(prunetrie ${CMAKE_SOURCE_DIR}/ld64/src/other/PruneTrie.cpp)
135   #include_directories("${CMAKE_SOURCE_DIR}/ld64/src/abstraction")
136   # put the header where we can find it.
137   configure_file(
138                 ${CMAKE_SOURCE_DIR}/ld64/src/other/prune_trie.h
139                 ${CMAKE_BINARY_DIR}/include/mach-o/prune_trie.h
140                 COPYONLY)
141   set(XTOOLS_HAS_LIBPRUNETRIE YES)
142   include_directories("${CMAKE_BINARY_DIR}/include")
143 endif()
145 if( EXISTS ${CMAKE_SOURCE_DIR}/cctools/CMakeLists.txt )
146   add_subdirectory(cctools)
147 endif()