CMakeLists.txt 4.62 KB
Newer Older
1 2
project (XPDev C)

Deucе's avatar
Deucе committed
3
cmake_minimum_required(VERSION 3.11)
deuce's avatar
deuce committed
4 5

INCLUDE (CheckIncludeFiles)
6
INCLUDE (CheckFunctionExists)
Deucе's avatar
Deucе committed
7 8 9 10 11 12
find_package(Threads)
find_package(X11)
if(NOT WIN32)
	find_package(PkgConfig)
	pkg_check_modules(SDL2 sdl2)
endif()
deuce's avatar
deuce committed
13

14
set(SOURCE
deuce's avatar
deuce committed
15 16 17 18 19 20 21 22 23 24 25 26
    conwrap.c
    dat_file.c
    datewrap.c
    dirwrap.c
    filewrap.c
    genwrap.c
    ini_file.c
    link_list.c
    msg_queue.c
    multisock.c
    netwrap.c
    semfile.c
Deucе's avatar
Deucе committed
27 28
    semwrap.c
    sockwrap.c
deuce's avatar
deuce committed
29 30 31
    str_list.c
    strwrap.c
    threadwrap.c
Deucе's avatar
Deucе committed
32
    unicode.c
deuce's avatar
deuce committed
33 34 35 36 37
    xp_dl.c
    xpbeep.c
    xpdatetime.c
    xpmap.c
    xpprintf.c
Deucе's avatar
Deucе committed
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
)

set(HEADER
	conwrap.h
	cp437defs.h
	dat_file.h
	datewrap.h
	dirwrap.h
	eventwrap.h
	filewrap.h
	gen_defs.h
	genwrap.h
	haproxy.h
	ini_file.h
	link_list.h
	msg_queue.h
	multisock.h
	netwrap.h
	petdefs.h
	semfile.h
	semwrap.h
	sockwrap.h
	str_list.h
	strwrap.h
	threadwrap.h
	unicode_defs.h
	unicode.h
	wrapdll.h
	xp_dl.h
	xp_syslog.h
	xpbeep.h
	xpdatetime.h
	xpendian.h
	xpevent.h
	xpmap.h
	xpprintf.h
	xpsem.h
deuce's avatar
deuce committed
75 76
)

77 78
if(NOT WIN32)
	list(APPEND SOURCE xpevent.c)
79
    list(APPEND SOURCE xpsem.c)
80 81
endif()

Deucе's avatar
Deucе committed
82
if(SDL2_INCLUDE_DIRS)
deuce's avatar
deuce committed
83 84 85 86 87 88
	list(APPEND SOURCE sdlfuncs.c)
	if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
		list(APPEND SOURCE SDLMain.m)
	endif()
	if(WIN32)
		list(APPEND SOURCE SDL_win32_main.c)
89 90 91
	endif()
endif()

