-
-
Notifications
You must be signed in to change notification settings - Fork 145
/
CMakeLists.txt
128 lines (111 loc) ยท 4.31 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
cmake_minimum_required(VERSION 3.20)
project(Clipboard LANGUAGES CXX C VERSION 0.10.0)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED True)
if (UNIX AND NOT APPLE AND NOT HAIKU AND NOT ANDROID)
set(X11WL ON)
endif()
execute_process( # save the current branch to GIT_BRANCH
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process( # save the current commit hash to GIT_COMMIT_HASH
COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
add_definitions(-DGIT_COMMIT_HASH="${GIT_COMMIT_HASH}")
add_definitions(-DGIT_BRANCH="${GIT_BRANCH}")
add_definitions(-DCLIPBOARD_VERSION="${PROJECT_VERSION}")
if (MSVC)
add_compile_definitions(NOMINMAX) # Prevent min() or max() from being made into macros by windows.h
endif()
if (NOT CMAKE_INSTALL_LIBDIR)
set(CMAKE_INSTALL_LIBDIR "lib")
endif()
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
if (NOT NO_ALSA)
find_package(ALSA REQUIRED)
add_definitions(-DUSE_ALSA)
endif()
#find_path(LIBURING_INCLUDE_DIR liburing.h)
#if (LIBURING_INCLUDE_DIR)
# message(STATUS "Building the Clipboard Project with io_uring support")
# set(HAVE_LIBURING TRUE)
#else()
# message(FATAL_ERROR "Could not find liburing")
#endif()
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "Building the Clipboard Project in Debug mode")
if(NOT MSVC AND NOT APPLE)
#add_compile_options(-fsanitize=address)
#add_link_options(-fsanitize=address)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
endif()
if (NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
if (NOT NO_COVERAGE)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
add_compile_options(--coverage)
add_link_options(--coverage)
endif()
endif()
endif()
else()
if(NOT WIN32 AND NOT APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s")
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -s")
endif()
endif()
set(LIB_LOCATION ${CMAKE_BINARY_DIR})
set(BIN_LOCATION ${CMAKE_BINARY_DIR})
if ($ENV{CI}) # enable easy artifact access on CI by shipping everything to a unified folder
set(LIB_LOCATION ${CMAKE_BINARY_DIR}/output/lib)
set(BIN_LOCATION ${CMAKE_BINARY_DIR}/output/bin)
endif()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIB_LOCATION})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIB_LOCATION})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BIN_LOCATION})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${LIB_LOCATION})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${LIB_LOCATION})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${BIN_LOCATION})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${LIB_LOCATION})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${LIB_LOCATION})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${BIN_LOCATION})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_MINSIZEREL ${LIB_LOCATION})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL ${LIB_LOCATION})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${BIN_LOCATION})
function(enable_lto this_target)
include(CheckIPOSupported)
check_ipo_supported(RESULT lto_supported)
if(lto_supported AND NOT NO_LTO)
set_property(TARGET ${this_target} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
if(CMAKE_COMPILER_IS_GNUCXX)
list(APPEND CMAKE_CXX_COMPILE_OPTIONS_IPO "-flto=auto") # set the thread amount to what is available on the CPU
endif()
endif()
endfunction()
add_subdirectory(src/gui)
find_package(X11)
if(NOT NO_X11 AND X11_FOUND AND NOT APPLE) # X11 is technically available on macOS, but we don't want to use it
message(STATUS "Building the Clipboard Project with X11 support")
add_subdirectory(src/cbx11)
else()
message(STATUS "Building the Clipboard Project without X11 support")
endif()
find_package(PkgConfig)
pkg_check_modules(WAYLAND_CLIENT wayland-client wayland-protocols)
if(NOT NO_WAYLAND AND WAYLAND_CLIENT_FOUND)
message(STATUS "Building the Clipboard Project with Wayland support")
add_subdirectory(src/cbwayland)
else()
message(STATUS "Building the Clipboard Project without Wayland support")
endif()
add_subdirectory(src/cb)