source: branches/monitor-improvement/CMakeLists.txt@ 1180

Last change on this file since 1180 was 1180, checked in by alno, 12 years ago

WebIf:

  • Merging revisions 1177-1179 of trunk
File size: 13.3 KB
Line 
1project (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
9cmake_minimum_required (VERSION 2.4)
10if(COMMAND cmake_policy)
11 cmake_policy(SET CMP0005 OLD)
12 cmake_policy(SET CMP0003 NEW)
13endif(COMMAND cmake_policy)
14
15#----------------------- detect system ------------------------------
16
17if (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")
48else (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")
68endif (CMAKE_CROSSCOMPILING)
69
70#----------------------- some paths ------------------------------
71
72set (OPTIONAL_LINK_DIR "" CACHE STRING "Some optional link directories")
73set (OPTIONAL_INCLUDE_DIR "" CACHE STRING "Some optional include directories")
74
75include_directories (
76 ${CMAKE_CURRENT_SOURCE_DIR}/csctapi
77 ${CMAKE_CURRENT_SOURCE_DIR}/cscrypt
78 ${OPTIONAL_INCLUDE_DIR}
79 )
80link_directories (${OPTIONAL_LINK_DIR})
81
82#----------------------- global options ------------------------------
83
84if (OSCamOperatingSystem MATCHES "Linux")
85 add_definitions ("-DOS_LINUX")
86 set (DEFAULT_CS_CONFDIR "/usr/local/etc")
87elseif (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")
90elseif (OSCamOperatingSystem MATCHES "Tuxbox")
91 add_definitions ("-DOS_LINUX -DTUXBOX -DPPC")
92 set (DEFAULT_CS_CONFDIR "/var/tuxbox/config")
93elseif (OSCamOperatingSystem MATCHES "NeutrinoHD")
94 add_definitions ("-DOS_LINUX -DTUXBOX -DCOOL")
95 set (DEFAULT_CS_CONFDIR "/var/tuxbox/config")
96elseif (OSCamOperatingSystem MATCHES "SlugOS")
97 add_definitions ("-DOS_LINUX")
98 set (DEFAULT_CS_CONFDIR "/var/etc")
99elseif (OSCamOperatingSystem MATCHES "Fonera2")
100 add_definitions ("-DOS_LINUX -DMIPSEL -DUCLIBC")
101 set (DEFAULT_CS_CONFDIR "/var/etc")
102elseif (OSCamOperatingSystem MATCHES "WRT54G")
103 add_definitions ("-DOS_LINUX -DMIPSEL -DUCLIBC -DUSE_GPIO")
104 set (DEFAULT_CS_CONFDIR "/jffs/etc/config/oscam")
105elseif (OSCamOperatingSystem MATCHES "Amino")
106 add_definitions ("-DOS_LINUX")
107 set (DEFAULT_CS_CONFDIR "/usr/local/etc")
108elseif (OSCamOperatingSystem MATCHES "Windows/Cygwin")
109 add_definitions ("-DOS_CYGWIN32 -static")
110 set (DEFAULT_CS_CONFDIR ".")
111endif (OSCamOperatingSystem MATCHES "Linux")
112
113set (CS_CONFDIR ${DEFAULT_CS_CONFDIR} CACHE STRING "Default path for the config files")
114add_definitions ("-DCS_CONFDIR=\\\"${CS_CONFDIR}\\\"")
115
116set (CS_OS_CPU ${CMAKE_SYSTEM_PROCESSOR})
117set (CS_OSTYPE ${CS_OS_CPU}-${CS_OS_HW}-${CS_OS_SYS})
118
119add_definitions ("-DUSE_CMAKE")
120add_definitions ("-DCS_OSTYPE=\\\"${CS_OSTYPE}\\\"")
121add_definitions ("-DCS_OS_CPU=\\\"${CS_OS_CPU}\\\"")
122add_definitions ("-DCS_OS_HW=\\\"${CS_OS_HW}\\\"")
123add_definitions ("-DCS_OS_SYS=\\\"${CS_OS_SYS}\\\"")
124
125#----------------------- subdirectories ------------------------------
126
127include (CheckIncludeFile)
128check_include_file ("openssl/aes.h" HAVE_AES)
129if (HAVE_AES)
130 add_definitions ("-DHAVE_AES")
131endif (HAVE_AES)
132
133check_include_file ("openssl/sha.h" HAVE_SHA)
134if (HAVE_SHA)
135 add_definitions ("-DHAVE_SHA")
136endif (HAVE_SHA)
137
138check_include_file ("PCSC/wintypes.h" HAVE_PCSC)
139if (HAVE_PCSC)
140 add_definitions ("-DHAVE_PCSC")
141if (OSCamOperatingSystem MATCHES "Linux")
142 add_definitions ("-I/usr/include/PCSC")
143endif (OSCamOperatingSystem MATCHES "Linux")
144endif (HAVE_PCSC)
145
146#----------------------- subdirectories ------------------------------
147
148add_subdirectory (csctapi)
149add_subdirectory (cscrypt)
150
151#----------------------- file groups ------------------------------
152
153file (GLOB csmodules_srcs "module-*.c")
154file (GLOB csmodules_hdrs "module-*.h")
155file (GLOB csreaders_srcs "reader-*.c")
156file (GLOB csreaders_hdrs "reader-*.h")
157file (GLOB csoscam_srcs "oscam-*.c")
158file (GLOB csoscam_hdrs "oscam-*.h")
159file (GLOB exe_srcs "oscam.c")
160file (GLOB exe_hdrs "globals.h")
161file (GLOB all_srcs ${csmodules_srcs} ${csreaders_srcs} ${csoscam_srcs} ${exe_srcs})
162
163#----------------------- modules ------------------------------
164
165set (csmodules "csmodules")
166add_library (${csmodules} STATIC ${csmodules_srcs} ${csmodules_hdrs})
167
168#----------------------- readers ------------------------------
169
170set (csreaders "csreaders")
171add_library (${csreaders} STATIC ${csreaders_srcs} ${csreaders_hdrs})
172
173#----------------------- other oscam files ------------------------------
174
175set (csoscam "csoscam")
176add_library (${csoscam} STATIC ${csoscam_srcs} ${csoscam_hdrs})
177
178#----------------------- the executable ------------------------------
179
180set (exe_name "oscam")
181add_executable (${exe_name} ${exe_srcs} ${exe_hdrs})
182target_link_libraries (${exe_name} ${csoscam} ${csmodules} ${csreaders} csctapi cscrypt pthread)
183if (HAVE_AES)
184 target_link_libraries (${exe_name} crypto)
185endif (HAVE_AES)
186if (HAVE_PCSC)
187if (NOT OSCamOperatingSystem MATCHES "Mac OS X")
188 target_link_libraries (${exe_name} pcsclite)
189endif (NOT OSCamOperatingSystem MATCHES "Mac OS X")
190endif (HAVE_PCSC)
191
192add_dependencies (${exe_name} ${csoscam} ${csreaders} ${csmodules})
193
194#----------------------- specific options ------------------------------
195
196if (OSCamOperatingSystem MATCHES "Linux")
197elseif (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")
202elseif (OSCamOperatingSystem MATCHES "Tuxbox")
203 target_link_libraries ( ${exe_name} dl)
204elseif (OSCamOperatingSystem MATCHES "NeutrinoHD")
205elseif (OSCamOperatingSystem MATCHES "SlugOS")
206elseif (OSCamOperatingSystem MATCHES "Fonera2")
207elseif (OSCamOperatingSystem MATCHES "WRT54G")
208elseif (OSCamOperatingSystem MATCHES "Amino")
209elseif (OSCamOperatingSystem MATCHES "Windows/cygwin")
210elseif (OSCamOperatingSystem MATCHES "NeutrinoHD")
211 target_link_libraries ( ${exe_name} rt nxp )
212endif (OSCamOperatingSystem MATCHES "Linux")
213
214#----------------------- put svnversion in the build ------------------------------
215# at every target rebuild, we re-build the oscam.c compilation...
216
217# add the needed dependency
218add_dependencies (${exe_name} svnversion)
219add_dependencies (${csoscam} svnversion-log)
220
221# how to re-build the files which printout the version
222add_custom_target (
223 svnversion
224 ALL
225 touch ${CMAKE_CURRENT_SOURCE_DIR}/oscam.c
226)
227add_custom_target (
228 svnversion-log
229 ALL
230 touch ${CMAKE_CURRENT_SOURCE_DIR}/oscam-log.c
231)
232
233#if the svnversion program is absent, this will leave the SVN_REVISION string empty,
234#but won't stop CMake.
235execute_process (COMMAND "svnversion" "-n" "${CMAKE_CURRENT_SOURCE_DIR}" OUTPUT_VARIABLE OSCAM_SVN_REVISION)
236
237if (OSCAM_SVN_REVISION)
238 string (REGEX REPLACE "[0-9]+:" "" OSCAM_SVN_REVISION "${OSCAM_SVN_REVISION}")
239 string (REPLACE "M" "" OSCAM_SVN_REVISION "${OSCAM_SVN_REVISION}")
240 string (REPLACE "exported" "0" OSCAM_SVN_REVISION "${OSCAM_SVN_REVISION}")
241else (OSCAM_SVN_REVISION)
242 set (OSCAM_SVN_REVISION "0")
243endif (OSCAM_SVN_REVISION)
244
245# pass the version to the compilations as a define
246add_definitions ("-D'CS_SVN_VERSION=\"${OSCAM_SVN_REVISION}\"'")
247
248#----------------------- global compile and link options ------------------------------
249
250# some optimisations
251if (OSCamOperatingSystem MATCHES "Mac OS X")
252add_definitions ("-O2 -Winline -Wall -Wextra -finline-functions -fomit-frame-pointer -m32")
253else (OSCamOperatingSystem MATCHES "Mac OS X")
254add_definitions ("-O2 -Winline -Wall -Wextra -finline-functions -fomit-frame-pointer")
255endif (OSCamOperatingSystem MATCHES "Mac OS X")
256
257# we don't want the '-rdynamic' in the link command
258set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
259
260# we want to strip
261if (OSCamOperatingSystem MATCHES "Mac OS X")
262set (CMAKE_EXE_LINKER_FLAGS "-s -m32")
263else (OSCamOperatingSystem MATCHES "Mac OS X")
264set (CMAKE_EXE_LINKER_FLAGS "-s")
265endif (OSCamOperatingSystem MATCHES "Mac OS X")
266#----------------------- installation -----------------------------
267
268file (GLOB config_files "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/oscam.*")
269file (GLOB doc_files "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/txt/*.txt")
270file (GLOB man1_files "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/man/*.1")
271file (GLOB man5_files "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/man/*.5")
272file (GLOB example_files "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.ac"
273 "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.cert"
274 "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.conf"
275 "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.guess"
276 "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.ird"
277 "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.server"
278 "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.services"
279 "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.srvid"
280 "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.user")
281file (GLOB monitor_files "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/monitor/mpcs*.sh"
282 "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/monitor/mpcs*.tar")
283
284install (PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${exe_name}${CMAKE_EXECUTABLE_SUFFIX} DESTINATION bin COMPONENT bin)
285install (FILES ${config_files} DESTINATION etc COMPONENT config)
286install (FILES ${doc_files} DESTINATION share/doc/oscam COMPONENT doc)
287install (FILES ${man1_files} DESTINATION share/man/man1 COMPONENT doc)
288install (FILES ${man5_files} DESTINATION share/man/man5 COMPONENT doc)
289install (FILES ${example_files} DESTINATION share/doc/oscam/example COMPONENT doc)
290install (FILES ${monitor_files} DESTINATION share/doc/oscam/monitor COMPONENT doc)
291
292#----------------------- we can use CPack to build pacakges --------------------------
293
294# get version from source file
295execute_process (COMMAND grep CS_VERSION ${CMAKE_CURRENT_SOURCE_DIR}/globals.h
296 OUTPUT_VARIABLE CS_VERSION)
297string (REGEX REPLACE ".*\"\(.*\)\".*" "\\1" CS_VERSION ${CS_VERSION})
298string (REGEX REPLACE "\(.*\)\\..*\\..*" "\\1" CPACK_PACKAGE_VERSION_MAJOR ${CS_VERSION})
299string (REGEX REPLACE ".*\\.\(.*\)\\..*" "\\1" CPACK_PACKAGE_VERSION_MINOR ${CS_VERSION})
300string (REGEX REPLACE ".*\\..*\\.\(.*\)" "\\1" CPACK_PACKAGE_VERSION_PATCH ${CS_VERSION})
301set (CPACK_PACKAGE_VERSION
302 "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
303
304# compute my filename
305set (CPACK_PACKAGE_FILE_NAME
306 "${PROJECT_NAME}-${CPACK_PACKAGE_VERSION}-${CS_OSTYPE}")
307
308# wich archive we want to generate
309set (CPACK_GENERATOR "TGZ")
310
311# what to put in the archive
312set (CPACK_STRIP_FILES TRUE)
313set (CPACK_COMPONENTS_ALL bin)# config doc)
314
315# ok, we can now use CPack
316include (CPack)
317
318#----------------------- printout resume -----------------------------
319
320message (STATUS "")
321message (STATUS " operating system: ${OSCamOperatingSystem}")
322message (STATUS " system type: ${CS_OSTYPE}")
323message (STATUS " system: ${CS_OS_SYS}")
324message (STATUS " cpu: ${CS_OS_CPU}")
325message (STATUS " hw: ${CS_OS_HW}")
326if (HAVE_AES)
327 message (STATUS " use system aes functions")
328else (HAVE_AES)
329 message (STATUS " use built-in aes functions")
330endif (HAVE_AES)
331if (HAVE_SHA)
332 message (STATUS " use system sha functions")
333else (HAVE_SHA)
334 message (STATUS " use built-in sha functions")
335endif (HAVE_SHA)
336if (HAVE_PCSC)
337 message (STATUS " use system pcsc functions")
338endif (HAVE_PCSC)
339message (STATUS "")
Note: See TracBrowser for help on using the repository browser.