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

deuce's avatar
deuce committed
3
cmake_minimum_required(VERSION 2.8.11)
deuce's avatar
deuce committed
4 5

INCLUDE (CheckIncludeFiles)
6 7 8 9 10
INCLUDE (CheckFunctionExists)
INCLUDE (FindThreads)
INCLUDE (FindSDL)
INCLUDE (FindX11)
INCLUDE (FindPkgConfig)
deuce's avatar
deuce committed
11

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

37 38
if(NOT WIN32)
	list(APPEND SOURCE xpevent.c)
39
    list(APPEND SOURCE xpsem.c)
40 41
endif()

deuce's avatar
deuce committed
42 43 44 45 46 47 48
if(SDL_FOUND)
	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)
49 50 51 52 53
	endif()
endif()

add_library(xpdev SHARED ${SOURCE})

54 55
target_link_libraries(xpdev ${CMAKE_DL_LIBS})

56
CHECK_INCLUDE_FILES(inttypes.h HAS_INTTYPES_H)
deuce's avatar
deuce committed
57 58 59
if(HAS_INTTYPES_H)
    target_compile_definitions(xpdev PUBLIC HAS_INTTYPES_H)
endif()
deuce's avatar
deuce committed
60 61 62 63
CHECK_INCLUDE_FILES(stdint.h HAS_STDINT_H)
if(HAS_STDINT_H)
    target_compile_definitions(xpdev PUBLIC HAS_STDINT_H)
endif()
deuce's avatar
deuce committed
64
target_compile_definitions(xpdev PUBLIC LINK_LIST_THREADSAFE)
deuce's avatar
deuce committed
65 66 67 68 69

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)
70
    target_compile_definitions(xpdev PRIVATE SOUNDCARD_H_IN=1)
deuce's avatar
deuce committed
71
elseif(HAS_SOUNDCARD_H)
72
    target_compile_definitions(xpdev PRIVATE SOUNDCARD_H_IN=2)
deuce's avatar
deuce committed
73
elseif(HAS_LINUX_SOUNDCARD_H)
74
    target_compile_definitions(xpdev PRIVATE SOUNDCARD_H_IN=3)
deuce's avatar
deuce committed
75 76 77 78
endif()

CHECK_INCLUDE_FILES(dev/speaker/speaker.h HAS_DEV_SPEAKER_SPEAKER_H)
if(HAS_DEV_SPEAKER_SPEAKER_H)
79
	target_compile_definitions(xpdev PRIVATE HAS_DEV_SPEAKER_SPEAKER_H)
deuce's avatar
deuce committed
80 81 82
endif()
CHECK_INCLUDE_FILES(dev/machine/speaker.h HAS_DEV_MACHINE_SPEAKER_H)
if(HAS_DEV_MACHINE_SPEAKER_H)
83
	target_compile_definitions(xpdev PRIVATE HAS_DEV_MACHINE_SPEAKER_H)
deuce's avatar
deuce committed
84 85 86
endif()
CHECK_INCLUDE_FILES(dev/speaker/spkr.h HAS_DEV_MACHINE_SPKR_H)
if(HAS_DEV_MACHINE_SPKR_H)
87
	target_compile_definitions(xpdev PRIVATE HAS_DEV_MACHINE_SPKR_H)
deuce's avatar
deuce committed
88 89
endif()

90
target_compile_definitions(xpdev PRIVATE WRAPPER_EXPORTS)
91
target_compile_definitions(xpdev INTERFACE WRAPPER_IMPORTS)
92
if(WIN32)
deuce's avatar
deuce committed
93
	target_link_libraries(xpdev Iphlpapi Ws2_32 Winmm Netapi32)
94
elseif(CMAKE_SYSTEM_NAME STREQUAL "Haiku")
95
	target_link_libraries(xpdev network m)
deuce's avatar
deuce committed
96
elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
97
	target_link_libraries(xpdev ossaudio m)
deuce's avatar
deuce committed
98
elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
99
	target_link_libraries(xpdev ossaudio m)
