-
Notifications
You must be signed in to change notification settings - Fork 16
/
CMakeLists.txt
149 lines (128 loc) · 5.05 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
cmake_minimum_required(VERSION 3.13)
if (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message(FATAL_ERROR "In-source builds are not allowed. You should create separate directory for build files.")
endif()
set(VERSION "24.4")
set(PACKAGE "nzbget" CACHE INTERNAL "")
set(LIBS "" CACHE INTERNAL "")
set(INCLUDES "" CACHE INTERNAL "")
set(PACKAGE_BUGREPORT "https://github.com/nzbgetcom/nzbget/issues")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_CONFIGURATION_TYPES "Release" "Debug")
string(REGEX MATCH "^([0-9]+)\\.([0-9]+)" VERSION_MATCH ${VERSION})
set(VERSION_MAJOR ${CMAKE_MATCH_1})
set(VERSION_MINOR ${CMAKE_MATCH_2})
add_compile_definitions(HAVE_CONFIG_H=1)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "")
endif()
option(BUILD_ONLY_TESTS "Build only tests (for CI)")
project(
nzbget
VERSION ${VERSION}
DESCRIPTION "NZBGet is a binary downloader, which downloads files from Usenet"
LANGUAGES C CXX
)
if(APPLE)
# On macOS Cmake, when cross-compiling, sometimes CMAKE_SYSTEM_PROCESSOR wrongfully stays
# the same as CMAKE_HOST_SYSTEM_PROCESSOR regardless the target CPU.
# The manual call to set(CMAKE_SYSTEM_PROCESSOR) has to be set after the project() call.
# because project() might reset CMAKE_SYSTEM_PROCESSOR back to the value of CMAKE_HOST_SYSTEM_PROCESSOR.
# Check if CMAKE_SYSTEM_PROCESSOR is not equal to CMAKE_OSX_ARCHITECTURES
if(NOT CMAKE_OSX_ARCHITECTURES STREQUAL "")
if(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL CMAKE_OSX_ARCHITECTURES)
# Split CMAKE_OSX_ARCHITECTURES into a list
string(REPLACE ";" " " ARCH_LIST ${CMAKE_OSX_ARCHITECTURES})
separate_arguments(ARCH_LIST UNIX_COMMAND ${ARCH_LIST})
# Count the number of architectures
list(LENGTH ARCH_LIST ARCH_COUNT)
# Ensure that exactly one architecture is specified
if(NOT ARCH_COUNT EQUAL 1)
message(FATAL_ERROR "CMAKE_OSX_ARCHITECTURES must have exactly one value. Current value: ${CMAKE_OSX_ARCHITECTURES}")
endif()
set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_OSX_ARCHITECTURES})
message(STATUS "CMAKE_SYSTEM_PROCESSOR is manually set to ${CMAKE_SYSTEM_PROCESSOR}")
endif()
endif()
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang")
set(CMAKE_CXX_FLAGS "-O0 -pthread -g -DDEBUG -Weverything -Wno-c++98-compat" CACHE STRING "" FORCE)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "-O0 -pthread -g -DDEBUG -Wall -Wextra" CACHE STRING "" FORCE)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS "/Od /Zi /MTd /MP /W4 /EHs /DDEBUG /D_DEBUG /DWIN32 /wd4800 /wd4267" CACHE STRING "" FORCE)
set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} winmm.lib Dbghelp.lib libcpmtd.lib" CACHE STRING "" FORCE)
endif()
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang")
set(CMAKE_CXX_FLAGS "-O2 -g0 -pthread -DNDEBUG -Wno-c++98-compat" CACHE STRING "" FORCE)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "-O2 -g0 -pthread -DNDEBUG" CACHE STRING "" FORCE)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS "/O2 /MT /MP /EHs /DNDEBUG /DWIN32 /wd4800 /wd4267" CACHE STRING "" FORCE)
set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} winmm.lib" CACHE STRING "" FORCE)
endif()
endif()
set(CMAKE_C_FLAGS_DEBUG ${CMAKE_CXX_FLAGS} CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS_RELEASE ${CMAKE_CXX_FLAGS} CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS} CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS} CACHE STRING "" FORCE)
include_directories(${CMAKE_BINARY_DIR})
include_directories(${CMAKE_SOURCE_DIR})
include(daemon/sources.cmake)
if(NOT BUILD_ONLY_TESTS)
add_executable(${PACKAGE} ${SRC})
if(CMAKE_BUILD_TYPE STREQUAL "Release")
add_custom_command(
TARGET ${PACKAGE} POST_BUILD
DEPENDS ${PACKAGE}
COMMAND ${CMAKE_STRIP}
ARGS ${PACKAGE}
)
endif()
endif()
if(WIN32)
include(cmake/windows.cmake)
if(NOT BUILD_ONLY_TESTS)
target_sources(${PACKAGE} PRIVATE ${CMAKE_SOURCE_DIR}/windows/resources/nzbget.rc)
configure_file(
${CMAKE_SOURCE_DIR}/windows/resources/version.rc.in
${CMAKE_BINARY_DIR}/version.rc
)
configure_file(
${CMAKE_SOURCE_DIR}/windows/version.nsi.in
${CMAKE_BINARY_DIR}/version.nsi
@ONLY
)
configure_file(
${CMAKE_SOURCE_DIR}/windows/version-uninstall.nsi.in
${CMAKE_BINARY_DIR}/version-uninstall.nsi
@ONLY
)
target_sources(${PACKAGE} PRIVATE ${CMAKE_BINARY_DIR}/version.rc)
endif()
else()
include(cmake/posix.cmake)
if(NOT BUILD_ONLY_TESTS)
include(${CMAKE_SOURCE_DIR}/cmake/install.cmake)
endif()
endif()
include(lib/sources.cmake)
configure_file(
${CMAKE_SOURCE_DIR}/cmake/config.h.in
${CMAKE_BINARY_DIR}/config.h
)
if(NOT BUILD_ONLY_TESTS)
target_link_libraries(${PACKAGE} PRIVATE ${LIBS})
target_include_directories(${PACKAGE} PRIVATE ${INCLUDES})
endif()
if(ENABLE_TESTS OR BUILD_ONLY_TESTS)
include(CTest)
add_subdirectory(tests)
endif()