source: trunk/CMakeLists.txt@ 1284

Last change on this file since 1284 was 1284, checked in by dingo35, 10 years ago

Add Triple Dragon support, thanks to Single

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