deuce's avatar
deuce committed
100
elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
101
	target_link_libraries(xpdev socket m)
102
else()
103
	target_link_libraries(xpdev m)
deuce's avatar
deuce committed
104
endif()
deuce's avatar
deuce committed
105
target_link_libraries(xpdev ${CMAKE_THREAD_LIBS_INIT})
deuce's avatar
deuce committed
106 107

if(EXISTS /dev/urandom)
108
	target_compile_definitions(xpdev PRIVATE HAS_DEV_URANDOM URANDOM_DEV="/dev/urandom")
deuce's avatar
deuce committed
109 110
endif()
if(EXISTS /dev/random)
111
	target_compile_definitions(xpdev PRIVATE HAS_DEV_RANDOM RANDOM_DEV="/dev/random")
deuce's avatar
deuce committed
112 113 114 115
endif()

CHECK_FUNCTION_EXISTS(random HAS_RANDOM_FUNC) 
if(HAS_RANDOM_FUNC)
116
	target_compile_definitions(xpdev PRIVATE HAS_RANDOM_FUNC)
deuce's avatar
deuce committed
117 118 119 120
endif()

CHECK_FUNCTION_EXISTS(srandomdev HAS_SRANDOMDEV_FUNC)
if(HAS_SRANDOMDEV_FUNC)
121 122 123
	target_compile_definitions(xpdev PRIVATE HAS_SRANDOMDEV_FUNC)
endif()

deuce's avatar
deuce committed
124
if(SDL_FOUND)
deuce's avatar
deuce committed
125 126
	target_include_directories(xpdev PUBLIC ${SDL_INCLUDE_DIR})
	target_compile_definitions(xpdev PUBLIC WITH_SDL_AUDIO)
127 128 129 130 131 132 133 134 135 136 137 138
endif()

if(X11_FOUND)
	target_include_directories(xpdev PRIVATE X11_INCLUDE_DIR)
endif()

pkg_check_modules(PORTAUDIO2 portaudio-2.0)
if(PORTAUDIO2_FOUND)
	set(PORTAUDIO_FOUND TRUE)
	set(PORTAUDIO_LIBS PORTAUDIO2_LIBS)
	set(PORTAUDIO_CFLAGS PORTAUDIO2_CFLAGS)
else()
139
	find_path(PORTAUDIO_INCLUDEDIR portaudio.h)
140
	if(PORTAUDIO_INCLUDEDIR)
141
		set(PORTAUDIO_FOUND TRUE)
142 143 144 145 146 147 148 149
	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
150
if(USE_ALSA_SOUND)
151
    target_compile_definitions(xpdev PRIVATE USE_ALSA_SOUND)
deuce's avatar
deuce committed
152
endif()
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182

set(INSTALL_HEADERS
	conwrap.h
	dat_file.h
	datewrap.h
	dirwrap.h
	eventwrap.h
	filewrap.h
	gen_defs.h
	genwrap.h
	ini_file.h
	link_list.h
	msg_queue.h
	multisock.h
	netwrap.h
	semfile.h
	semwrap.h
	sockwrap.h
	str_list.h
	strwrap.h
	threadwrap.h
	wrapdll.h
	xp_dl.h
	xp_syslog.h
	xpbeep.h
	xpdatetime.h
	xpendian.h
	xpmap.h
	xpprintf.h
)
183 184
if(NOT WIN32)
	list(APPEND INSTALL_HEADERS xpevent.h)
185
	list(APPEND INSTALL_HEADERS xpsem.h)
186
endif()
187
target_include_directories(xpdev INTERFACE $<INSTALL_INTERFACE:include/xpdev>)
188

deuce's avatar
deuce committed
189 190
export(PACKAGE XPDev)

191
install(TARGETS xpdev DESTINATION lib EXPORT XPDevConfig)
192
install(FILES ${INSTALL_HEADERS} DESTINATION include/xpdev)
193
install(EXPORT XPDevConfig DESTINATION lib/cmake/XPDev)
194