Deucе's avatar
Deucе committed
92 93 94
add_library(xpdev OBJECT ${SOURCE})
target_include_directories(xpdev PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(xpdev PUBLIC ${XPDevPlus_BINARY_DIR})
95 96
target_link_libraries(xpdev ${CMAKE_DL_LIBS})

97
CHECK_INCLUDE_FILES(inttypes.h HAS_INTTYPES_H)
deuce's avatar
deuce committed
98
CHECK_INCLUDE_FILES(stdint.h HAS_STDINT_H)
Deucе's avatar
Deucе committed
99
set(LINK_LIST_THREADSAFE TRUE PARENT_SCOPE)
deuce's avatar
deuce committed
100 101 102 103 104

CHECK_INCLUDE_FILES(sys/soundcard.h HAS_SYS_SOUNDCARD_H) 
CHECK_INCLUDE_FILES(soundcard.h HAS_SOUNDCARD_H) 
CHECK_INCLUDE_FILES(linux/inttypes.h HAS_LINUX_SOUNDCARD_H) 
if(HAS_SYS_SOUNDCARD_H)
105
    target_compile_definitions(xpdev PRIVATE SOUNDCARD_H_IN=1)
deuce's avatar
deuce committed
106
elseif(HAS_SOUNDCARD_H)
107
    target_compile_definitions(xpdev PRIVATE SOUNDCARD_H_IN=2)
deuce's avatar
deuce committed
108
elseif(HAS_LINUX_SOUNDCARD_H)
109
    target_compile_definitions(xpdev PRIVATE SOUNDCARD_H_IN=3)
deuce's avatar
deuce committed
110 111 112 113
endif()

CHECK_INCLUDE_FILES(dev/speaker/speaker.h HAS_DEV_SPEAKER_SPEAKER_H)
if(HAS_DEV_SPEAKER_SPEAKER_H)
114
	target_compile_definitions(xpdev PRIVATE HAS_DEV_SPEAKER_SPEAKER_H)
deuce's avatar
deuce committed
115 116 117
endif()
CHECK_INCLUDE_FILES(dev/machine/speaker.h HAS_DEV_MACHINE_SPEAKER_H)
if(HAS_DEV_MACHINE_SPEAKER_H)
118
	target_compile_definitions(xpdev PRIVATE HAS_DEV_MACHINE_SPEAKER_H)
deuce's avatar
deuce committed
119 120 121
endif()
CHECK_INCLUDE_FILES(dev/speaker/spkr.h HAS_DEV_MACHINE_SPKR_H)
if(HAS_DEV_MACHINE_SPKR_H)
122
	target_compile_definitions(xpdev PRIVATE HAS_DEV_MACHINE_SPKR_H)
deuce's avatar
deuce committed
123 124
endif()

Deucе's avatar
Deucе committed
125
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
Deucе's avatar
Fix  
Deucе committed
126
	target_compile_definitions(xpdev PUBLIC POSIX_C_SOURCE=200809L _DEFAULT_SOURCE _BSD_SOURCE SPEED_MACROS_ONLY _GNU_SOURCE _FILE_OFFSET_BITS=64)
Deucе's avatar
Deucе committed
127 128
endif()

129
if(WIN32)
Deucе's avatar
Deucе committed
130 131
	target_compile_definitions(xpdev PUBLIC _WIN32 _WIN32_WINNT=0x0501 WINVER=0x0501 MSVCRT_VERSION=0x0501 _WIN32_IE=0x0500)
	target_link_libraries(xpdev iphlpapi ws2_32 winmm netapi32)
132
elseif(CMAKE_SYSTEM_NAME STREQUAL "Haiku")
133
	target_link_libraries(xpdev network m)
deuce's avatar
deuce committed
134
elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
135
	target_link_libraries(xpdev ossaudio m)
deuce's avatar
deuce committed
136
elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
137
	target_link_libraries(xpdev ossaudio m)
deuce's avatar
deuce committed
138
elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
139
	target_link_libraries(xpdev socket m)
140
else()
141
	target_link_libraries(xpdev m)
deuce's avatar
deuce committed
142
endif()
deuce's avatar
deuce committed
143
target_link_libraries(xpdev ${CMAKE_THREAD_LIBS_INIT})
deuce's avatar
deuce committed
144 145

if(EXISTS /dev/urandom)
146
	target_compile_definitions(xpdev PRIVATE HAS_DEV_URANDOM URANDOM_DEV="/dev/urandom")
deuce's avatar
deuce committed
147 148
endif()
if(EXISTS /dev/random)
149
	target_compile_definitions(xpdev PRIVATE HAS_DEV_RANDOM RANDOM_DEV="/dev/random")
deuce's avatar
deuce committed
150 151 152 153
endif()

CHECK_FUNCTION_EXISTS(random HAS_RANDOM_FUNC) 
if(HAS_RANDOM_FUNC)
154
	target_compile_definitions(xpdev PRIVATE HAS_RANDOM_FUNC)
deuce's avatar
deuce committed
155 156 157 158
endif()

CHECK_FUNCTION_EXISTS(srandomdev HAS_SRANDOMDEV_FUNC)
if(HAS_SRANDOMDEV_FUNC)
159 160 161
	target_compile_definitions(xpdev PRIVATE HAS_SRANDOMDEV_FUNC)
endif()

Deucе's avatar
Deucе committed
162 163 164
if(SDL2_INCLUDE_DIRS)
	target_include_directories(xpdev PUBLIC ${SDL2_INCLUDE_DIRS})
	set(WITH_SDL_AUDIO TRUE PARENT_SCOPE)
165 166 167
endif()

if(X11_FOUND)
Deucе's avatar
Deucе committed
168
	target_include_directories(xpdev PRIVATE ${X11_INCLUDE_DIR})
169 170
endif()

Deucе's avatar
Deucе committed
171 172 173
if (PKG_CONFIG_FOUND)
	pkg_check_modules(PORTAUDIO2 portaudio-2.0)
	if(PORTAUDIO2_FOUND)
174
		set(PORTAUDIO_FOUND TRUE)
Deucе's avatar
Deucе committed
175 176 177 178 179 180 181
		set(PORTAUDIO_LIBS PORTAUDIO2_LIBS)
		set(PORTAUDIO_CFLAGS PORTAUDIO2_CFLAGS)
	else()
		find_path(PORTAUDIO_INCLUDEDIR portaudio.h)
		if(PORTAUDIO_INCLUDEDIR)
			set(PORTAUDIO_FOUND TRUE)
		endif()
182 183 184 185 186 187 188 189
	endif()
endif()

if(PORTAUDIO_FOUND)
	target_include_directories(xpdev PRIVATE ${PORTAUDIO_INCLUDEDIR})
endif()

CHECK_INCLUDE_FILES(alsa/asoundlib.h USE_ALSA_SOUND)
deuce's avatar
deuce committed
190
if(USE_ALSA_SOUND)
191
    target_compile_definitions(xpdev PRIVATE USE_ALSA_SOUND)
deuce's avatar
deuce committed
192
endif()