Top level CMake (initial version)
[darwin-xtools.git] / CMakeLists.txt
blob899dac04acd862e1d24256eddf3d7aed668f9dbb
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 option(XTOOLS_LTO_SUPPORT "Support LTO in cctools and ld64." OFF)
62 set(XTOOLS_HOST_IS_64B YES)
64 SET(CMAKE_C_FLAGS_MINSIZEREL   "-Os")
65 SET(CMAKE_CXX_FLAGS_MINSIZEREL "-Os")
66 #SET(CMAKE_C_FLAGS "-Os -g")
67 #SET(CMAKE_CXX_FLAGS "-Os -g")
69 include(config-ix)
71 set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
72 if (APPLE)
73   set(CMAKE_INSTALL_NAME_DIR "@rpath")
74   set(CMAKE_INSTALL_RPATH "@executable_path/../lib")
75 else(UNIX)
76   if(NOT DEFINED CMAKE_INSTALL_RPATH)
77     set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib${UNIX_LIBDIR_SUFFIX}")
78     if (${CMAKE_SYSTEM_NAME} MATCHES FreeBSD)
79       set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,origin")
80       set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,origin")
81     endif()
82   endif(NOT DEFINED CMAKE_INSTALL_RPATH)
83 endif()
85 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
86 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
87 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/archs)
89 #include_directories("${CMAKE_SOURCE_DIR}/host-includes")
90 #link_directories("${CMAKE_SOURCE_DIR}/host-libs")
92 if( EXISTS ${CMAKE_SOURCE_DIR}/dyld/include/mach-o/dyld_priv.h)
93   configure_file(
94                 ${CMAKE_SOURCE_DIR}/dyld/include/mach-o/dyld_priv.h
95                 ${CMAKE_BINARY_DIR}/dyld-include/mach-o/dyld_priv.h
96                 COPYONLY)
97   configure_file(
98                 ${CMAKE_SOURCE_DIR}/dyld/include/mach-o/dyld.h
99                 ${CMAKE_BINARY_DIR}/dyld-include/mach-o/dyld.h
100                 COPYONLY)
101   configure_file(
102                 ${CMAKE_SOURCE_DIR}/dyld/include/mach-o/dyld_images.h
103                 ${CMAKE_BINARY_DIR}/dyld-include/mach-o/dyld_images.h
104                 COPYONLY)
105 endif()
107 # Evaluate first so that we find out about libprunetrie.
108 if( EXISTS ${CMAKE_SOURCE_DIR}/ld64/CMakeLists.txt )
109   add_subdirectory(ld64)
110 endif()
112 set(XTOOLS_HAS_LIBPRUNETRIE)
113 if( EXISTS ${CMAKE_SOURCE_DIR}/ld64/src/other/PruneTrie.cpp)
114   # We need to do this here, because cctools and ld items both want it.
115   #add_library(prunetrie ${CMAKE_SOURCE_DIR}/ld64/src/other/PruneTrie.cpp)
116   #include_directories("${CMAKE_SOURCE_DIR}/ld64/src/abstraction")
117   # put the header where we can find it.
118   configure_file(
119                 ${CMAKE_SOURCE_DIR}/ld64/src/other/prune_trie.h
120                 ${CMAKE_BINARY_DIR}/include/mach-o/prune_trie.h
121                 COPYONLY)
122   set(XTOOLS_HAS_LIBPRUNETRIE YES)
123   include_directories("${CMAKE_BINARY_DIR}/include")
124 endif()
126 if( EXISTS ${CMAKE_SOURCE_DIR}/cctools/CMakeLists.txt )
127   add_subdirectory(cctools)
128 endif()