CMakeLists.txt 4.45 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 75
    xptime.c
)

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
76 77
)

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

Deucе's avatar
Deucе committed
83
if(SDL2_INCLUDE_DIRS)
deuce's avatar
deuce committed
84 85 86 87 88 89
	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)
90 91 92
	endif()
endif()

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

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

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)
106
    target_compile_definitions(xpdev PRIVATE SOUNDCARD_H_IN=1)
deuce's avatar
deuce committed
107
elseif(HAS_SOUNDCARD_H)
108
    target_compile_definitions(xpdev PRIVATE SOUNDCARD_H_IN=2)
deuce's avatar
deuce committed
109
elseif(HAS_LINUX_SOUNDCARD_H)
110
    target_compile_definitions(xpdev PRIVATE SOUNDCARD_H_IN=3)
deuce's avatar
deuce committed
111 112 113 114
endif()

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

126
if(WIN32)
Deucе's avatar
Deucе committed
127 128
	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)
129
elseif(CMAKE_SYSTEM_NAME STREQUAL "Haiku")
130
	target_link_libraries(xpdev network m)
deuce's avatar
deuce committed
131
elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
132
	target_link_libraries(xpdev ossaudio m)
deuce's avatar
deuce committed
133
elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
134
	target_link_libraries(xpdev ossaudio m)
deuce's avatar
deuce committed
135
elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
136
	target_link_libraries(xpdev socket m)
137
else()
138
	target_link_libraries(xpdev m)
deuce's avatar
deuce committed
139
endif()
deuce's avatar
deuce committed
140
target_link_libraries(xpdev ${CMAKE_THREAD_LIBS_INIT})
deuce's avatar
deuce committed
141 142

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

CHECK_FUNCTION_EXISTS(random HAS_RANDOM_FUNC) 
if(HAS_RANDOM_FUNC)
151
	target_compile_definitions(xpdev PRIVATE HAS_RANDOM_FUNC)
deuce's avatar
deuce committed
152 153 154 155
endif()

CHECK_FUNCTION_EXISTS(srandomdev HAS_SRANDOMDEV_FUNC)
if(HAS_SRANDOMDEV_FUNC)
156 157 158
	target_compile_definitions(xpdev PRIVATE HAS_SRANDOMDEV_FUNC)
endif()

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

if(X11_FOUND)
Deucе's avatar
Deucе committed
165
	target_include_directories(xpdev PRIVATE ${X11_INCLUDE_DIR})
166 167
endif()

Deucе's avatar
Deucе committed
168 169 170
if (PKG_CONFIG_FOUND)
	pkg_check_modules(PORTAUDIO2 portaudio-2.0)
	if(PORTAUDIO2_FOUND)
171
		set(PORTAUDIO_FOUND TRUE)
Deucе's avatar
Deucе committed
172 173 174 175 176 177 178
		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()
179 180 181 182 183 184 185 186
	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
187
if(USE_ALSA_SOUND)
188
    target_compile_definitions(xpdev PRIVATE USE_ALSA_SOUND)
deuce's avatar
deuce committed
189
endif()