-
Notifications
You must be signed in to change notification settings - Fork 509
/
CMakeLists.txt
180 lines (150 loc) · 6.23 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# CMakeLists.txt file to build the SDKlib library.
#
# It can be used to build a standalone library or to be included via add_subdirectory.
#
# To include the project in your application use the following:
# add_subdirectory(path/to/sdk)
# target_link_libraries(<target> PRIVATE MEGA::SDKlib)
#
# To use it as a standalone library, once compiled and installed:
# find_package(SDKlib REQUIRED)
# target_link_libraries(<target> PRIVATE MEGA::SDKlib)
# If you prefer to use pkg-config, use the following instead:
# pkg_check_modules(SDKlib REQUIRED IMPORTED_TARGET SDKlib)
# target_link_libraries(<target> PRIVATE PkgConfig::SDKlib)
#
cmake_minimum_required(VERSION 3.18)
# Qt Creator configures VCPKG automatically. Disable it, we may want to use different tripplets, paths...
set(QT_CREATOR_SKIP_VCPKG_SETUP TRUE CACHE BOOL "")
# Main modules location
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake/modules)
set(VCPKG_ROOT "" CACHE PATH "If set, it will build and use the VCPKG packages defined in the manifest file")
# Set up CMAKE_SYSTEM_NAME for cross compiling
if (VCPKG_ROOT)
include(set_cmake_system_name)
set_cmake_system_name()
endif()
## Configurable options ##
include(sdklib_options)
# If PROJECT_NAME is not set before project() we are the main project.
if(NOT PROJECT_NAME)
message(STATUS "[SDKlib] is a top-level project. Install target is enabled by default.")
set(SDKLIB_STANDALONE 1)
if (CMAKE_SYSTEM_NAME STREQUAL "iOS")
message(STATUS "Examples and tests will not be enabled by default.")
option(ENABLE_SDKLIB_EXAMPLES "Example application is built if enabled" OFF)
option(ENABLE_SDKLIB_TESTS "Integration and unit tests are built if enabled" OFF)
else()
message(STATUS "Examples and tests will be enabled by default.")
option(ENABLE_SDKLIB_EXAMPLES "Example application is built if enabled" ON)
option(ENABLE_SDKLIB_TESTS "Integration and unit tests are built if enabled" ON)
endif()
if (WIN32)
option(ENABLE_SDKLIB_WERROR "Enable warnings as errors" ON)
else()
option(ENABLE_SDKLIB_WERROR "Enable warnings as errors when building in debug mode." OFF)
endif()
else()
message(STATUS "[SDKlib] is building under project [${PROJECT_NAME}] Install target, examples and tests will not be enabled by default.")
set(SDKLIB_STANDALONE 0)
option(ENABLE_SDKLIB_EXAMPLES "Example application is built if enabled" OFF)
option(ENABLE_SDKLIB_TESTS "Integration and unit tests are built if enabled" OFF)
option(ENABLE_SDKLIB_WERROR "Enable warnings as errors." OFF)
endif()
## General configuration
include(sdklib_variables)
if(NOT PROJECT_NAME)
if(VCPKG_ROOT)
# Include VCPKG management tools.
include(vcpkg_management)
process_vcpkg_libraries(${CMAKE_CURRENT_LIST_DIR}/cmake)
else()
# For packages with no pkg-config in the system.
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake/modules/packages)
message(STATUS "Using system dependencies")
endif()
endif()
# Get SDK library version to use it as the CMake project version.
include(load_sdk_version)
read_sdk_version(MEGA_SDK_VERSION ${CMAKE_CURRENT_LIST_DIR}/include/mega/version.h)
project(SDKlib
VERSION ${MEGA_SDK_VERSION}
DESCRIPTION "MEGA SDK Library"
)
# In-source build not allowed
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(FATAL_ERROR "In-source build is not allowed. Remove CMakeCache.txt and the CMakeFiles directory and set a new binary directory different than the source tree.")
endif()
message(STATUS "Generator: ${CMAKE_GENERATOR}")
if(CMAKE_GENERATOR_PLATFORM)
message(STATUS "Platform: ${CMAKE_GENERATOR_PLATFORM}")
endif()
if(APPLE)
if(CMAKE_OSX_ARCHITECTURES)
message(STATUS "Architectures: ${CMAKE_OSX_ARCHITECTURES}")
else()
message(STATUS "Architectures: -Not set- (It defaults to the host system architecture)")
endif()
message(STATUS "Minimum deployment version: ${CMAKE_OSX_DEPLOYMENT_TARGET}")
endif()
message(STATUS "Target System Processor: ${CMAKE_SYSTEM_PROCESSOR}")
message(STATUS "Host System Processor: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(IS_MULTI_CONFIG)
if(CMAKE_CONFIGURATION_TYPES)
message(STATUS "Generated with config types: ${CMAKE_CONFIGURATION_TYPES}")
else()
message(FATAL_ERROR "You must specify CMAKE_CONFIGURATION_TYPES")
endif()
else()
if(CMAKE_BUILD_TYPE)
message(STATUS "Build type set to: ${CMAKE_BUILD_TYPE}")
else()
message(FATAL_ERROR "You must specify CMAKE_BUILD_TYPE. For example: -DCMAKE_BUILD_TYPE=Debug")
endif()
endif()
if($ENV{CFLAGS})
message(STATUS "Environment CFLAGS: $ENV{CFLAGS}")
endif()
if($ENV{CXXFLAGS})
message(STATUS "Environment CXXFLAGS: $ENV{CXXFLAGS}")
endif()
if($ENV{LDFLAGS})
message(STATUS "Environment LDFLAGS: $ENV{LDFLAGS}")
endif()
if(USE_READLINE AND WIN32)
message(FATAL_ERROR "Readline is not available in Windows builds. Disable USE_READLINE to continue.")
endif()
if(ENABLE_ISOLATED_GFX AND NOT USE_FREEIMAGE)
message(FATAL_ERROR "USE_FREEIMAGE is required when ENABLE_ISOLATED_GFX is enabled.")
endif()
message(STATUS "Building SDKlib v${PROJECT_VERSION}")
include(GNUInstallDirs) # Values for installation directories. All platforms
include(CMakePackageConfigHelpers) # For the CMake package
include(target_sources_conditional) # To add files to the project without building them
include(target_platform_compile_options) # To add compile options depeding on the platform
include(sdklib_libraries) # Includes a macro to load the dependencies, both the VCPKG or the system ones.
# Load common and per platform configuration for the project
include(configuration)
## Start loading targets
include(sdklib_target)
# Load Qt bindings
if(ENABLE_QT_BINDINGS)
add_subdirectory(bindings/qt)
endif()
# Load Java bindings
if(ENABLE_JAVA_BINDINGS)
add_subdirectory(bindings/java)
endif()
if(ENABLE_ISOLATED_GFX)
add_subdirectory(tools/gfxworker)
endif()
## Load examples and tests
if(ENABLE_SDKLIB_EXAMPLES)
add_subdirectory(examples)
endif()
if(ENABLE_SDKLIB_TESTS)
add_subdirectory(tests)
endif()
## Load FUSE support.
include(src/fuse/CMakeLists.txt)