1 | project (OSCam C)
|
---|
2 |
|
---|
3 | #----------------------- minimum version of cmake to use ------------
|
---|
4 |
|
---|
5 | # if you want to switch to 2.6 min, please look at the escaped definitions
|
---|
6 | # later in this file (the add_definitions in 2.6 don't need to be escaped),
|
---|
7 | # and remove the CMP0005 policy.
|
---|
8 | # the CMP0003 could also be removed for cmake 2.6
|
---|
9 | cmake_minimum_required (VERSION 2.4)
|
---|
10 | if(COMMAND cmake_policy)
|
---|
11 | cmake_policy(SET CMP0005 OLD)
|
---|
12 | cmake_policy(SET CMP0003 NEW)
|
---|
13 | endif(COMMAND cmake_policy)
|
---|
14 |
|
---|
15 | #----------------------- detect system ------------------------------
|
---|
16 |
|
---|
17 | if (CMAKE_CROSSCOMPILING)
|
---|
18 | if (OSCAM_SYSTEM_NAME MATCHES "Tuxbox")
|
---|
19 | set (OSCamOperatingSystem "Tuxbox")
|
---|
20 | set (CS_OS_HW "tuxbox")
|
---|
21 | set (CS_OS_SYS "linux")
|
---|
22 | elseif (OSCAM_SYSTEM_NAME MATCHES "Coolstream")
|
---|
23 | set (OSCamOperatingSystem "NeutrinoHD")
|
---|
24 | set (CS_OS_HW "coolstream")
|
---|
25 | set (CS_OS_SYS "linux")
|
---|
26 | elseif (OSCAM_SYSTEM_NAME MATCHES "NSLU2")
|
---|
27 | set (OSCamOperatingSystem "SlugOS")
|
---|
28 | set (CS_OS_HW "nslu2")
|
---|
29 | set (CS_OS_SYS "linux")
|
---|
30 | elseif (OSCAM_SYSTEM_NAME MATCHES "Fonera2")
|
---|
31 | set (OSCamOperatingSystem "Fonera2")
|
---|
32 | set (CS_OS_HW "fonera2")
|
---|
33 | set (CS_OS_SYS "linux")
|
---|
34 | elseif (OSCAM_SYSTEM_NAME MATCHES "WRT54G")
|
---|
35 | set (OSCamOperatingSystem "WRT54G")
|
---|
36 | set (CS_OS_HW "wrt54g")
|
---|
37 | set (CS_OS_SYS "linux")
|
---|
38 | elseif (OSCAM_SYSTEM_NAME MATCHES "Amino")
|
---|
39 | set (OSCamOperatingSystem "Amino")
|
---|
40 | set (CS_OS_HW "amino")
|
---|
41 | set (CS_OS_SYS "linux")
|
---|
42 | else (OSCAM_SYSTEM_NAME MATCHES "Tuxbox")
|
---|
43 | message (STATUS "Unknown cross system name: <${CMAKE_SYSTEM_NAME}>")
|
---|
44 | set (OSCamOperatingSystem "Unknown")
|
---|
45 | set (CS_OS_HW "unknown")
|
---|
46 | set (CS_OS_SYS "unknown")
|
---|
47 | endif (OSCAM_SYSTEM_NAME MATCHES "Tuxbox")
|
---|
48 | else (CMAKE_CROSSCOMPILING)
|
---|
49 | if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
---|
50 | set (OSCamOperatingSystem "Linux")
|
---|
51 | set (CS_OS_HW "pc")
|
---|
52 | set (CS_OS_SYS "linux")
|
---|
53 | elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
---|
54 | set (OSCamOperatingSystem "Mac OS X")
|
---|
55 | set (CS_OS_HW "mac")
|
---|
56 | set (CS_OS_SYS "macosx")
|
---|
57 | elseif (${CYGWIN})
|
---|
58 | set (OSCamOperatingSystem "Windows/Cygwin")
|
---|
59 | set (CS_OS_HW "pc")
|
---|
60 | set (CS_OS_SYS "cygwin")
|
---|
61 | set (CMAKE_SYSTEM_PROCESSOR "i386")
|
---|
62 | else (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
---|
63 | message (STATUS "Unknown system name: <${CMAKE_SYSTEM_NAME}>")
|
---|
64 | set (OSCamOperatingSystem "Unknown")
|
---|
65 | set (CS_OS_HW "unknown")
|
---|
66 | set (CS_OS_SYS "unknown")
|
---|
67 | endif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
---|
68 | endif (CMAKE_CROSSCOMPILING)
|
---|
69 |
|
---|
70 | #----------------------- some paths ------------------------------
|
---|
71 |
|
---|
72 | set (OPTIONAL_LINK_DIR "" CACHE STRING "Some optional link directories")
|
---|
73 | set (OPTIONAL_INCLUDE_DIR "" CACHE STRING "Some optional include directories")
|
---|
74 |
|
---|
75 | include_directories (
|
---|
76 | ${CMAKE_CURRENT_SOURCE_DIR}/csctapi
|
---|
77 | ${CMAKE_CURRENT_SOURCE_DIR}/cscrypt
|
---|
78 | ${OPTIONAL_INCLUDE_DIR}
|
---|
79 | )
|
---|
80 | link_directories (${OPTIONAL_LINK_DIR})
|
---|
81 |
|
---|
82 | #----------------------- global options ------------------------------
|
---|
83 |
|
---|
84 | if (OSCamOperatingSystem MATCHES "Linux")
|
---|
85 | add_definitions ("-DOS_LINUX")
|
---|
86 | set (DEFAULT_CS_CONFDIR "/usr/local/etc")
|
---|
87 | elseif (OSCamOperatingSystem MATCHES "Mac OS X")
|
---|
88 | add_definitions ("-DOS_MACOSX -DHAVE_PCSC -DNEED_DAEMON -DCS_NOSHM -DHAVE_PTHREAD_H -DUSE_PTHREAD")
|
---|
89 | set (DEFAULT_CS_CONFDIR "/usr/local/etc")
|
---|
90 | elseif (OSCamOperatingSystem MATCHES "Tuxbox")
|
---|
91 | add_definitions ("-DOS_LINUX -DTUXBOX -DPPC")
|
---|
92 | set (DEFAULT_CS_CONFDIR "/var/tuxbox/config")
|
---|
93 | elseif (OSCamOperatingSystem MATCHES "NeutrinoHD")
|
---|
94 | add_definitions ("-DOS_LINUX -DTUXBOX")
|
---|
95 | set (DEFAULT_CS_CONFDIR "/var/tuxbox/config")
|
---|
96 | elseif (OSCamOperatingSystem MATCHES "SlugOS")
|
---|
97 | add_definitions ("-DOS_LINUX")
|
---|
98 | set (DEFAULT_CS_CONFDIR "/var/etc")
|
---|
99 | elseif (OSCamOperatingSystem MATCHES "Fonera2")
|
---|
100 | add_definitions ("-DOS_LINUX -DMIPSEL -DUCLIBC")
|
---|
101 | set (DEFAULT_CS_CONFDIR "/var/etc")
|
---|
102 | elseif (OSCamOperatingSystem MATCHES "WRT54G")
|
---|
103 | add_definitions ("-DOS_LINUX -DMIPSEL -DUCLIBC -DUSE_GPIO")
|
---|
104 | set (DEFAULT_CS_CONFDIR "/jffs/etc/config/oscam")
|
---|
105 | elseif (OSCamOperatingSystem MATCHES "Amino")
|
---|
106 | add_definitions ("-DOS_LINUX")
|
---|
107 | set (DEFAULT_CS_CONFDIR "/usr/local/etc")
|
---|
108 | elseif (OSCamOperatingSystem MATCHES "Windows/Cygwin")
|
---|
109 | add_definitions ("-DOS_CYGWIN32 -static")
|
---|
110 | set (DEFAULT_CS_CONFDIR ".")
|
---|
111 | endif (OSCamOperatingSystem MATCHES "Linux")
|
---|
112 |
|
---|
113 | set (CS_CONFDIR ${DEFAULT_CS_CONFDIR} CACHE STRING "Default path for the config files")
|
---|
114 | add_definitions ("-DCS_CONFDIR=\\\"${CS_CONFDIR}\\\"")
|
---|
115 |
|
---|
116 | set (CS_OS_CPU ${CMAKE_SYSTEM_PROCESSOR})
|
---|
117 | set (CS_OSTYPE ${CS_OS_CPU}-${CS_OS_HW}-${CS_OS_SYS})
|
---|
118 |
|
---|
119 | add_definitions ("-DUSE_CMAKE")
|
---|
120 | add_definitions ("-DCS_OSTYPE=\\\"${CS_OSTYPE}\\\"")
|
---|
121 | add_definitions ("-DCS_OS_CPU=\\\"${CS_OS_CPU}\\\"")
|
---|
122 | add_definitions ("-DCS_OS_HW=\\\"${CS_OS_HW}\\\"")
|
---|
123 | add_definitions ("-DCS_OS_SYS=\\\"${CS_OS_SYS}\\\"")
|
---|
124 |
|
---|
125 | #----------------------- subdirectories ------------------------------
|
---|
126 |
|
---|
127 | include (CheckIncludeFile)
|
---|
128 | check_include_file ("openssl/aes.h" HAVE_AES)
|
---|
129 | if (HAVE_AES)
|
---|
130 | add_definitions ("-DHAVE_AES")
|
---|
131 | endif (HAVE_AES)
|
---|
132 |
|
---|
133 | check_include_file ("openssl/sha.h" HAVE_SHA)
|
---|
134 | if (HAVE_SHA)
|
---|
135 | add_definitions ("-DHAVE_SHA")
|
---|
136 | endif (HAVE_SHA)
|
---|
137 |
|
---|
138 | check_include_file ("PCSC/wintypes.h" HAVE_PCSC)
|
---|
139 | if (HAVE_PCSC)
|
---|
140 | add_definitions ("-DHAVE_PCSC")
|
---|
141 | if (OSCamOperatingSystem MATCHES "Linux")
|
---|
142 | add_definitions ("-I/usr/include/PCSC")
|
---|
143 | endif (OSCamOperatingSystem MATCHES "Linux")
|
---|
144 | endif (HAVE_PCSC)
|
---|
145 |
|
---|
146 | #----------------------- subdirectories ------------------------------
|
---|
147 |
|
---|
148 | add_subdirectory (csctapi)
|
---|
149 | add_subdirectory (cscrypt)
|
---|
150 |
|
---|
151 | #----------------------- file groups ------------------------------
|
---|
152 |
|
---|
153 | file (GLOB csmodules_srcs "module-*.c")
|
---|
154 | file (GLOB csmodules_hdrs "module-*.h")
|
---|
155 | file (GLOB csreaders_srcs "reader-*.c")
|
---|
156 | file (GLOB csreaders_hdrs "reader-*.h")
|
---|
157 | file (GLOB csoscam_srcs "oscam-*.c")
|
---|
158 | file (GLOB csoscam_hdrs "oscam-*.h")
|
---|
159 | file (GLOB exe_srcs "oscam.c")
|
---|
160 | file (GLOB exe_hdrs "globals.h")
|
---|
161 | file (GLOB all_srcs ${csmodules_srcs} ${csreaders_srcs} ${csoscam_srcs} ${exe_srcs})
|
---|
162 |
|
---|
163 | #----------------------- modules ------------------------------
|
---|
164 |
|
---|
165 | set (csmodules "csmodules")
|
---|
166 | add_library (${csmodules} STATIC ${csmodules_srcs} ${csmodules_hdrs})
|
---|
167 |
|
---|
168 | #----------------------- readers ------------------------------
|
---|
169 |
|
---|
170 | set (csreaders "csreaders")
|
---|
171 | add_library (${csreaders} STATIC ${csreaders_srcs} ${csreaders_hdrs})
|
---|
172 |
|
---|
173 | #----------------------- other oscam files ------------------------------
|
---|
174 |
|
---|
175 | set (csoscam "csoscam")
|
---|
176 | add_library (${csoscam} STATIC ${csoscam_srcs} ${csoscam_hdrs})
|
---|
177 |
|
---|
178 | #----------------------- the executable ------------------------------
|
---|
179 |
|
---|
180 | set (exe_name "oscam")
|
---|
181 | add_executable (${exe_name} ${exe_srcs} ${exe_hdrs})
|
---|
182 | target_link_libraries (${exe_name} ${csoscam} ${csmodules} ${csreaders} csctapi cscrypt pthread)
|
---|
183 | if (HAVE_AES)
|
---|
184 | target_link_libraries (${exe_name} crypto)
|
---|
185 | endif (HAVE_AES)
|
---|
186 | if (HAVE_PCSC)
|
---|
187 | if (NOT OSCamOperatingSystem MATCHES "Mac OS X")
|
---|
188 | target_link_libraries (${exe_name} pcsclite)
|
---|
189 | endif (NOT OSCamOperatingSystem MATCHES "Mac OS X")
|
---|
190 | endif (HAVE_PCSC)
|
---|
191 |
|
---|
192 | add_dependencies (${exe_name} ${csoscam} ${csreaders} ${csmodules})
|
---|
193 |
|
---|
194 | #----------------------- specific options ------------------------------
|
---|
195 |
|
---|
196 | if (OSCamOperatingSystem MATCHES "Linux")
|
---|
197 | elseif (OSCamOperatingSystem MATCHES "Mac OS X")
|
---|
198 | FIND_LIBRARY (PCSC_LIBRARY PCSC)
|
---|
199 | message (STATUS "OS X system PCSC : ${PCSC_LIBRARY}")
|
---|
200 | target_link_libraries ( ${exe_name} ${PCSC_LIBRARY})
|
---|
201 | set (HAVE_PCSC "1")
|
---|
202 | elseif (OSCamOperatingSystem MATCHES "Tuxbox")
|
---|
203 | target_link_libraries ( ${exe_name} dl)
|
---|
204 | elseif (OSCamOperatingSystem MATCHES "NeutrinoHD")
|
---|
205 | elseif (OSCamOperatingSystem MATCHES "SlugOS")
|
---|
206 | elseif (OSCamOperatingSystem MATCHES "Fonera2")
|
---|
207 | elseif (OSCamOperatingSystem MATCHES "WRT54G")
|
---|
208 | elseif (OSCamOperatingSystem MATCHES "Amino")
|
---|
209 | elseif (OSCamOperatingSystem MATCHES "Windows/cygwin")
|
---|
210 | endif (OSCamOperatingSystem MATCHES "Linux")
|
---|
211 |
|
---|
212 | #----------------------- put svnversion in the build ------------------------------
|
---|
213 | # at every target rebuild, we re-build the oscam.c compilation...
|
---|
214 |
|
---|
215 | # add the needed dependency
|
---|
216 | add_dependencies (${exe_name} svnversion)
|
---|
217 | add_dependencies (${csoscam} svnversion-log)
|
---|
218 |
|
---|
219 | # how to re-build the files which printout the version
|
---|
220 | add_custom_target (
|
---|
221 | svnversion
|
---|
222 | ALL
|
---|
223 | touch ${CMAKE_CURRENT_SOURCE_DIR}/oscam.c
|
---|
224 | )
|
---|
225 | add_custom_target (
|
---|
226 | svnversion-log
|
---|
227 | ALL
|
---|
228 | touch ${CMAKE_CURRENT_SOURCE_DIR}/oscam-log.c
|
---|
229 | )
|
---|
230 |
|
---|
231 | # pass the version to the compilations as a define
|
---|
232 | add_definitions ("-D'CS_SVN_VERSION=\"$(shell svnversion -n ${CMAKE_CURRENT_SOURCE_DIR} | sed 's/[MS]$$//')\"'")
|
---|
233 |
|
---|
234 | #----------------------- global compile and link options ------------------------------
|
---|
235 |
|
---|
236 | # some optimisations
|
---|
237 | add_definitions ("-O3 -Winline -Wall -Wno-implicit-function-declaration -Wno-parentheses -finline-functions -fomit-frame-pointer")
|
---|
238 |
|
---|
239 | # we don't want the '-rdynamic' in the link command
|
---|
240 | set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
|
---|
241 |
|
---|
242 | # we want to strip
|
---|
243 | set (CMAKE_EXE_LINKER_FLAGS "-s")
|
---|
244 |
|
---|
245 | #----------------------- installation -----------------------------
|
---|
246 |
|
---|
247 | file (GLOB config_files "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/oscam.*")
|
---|
248 | file (GLOB doc_files "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/txt/*.txt")
|
---|
249 | file (GLOB man1_files "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/man/*.1")
|
---|
250 | file (GLOB man5_files "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/man/*.5")
|
---|
251 | file (GLOB example_files "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.ac"
|
---|
252 | "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.cert"
|
---|
253 | "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.conf"
|
---|
254 | "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.guess"
|
---|
255 | "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.ird"
|
---|
256 | "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.server"
|
---|
257 | "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.services"
|
---|
258 | "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.srvid"
|
---|
259 | "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.user")
|
---|
260 | file (GLOB monitor_files "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/monitor/mpcs*.sh"
|
---|
261 | "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/monitor/mpcs*.tar")
|
---|
262 |
|
---|
263 | install (PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${exe_name}${CMAKE_EXECUTABLE_SUFFIX} DESTINATION bin COMPONENT bin)
|
---|
264 | install (FILES ${config_files} DESTINATION etc COMPONENT config)
|
---|
265 | install (FILES ${doc_files} DESTINATION share/doc/oscam COMPONENT doc)
|
---|
266 | install (FILES ${man1_files} DESTINATION share/man/man1 COMPONENT doc)
|
---|
267 | install (FILES ${man5_files} DESTINATION share/man/man5 COMPONENT doc)
|
---|
268 | install (FILES ${example_files} DESTINATION share/doc/oscam/example COMPONENT doc)
|
---|
269 | install (FILES ${monitor_files} DESTINATION share/doc/oscam/monitor COMPONENT doc)
|
---|
270 |
|
---|
271 | #----------------------- we can use CPack to build pacakges --------------------------
|
---|
272 |
|
---|
273 | # get version from source file
|
---|
274 | execute_process (COMMAND grep CS_VERSION ${CMAKE_CURRENT_SOURCE_DIR}/globals.h
|
---|
275 | OUTPUT_VARIABLE CS_VERSION)
|
---|
276 | string (REGEX REPLACE ".*\"\(.*\)\".*" "\\1" CS_VERSION ${CS_VERSION})
|
---|
277 | string (REGEX REPLACE "\(.*\)\\..*\\..*" "\\1" CPACK_PACKAGE_VERSION_MAJOR ${CS_VERSION})
|
---|
278 | string (REGEX REPLACE ".*\\.\(.*\)\\..*" "\\1" CPACK_PACKAGE_VERSION_MINOR ${CS_VERSION})
|
---|
279 | string (REGEX REPLACE ".*\\..*\\.\(.*\)" "\\1" CPACK_PACKAGE_VERSION_PATCH ${CS_VERSION})
|
---|
280 | set (CPACK_PACKAGE_VERSION
|
---|
281 | "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
|
---|
282 |
|
---|
283 | # compute my filename
|
---|
284 | set (CPACK_PACKAGE_FILE_NAME
|
---|
285 | "${PROJECT_NAME}-${CPACK_PACKAGE_VERSION}-${CS_OSTYPE}")
|
---|
286 |
|
---|
287 | # wich archive we want to generate
|
---|
288 | set (CPACK_GENERATOR "TGZ")
|
---|
289 |
|
---|
290 | # what to put in the archive
|
---|
291 | set (CPACK_STRIP_FILES TRUE)
|
---|
292 | set (CPACK_COMPONENTS_ALL bin)# config doc)
|
---|
293 |
|
---|
294 | # ok, we can now use CPack
|
---|
295 | include (CPack)
|
---|
296 |
|
---|
297 | #----------------------- printout resume -----------------------------
|
---|
298 |
|
---|
299 | message (STATUS "")
|
---|
300 | message (STATUS " operating system: ${OSCamOperatingSystem}")
|
---|
301 | message (STATUS " system type: ${CS_OSTYPE}")
|
---|
302 | message (STATUS " system: ${CS_OS_SYS}")
|
---|
303 | message (STATUS " cpu: ${CS_OS_CPU}")
|
---|
304 | message (STATUS " hw: ${CS_OS_HW}")
|
---|
305 | if (HAVE_AES)
|
---|
306 | message (STATUS " use system aes functions")
|
---|
307 | else (HAVE_AES)
|
---|
308 | message (STATUS " use built-in aes functions")
|
---|
309 | endif (HAVE_AES)
|
---|
310 | if (HAVE_SHA)
|
---|
311 | message (STATUS " use system sha functions")
|
---|
312 | else (HAVE_SHA)
|
---|
313 | message (STATUS " use built-in sha functions")
|
---|
314 | endif (HAVE_SHA)
|
---|
315 | if (HAVE_PCSC)
|
---|
316 | message (STATUS " use system pcsc functions")
|
---|
317 | endif (HAVE_PCSC)
|
---|
318 | message (STATUS "")
|
---|