-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
64 lines (55 loc) · 1.74 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
cmake_minimum_required(VERSION 3.25)
project(libmobile-bgb VERSION 0.2.0)
include(CheckLibraryExists)
include(CheckLinkerFlag)
set(CMAKE_C_STANDARD 11)
option(WITH_SYSTEM_LIBMOBILE "force using a system-wide copy of libmobile" OFF)
option(WITH_BUNDLED_LIBMOBILE "force using a bundled copy of libmobile" OFF)
set(c_args)
set(c_defs)
set(deps)
# Default cflags
if(NOT MSVC)
list(APPEND c_args -Wall -Wextra)
endif()
# Enable -ffunction-sections -fdata-sections and -Wl,--gc-sections by default
check_linker_flag(C -Wl,--gc-sections HAVE_GC_SECTIONS)
if(HAVE_GC_SECTIONS)
add_compile_options(-ffunction-sections -fdata-sections)
add_link_options(-Wl,--gc-sections)
endif()
find_package(PkgConfig)
# Include libmobile library
if(NOT WITH_BUNDLED_LIBMOBILE AND PkgConfig_FOUND)
pkg_check_modules(libmobile IMPORTED_TARGET "libmobile >= 0.2.0")
endif()
if (WITH_SYSTEM_LIBMOBILE AND NOT libmobile_FOUND)
message(FATAL_ERROR "libmobile not found")
endif()
if(libmobile_FOUND)
list(APPEND deps PkgConfig::libmobile)
else()
add_subdirectory(subprojects/libmobile)
list(APPEND deps libmobile_static)
endif()
if(WIN32)
check_library_exists(ws2_32 exit "" HAVE_LIBWS2_32)
if(NOT HAVE_LIBWS2_32)
message(FATAL_ERROR "ws2_32 not found")
endif()
list(APPEND deps ws2_32)
list(APPEND c_defs UNICODE _UNICODE _WIN32_WINNT=0x0501)
list(APPEND c_defs _CRT_SECURE_NO_WARNINGS)
endif()
add_executable(mobile
source/bgblink.c
source/bgblink.h
source/main.c
source/socket.c
source/socket.h
source/socket_impl.c
source/socket_impl.h)
target_link_libraries(mobile PRIVATE ${deps})
target_compile_options(mobile PRIVATE ${c_args})
target_compile_definitions(mobile PRIVATE ${c_defs})
install(TARGETS mobile)