CMakeLists.txt 7.59 KB
Newer Older
1 2 3 4
project (krita-and-all-its-deps)

#
# Build all dependencies for Krita and finally Krita itself.
5
# Parameters: EXTERNALS_DOWNLOAD_DIR place to download all packages
6
#             INSTALL_ROOT place to install everything to
7
#             MXE_TOOLCHAIN: the toolchain file to cross-compile using MXE
8
#
9 10 11 12 13
# Example usage: cmake ..\kritadeposx -DEXTERNALS_DOWNLOAD_DIR=/dev2/d -DINSTALL_ROOT=/dev2/i -DWIN64_BUILD=TRUE  -DBOOST_LIBRARYDIR=/dev2/i/lib   -G "Visual Studio 11 Win64"


cmake_minimum_required(VERSION 2.8.6)

14 15
if(NOT SUBMAKE_JOBS)
	set(SUBMAKE_JOBS 1)
16
endif()
17

18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
	message(FATAL_ERROR "Compiling in the source directory is not supported. Use for example 'mkdir build; cd build; cmake ..'.")
endif (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)

# Tools must be obtained to work with:
include (ExternalProject)

# allow specification of a directory with pre-downloaded
# requirements
if(NOT IS_DIRECTORY ${EXTERNALS_DOWNLOAD_DIR})
    message(FATAL_ERROR "No externals download dir set. Use -DEXTERNALS_DOWNLOAD_DIR")
endif()

if(NOT IS_DIRECTORY ${INSTALL_ROOT})
    message(FATAL_ERROR "No install dir set. Use -DINSTALL_ROOT")
endif()

set(TOP_INST_DIR ${INSTALL_ROOT})
set(EXTPREFIX "${TOP_INST_DIR}")
set(CMAKE_PREFIX_PATH "${EXTPREFIX}")

39
if (${CMAKE_GENERATOR} STREQUAL "Visual Studio 14 2015 Win64")
40 41 42 43 44
    SET(GLOBAL_PROFILE
        -DCMAKE_MODULE_LINKER_FLAGS=/machine:x64
        -DCMAKE_EXE_LINKER_FLAGS=/machine:x64
        -DCMAKE_SHARED_LINKER_FLAGS=/machine:x64
        -DCMAKE_STATIC_LINKER_FLAGS=/machine:x64
45 46 47 48 49 50 51
    )
endif ()

message( STATUS "CMAKE_GENERATOR: ${CMAKE_GENERATOR}")
message( STATUS "CMAKE_CL_64: ${CMAKE_CL_64}")

set(GLOBAL_BUILD_TYPE RelWithDebInfo)
52
set(GLOBAL_PROFILE ${GLOBAL_PROFILE} -DBUILD_TESTING=false)
53

54 55
if (MINGW)
	option(QT_ENABLE_DEBUG_INFO "Build Qt with debug info included" OFF)
56 57 58 59 60
	option(QT_ENABLE_DYNAMIC_OPENGL "Build Qt with dynamic ANGLE support '-opengl dynamic -angle' (needs env var 'WindowsSdkDir' set to path of Windows 10 SDK)" ON)
    if (QT_ENABLE_DYNAMIC_OPENGL)
		if (DEFINED ENV{WindowsSdkDir})
			message(STATUS "WindowsSdkDir is set to '$ENV{WindowsSdkDir}'")
		else (DEFINED ENV{WindowsSdkDir})
luz paz's avatar
luz paz committed
61
			message(FATAL_ERROR "Environment variable 'WindowsSdkDir' not set! Please set it to path of Windows 10 SDK or disable QT_ENABLE_DYNAMIC_OPENGL")
62
		endif ()
63
    endif ()
64 65
endif (MINGW)

66 67 68 69
if (WIN32)
    option(USE_QT_TABLET_WINDOWS "Do not use Krita's forked Wintab and Windows Ink support on Windows, but leave everything to Qt." ON)
endif ()

70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
set(SECURITY_EXE_LINKER_FLAGS "")
set(SECURITY_SHARED_LINKER_FLAGS "")
set(SECURITY_MODULE_LINKER_FLAGS "")
if (MINGW)
	option(USE_MINGW_HARDENING_LINKER "Enable DEP (NX), ASLR and high-entropy ASLR linker flags (mingw-w64)" ON)
	if (USE_MINGW_HARDENING_LINKER)
		set(SECURITY_EXE_LINKER_FLAGS "-Wl,--dynamicbase -Wl,--nxcompat -Wl,--disable-auto-image-base")
		set(SECURITY_SHARED_LINKER_FLAGS "-Wl,--dynamicbase -Wl,--nxcompat -Wl,--disable-auto-image-base")
		set(SECURITY_MODULE_LINKER_FLAGS "-Wl,--dynamicbase -Wl,--nxcompat -Wl,--disable-auto-image-base")
		if ("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
			# Enable high-entropy ASLR for 64-bit
			# The image base has to be >4GB for HEASLR to be enabled.
			# The values used here are kind of arbitrary.
			set(SECURITY_EXE_LINKER_FLAGS "${SECURITY_EXE_LINKER_FLAGS} -Wl,--high-entropy-va -Wl,--image-base,0x140000000")
			set(SECURITY_SHARED_LINKER_FLAGS "${SECURITY_SHARED_LINKER_FLAGS} -Wl,--high-entropy-va -Wl,--image-base,0x180000000")
			set(SECURITY_MODULE_LINKER_FLAGS "${SECURITY_MODULE_LINKER_FLAGS} -Wl,--high-entropy-va -Wl,--image-base,0x180000000")
			set(GLOBAL_PROFILE ${GLOBAL_PROFILE}
				-DCMAKE_EXE_LINKER_FLAGS=${SECURITY_EXE_LINKER_FLAGS}
				-DCMAKE_SHARED_LINKER_FLAGS=${SECURITY_SHARED_LINKER_FLAGS}
				-DCMAKE_MODULE_LINKER_FLAGS=${SECURITY_MODULE_LINKER_FLAGS}
			)
91 92
		endif ()
	else ()
93
		message(WARNING "Linker Security Flags not enabled!")
94 95
	endif ()
endif ()
96

97 98
if (DEFINED EP_PREFIX)
	set_directory_properties(PROPERTIES EP_PREFIX ${EP_PREFIX})
99
endif ()
100

101
if (MSVC)
102
    message(FATAL_ERROR "Krita cannot be built with MSVC. See the README.md file!")
103 104
endif()

105
if (MINGW)
106
   set(PATCH_COMMAND myptch)
107 108
endif()

109
if (MSYS)
110
	set(PATCH_COMMAND patch)
111
    set(GLOBAL_PROFILE ${GLOBAL_PROFILE}
112
                           -DCMAKE_TOOLCHAIN_FILE=${MXE_TOOLCHAIN}
113 114
                           -DCMAKE_FIND_PREFIX_PATH=${CMAKE_PREFIX_PATH}
                           -DCMAKE_SYSTEM_INCLUDE_PATH=${CMAKE_PREFIX_PATH}/include
115
                           -DCMAKE_INCLUDE_PATH=${CMAKE_PREFIX_PATH}/include
116 117
                           -DCMAKE_LIBRARY_PATH=${CMAKE_PREFIX_PATH}/lib
                           -DZLIB_ROOT=${CMAKE_PREFIX_PATH}
118 119
    )
    set(GLOBAL_AUTOMAKE_PROFILE  --host=i686-pc-mingw32 )
120
endif()
121 122

if (APPLE)
123
    set(GLOBAL_PROFILE ${GLOBAL_PROFILE} -DCMAKE_MACOSX_RPATH=ON -DKDE_SKIP_RPATH_SETTINGS=ON -DBUILD_WITH_INSTALL_RPATH=ON -DAPPLE_SUPPRESS_X11_WARNING=ON)
124 125 126 127 128 129 130 131
    set(PATCH_COMMAND patch)
endif ()

if (UNIX AND NOT APPLE)
	set(LINUX true)
    set(PATCH_COMMAND patch)
endif ()

132 133 134 135 136 137
function(TestCompileLinkPythonLibs OUTPUT_VARNAME)
	include(CheckCXXSourceCompiles)
	set(CMAKE_REQUIRED_INCLUDES ${PYTHON_INCLUDE_PATH})
	set(CMAKE_REQUIRED_LIBRARIES ${PYTHON_LIBRARIES})
	if (MINGW)
		set(CMAKE_REQUIRED_DEFINITIONS -D_hypot=hypot)
138
	endif ()
139 140 141 142 143 144 145 146 147 148 149
	unset(${OUTPUT_VARNAME} CACHE)
	CHECK_CXX_SOURCE_COMPILES("
#include <Python.h>
int main(int argc, char *argv[]) {
	Py_InitializeEx(0);
}" ${OUTPUT_VARNAME})
endfunction()

if (MINGW)
	option(ENABLE_PYTHON_DEPS "Enable Python deps (sip, pyqt)" ON)
	if (ENABLE_PYTHON_DEPS)
150 151 152 153 154
        if (ENABLE_PYTHON_2)
            message(FATAL_ERROR "Python 2.7 is not supported on Windows at the moment.")
        else(ENABLE_PYTHON_2)
            find_package(PythonInterp 3.6 EXACT)
            find_package(PythonLibs 3.6 EXACT)
155
        endif()
156 157
		if (PYTHONLIBS_FOUND AND PYTHONINTERP_FOUND)
			message(STATUS "Python requirements met.")
158 159 160
			TestCompileLinkPythonLibs(CAN_USE_PYTHON_LIBS)
			if (NOT CAN_USE_PYTHON_LIBS)
				message(FATAL_ERROR "Compiling with Python library failed, please check whether the architecture is correct!")
161
			endif ()
162 163
		else (PYTHONLIBS_FOUND AND PYTHONINTERP_FOUND)
			message(FATAL_ERROR "Python requirements not met. To disable Python deps, set ENABLE_PYTHON_DEPS to OFF.")
164 165 166
		endif ()
	endif ()
endif ()
167

168
# this list must be dependency-ordered
169 170
if (ENABLE_PYTHON_DEPS OR NOT MINGW)
	add_subdirectory( ext_python )
171
endif ()
172 173 174
if (MINGW)
    add_subdirectory( ext_patch )
    add_subdirectory( ext_png2ico )
175
endif ()
176
add_subdirectory( ext_lzma )
177
add_subdirectory( ext_iconv )
178 179
add_subdirectory( ext_gettext )
add_subdirectory( ext_zlib )
180 181 182 183 184 185 186 187 188 189
add_subdirectory( ext_boost )
add_subdirectory( ext_jpeg )
add_subdirectory( ext_tiff )
add_subdirectory( ext_png )
add_subdirectory( ext_eigen3 )
add_subdirectory( ext_expat ) # for exiv2
add_subdirectory( ext_exiv2 )
add_subdirectory( ext_ilmbase )
add_subdirectory( ext_lcms2 )
add_subdirectory( ext_openexr )
190
add_subdirectory( ext_openssl )
191 192 193 194 195
add_subdirectory( ext_vc )
add_subdirectory( ext_gsl )
add_subdirectory( ext_fftw3 )
add_subdirectory( ext_ocio )
add_subdirectory( ext_fontconfig)
196
add_subdirectory( ext_freetype)
197
add_subdirectory( ext_qt )
198 199 200
add_subdirectory( ext_poppler )
add_subdirectory( ext_libraw )
add_subdirectory( ext_frameworks )
201 202 203
if (ENABLE_PYTHON_DEPS OR NOT MINGW)
	add_subdirectory( ext_sip )
	add_subdirectory( ext_pyqt )
204
endif ()
205

206
if (MINGW)
207
    add_subdirectory( ext_drmingw )
208
#    add_subdirectory( ext_ffmpeg )
209
endif ()
210 211 212

if (NOT APPLE)
	add_subdirectory( ext_gmic )
213
endif ()
214

215 216 217 218 219
if(UNIX)
    add_subdirectory( ext_pkgconfig )
    add_subdirectory( ext_heif )
endif()

220
add_subdirectory(ext_giflib)
221
add_subdirectory(ext_quazip)