source: trunk/CMakeLists.txt @ 5375

Last change on this file since 5375 was 4843, checked in by Deas, 9 years ago

commit change suggested by Madmaxx in #1656

File size: 27.9 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 "WRT350NV2")
35        set (OSCamOperatingSystem "OpenWRT")
36        set (CS_OS_HW "wrt350nv2")
37        set (CS_OS_SYS "linux")
38    elseif (OSCAM_SYSTEM_NAME MATCHES "Dockstar")
39        set (OSCamOperatingSystem "OpenWRT")
40        set (CS_OS_HW "dockstar")
41        set (CS_OS_SYS "linux")
42    elseif (OSCAM_SYSTEM_NAME MATCHES "Fonera2")
43        set (OSCamOperatingSystem "Fonera2")
44        set (CS_OS_HW "fonera2")
45        set (CS_OS_SYS "linux")
46    elseif (OSCAM_SYSTEM_NAME MATCHES "DIR-825")
47        set (OSCamOperatingSystem "DIR-825")
48        set (CS_OS_HW "dir825")
49        set (CS_OS_SYS "linux")
50    elseif (OSCAM_SYSTEM_NAME MATCHES "AZBox")
51        set (OSCamOperatingSystem "AZBox")
52        set (CS_OS_HW "azbox")
53        set (CS_OS_SYS "linux")
54    elseif (OSCAM_SYSTEM_NAME MATCHES "agv2+w")
55        set (OSCamOperatingSystem "agv2+w")
56        set (CS_OS_HW "agv2+w")
57        set (CS_OS_SYS "linux")
58    elseif (OSCAM_SYSTEM_NAME MATCHES "WRT54G")
59        set (OSCamOperatingSystem "WRT54G")
60        set (CS_OS_HW "wrt54g")
61        set (CS_OS_SYS "linux")
62    elseif (OSCAM_SYSTEM_NAME MATCHES "Amino")
63        set (OSCamOperatingSystem "Amino")
64        set (CS_OS_HW "amino")
65        set (CS_OS_SYS "linux")
66    elseif (OSCAM_SYSTEM_NAME MATCHES "QboxHD")
67        set (OSCamOperatingSystem "QboxHD")
68        set (CS_OS_HW "qboxhd")
69        set (CS_OS_SYS "linux")
70    elseif (OSCAM_SYSTEM_NAME MATCHES "Padre")
71        set (OSCamOperatingSystem "Padre")
72        set (CS_OS_HW "sparc")
73        set (CS_OS_SYS "linux")
74    elseif (OSCAM_SYSTEM_NAME MATCHES "FriendlyARM")
75        set (OSCamOperatingSystem "FriendlyARM")
76        set (CS_OS_HW "friendlyarm")
77        set (CS_OS_SYS "linux")
78    else (OSCAM_SYSTEM_NAME MATCHES "Tuxbox")
79        message (STATUS "Unknown cross system name: <${CMAKE_SYSTEM_NAME}>")
80        set (OSCamOperatingSystem "Unknown")
81        set (CS_OS_HW "unknown")
82        set (CS_OS_SYS "unknown")
83    endif (OSCAM_SYSTEM_NAME MATCHES "Tuxbox")
84else (CMAKE_CROSSCOMPILING)
85    if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
86        set (OSCamOperatingSystem "Linux")
87        set (CS_OS_HW "pc")
88        set (CS_OS_SYS "linux")
89    elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
90        set (OSCamOperatingSystem "FreeBSD")
91        set (CS_OS_HW "pc")
92        set (CS_OS_SYS "freebsd")
93    elseif (OSCamOperatingSystem MATCHES "Padre")
94        add_definitions ("-DOS_LINUX -DPADRE -DSPARC")
95        set (DEFAULT_CS_CONFDIR "/etc/oscam")
96    elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
97        set (OSCamOperatingSystem "Mac OS X")
98        set (CS_OS_HW "mac")
99        set (CS_OS_SYS "macosx")
100        SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32" )
101        SET( CMAKE_CFLAGS "${CMAKE_CFLAGS} -m32" )
102    elseif (${CYGWIN})
103        set (OSCamOperatingSystem "Windows/Cygwin")
104        set (CS_OS_HW "pc")
105        set (CS_OS_SYS "cygwin")
106        set (CMAKE_SYSTEM_PROCESSOR "i386")
107    else (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
108        message (STATUS "Unknown system name: <${CMAKE_SYSTEM_NAME}>")
109        set (OSCamOperatingSystem "Unknown")
110        set (CS_OS_HW "unknown")
111        set (CS_OS_SYS "unknown")
112    endif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
113endif (CMAKE_CROSSCOMPILING)
114
115#----------------------- some paths ------------------------------
116
117set (OPTIONAL_LINK_DIR "" CACHE STRING "Some optional link directories")
118set (OPTIONAL_INCLUDE_DIR "" CACHE STRING "Some optional include directories")
119
120if (OSCamOperatingSystem MATCHES "Windows/Cygwin")
121include_directories (
122    ${CMAKE_CURRENT_SOURCE_DIR}/csctapi
123    ${CMAKE_CURRENT_SOURCE_DIR}/cscrypt
124    ${CMAKE_CURRENT_SOURCE_DIR}/algo
125    ${CMAKE_CURRENT_SOURCE_DIR}/cygwin
126    /usr/include/w32api
127    ${OPTIONAL_INCLUDE_DIR}
128    )
129else (OSCamOperatingSystem MATCHES "Windows/Cygwin")
130include_directories (
131    ${CMAKE_CURRENT_SOURCE_DIR}/csctapi
132    ${CMAKE_CURRENT_SOURCE_DIR}/cscrypt
133    ${CMAKE_CURRENT_SOURCE_DIR}/algo
134    ${OPTIONAL_INCLUDE_DIR}
135    )
136endif (OSCamOperatingSystem MATCHES "Windows/Cygwin")
137
138if(OSCamOperatingSystem MATCHES "Windows/Cygwin")
139link_directories (
140    /usr/lib
141    /usr/lib/w32api
142    /cygdrive/c/WINDOWS/system32/
143    ${OPTIONAL_LINK_DIR}
144    )
145else (OSCamOperatingSystem MATCHES "Windows/Cygwin")
146link_directories (
147    ${OPTIONAL_LINK_DIR}
148    )
149endif (OSCamOperatingSystem MATCHES "Windows/Cygwin")
150
151#----------------------- global options ------------------------------
152
153if (OSCamOperatingSystem MATCHES "Linux")
154    add_definitions ("-DOS_LINUX")
155    set (DEFAULT_CS_CONFDIR "/usr/local/etc")
156elseif (OSCamOperatingSystem MATCHES "Mac OS X")
157    add_definitions ("-DOS_MACOSX -DHAVE_PCSC -DNEED_DAEMON")
158    set (DEFAULT_CS_CONFDIR "/usr/local/etc")
159elseif (OSCamOperatingSystem MATCHES "Tuxbox")
160    set (DEFAULT_CS_CONFDIR "/var/tuxbox/config")
161    if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "mips")
162        add_definitions ("-DOS_LINUX -DTUXBOX -DMIPSEL")
163    else (${CMAKE_SYSTEM_PROCESSOR} MATCHES "mips")
164        add_definitions ("-DOS_LINUX -DTUXBOX -DPPC")
165    endif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "mips")
166elseif (OSCamOperatingSystem MATCHES "TripleDragon")
167    add_definitions ("-DOS_LINUX -DTRIPLEDRAGON -DSTB04SCI -DTUXBOX -DPPC")
168    set (DEFAULT_CS_CONFDIR "/var/tuxbox/config")
169elseif (OSCamOperatingSystem MATCHES "NeutrinoHD")
170    add_definitions ("-DOS_LINUX -DTUXBOX -DCOOL")
171    set (DEFAULT_CS_CONFDIR "/var/tuxbox/config")
172elseif (OSCamOperatingSystem MATCHES "SlugOS")
173    add_definitions ("-DOS_LINUX -DARM")
174    set (DEFAULT_CS_CONFDIR "/var/etc")
175elseif (OSCamOperatingSystem MATCHES "OpenWRT")
176    if (CS_OS_HW MATCHES "wrt350nv2")
177        add_definitions ("-DOS_LINUX -DARM -DWRT350NV2")
178        set (DEFAULT_CS_CONFDIR "/etc/oscam")
179    elseif (CS_OS_HW MATCHES "dockstar")
180        add_definitions ("-DOS_LINUX -DARM -DDOCKSTAR")
181        set (DEFAULT_CS_CONFDIR "/usr/oscam")
182    else (CS_OS_HW MATCHES "wrt350nv2")
183        add_definitions ("-DOS_LINUX -DARM")
184        set (DEFAULT_CS_CONFDIR "/usr/oscam")
185    endif (CS_OS_HW MATCHES "wrt350nv2")
186elseif (OSCamOperatingSystem MATCHES "Fonera2")
187    add_definitions ("-DOS_LINUX -DMIPSEL -DUCLIBC")
188    set (DEFAULT_CS_CONFDIR "/var/etc")
189elseif (OSCamOperatingSystem MATCHES "DIR-825")
190    add_definitions ("-DOS_LINUX -DMIPSEL -DUCLIBC")
191    set (DEFAULT_CS_CONFDIR "/var/etc")
192elseif (OSCamOperatingSystem MATCHES "AZBox")
193    add_definitions ("-DOS_LINUX -DMIPSEL -DAZBOX")
194    set (DEFAULT_CS_CONFDIR "/PLUGINS/OpenXCAS/oscamCAS")
195elseif (OSCamOperatingSystem MATCHES "agv2+w")
196    add_definitions ("-DOS_LINUX -DUCLIBC")
197    set (DEFAULT_CS_CONFDIR "/etc")
198elseif (OSCamOperatingSystem MATCHES "WRT54G")
199    add_definitions ("-DOS_LINUX -DMIPSEL -DUCLIBC -DUSE_GPIO")
200    set (DEFAULT_CS_CONFDIR "/jffs/etc/config/oscam")
201elseif (OSCamOperatingSystem MATCHES "Amino")
202    add_definitions ("-DOS_LINUX -DSH4 -DTUXBOX")
203    set (DEFAULT_CS_CONFDIR "/usr/local/etc")
204elseif (OSCamOperatingSystem MATCHES "QboxHD")
205    add_definitions ("-DOS_LINUX -DSH4 -DQBOXHD -DTUXBOX")
206    set (DEFAULT_CS_CONFDIR "/var/tuxbox/config")
207elseif (OSCamOperatingSystem MATCHES "Windows/Cygwin")
208    add_definitions ("-DOS_CYGWIN32 -static -DHAVE_PCSC")
209    set (DEFAULT_CS_CONFDIR ".")
210elseif (OSCamOperatingSystem MATCHES "FreeBSD")
211    add_definitions ("-DOS_FREEBSD")
212    set (DEFAULT_CS_CONFDIR ".")
213elseif (OSCamOperatingSystem MATCHES "FriendlyARM")
214    add_definitions ("-DOS_LINUX -DARM")
215    set (DEFAULT_CS_CONFDIR ".")
216endif (OSCamOperatingSystem MATCHES "Linux")
217
218set (CS_CONFDIR ${DEFAULT_CS_CONFDIR} CACHE STRING "Default path for the config files")
219add_definitions ("-DCS_CONFDIR=\\\"${CS_CONFDIR}\\\"")
220
221set (CS_OS_CPU ${CMAKE_SYSTEM_PROCESSOR})
222set (CS_OSTYPE ${CS_OS_CPU}-${CS_OS_HW}-${CS_OS_SYS})
223
224add_definitions ("-DUSE_CMAKE")
225add_definitions ("-DCS_OSTYPE=\\\"${CS_OSTYPE}\\\"")
226add_definitions ("-DCS_OS_CPU=\\\"${CS_OS_CPU}\\\"")
227add_definitions ("-DCS_OS_HW=\\\"${CS_OS_HW}\\\"")
228add_definitions ("-DCS_OS_SYS=\\\"${CS_OS_SYS}\\\"")
229
230# Manage oscam-config.h based on command line parameters
231# Manipulate config file based on given parameters and read unset parameters
232
233# Available options
234set(addons WEBIF HAVE_DVBAPI IRDETO_GUESSING CS_ANTICASC WITH_DEBUG CS_WITH_DOUBLECHECK CS_LED QBOXHD_LED CS_LOGHISTORY WITH_SSL)
235set(protocols MODULE_CAMD33 MODULE_CAMD35 MODULE_CAMD35_TCP MODULE_NEWCAMD MODULE_CCCAM MODULE_RADEGAST MODULE_SERIAL MODULE_MONITOR MODULE_CONSTCW)
236set(readers WITH_CARDREADER READER_NAGRA READER_IRDETO READER_CONAX READER_CRYPTOWORKS READER_SECA READER_VIACCESS READER_VIDEOGUARD READER_DRE READER_TONGFANG)
237
238MACRO(GENERATE_OSCAM_CONFIG fullpath)
239    file(READ ${fullpath} config)
240    foreach(option ${addons} ${protocols} ${readers})
241        if(DEFINED ${option})
242            # Note: cmake does not read the file as individual lines but as a long
243            #       string, hence we use \n instead of ^ to determine where a line begins
244
245            if(${option})
246                string(REGEX REPLACE "\n//#define ${option}" "\n#define ${option}" config ${config})
247            else(${option})
248                string(REGEX REPLACE "\n#define ${option}" "\n//#define ${option}" config ${config})
249            endif(${option})
250        else(DEFINED ${option})
251            # read value from current oscam-config.h
252
253            if(${config} MATCHES "\n#define ${option}")
254                SET(${option} TRUE)
255            endif(${config} MATCHES "\n#define ${option}")
256        endif(DEFINED ${option})
257    endforeach(option)
258    file(WRITE ${fullpath} ${config})
259ENDMACRO(GENERATE_OSCAM_CONFIG fullpath)
260
261#----------------------- subdirectories ------------------------------
262
263include (CheckIncludeFile)
264GENERATE_OSCAM_CONFIG("${CMAKE_CURRENT_SOURCE_DIR}/oscam-config.h")
265
266check_include_file ("pthread.h" HAVE_PTHREAD)
267if (HAVE_PTHREAD)
268    message(STATUS "  pthread found. Adding pthread support ")
269    add_definitions ("-DHAVE_PTHREAD_H")
270elseif (HAVE_PTHREAD)
271    message(STATUS "  no pthread found. No smartreader ")
272endif (HAVE_PTHREAD)
273
274check_include_file ("openssl/aes.h" HAVE_LIBCRYPTO)
275if (HAVE_LIBCRYPTO)
276    add_definitions ("-DWITH_LIBCRYPTO")
277endif (HAVE_LIBCRYPTO)
278
279find_package(OpenSSL QUIET)
280if (OPENSSL_FOUND)
281    include_directories(${OPENSSL_INCLUDE_DIR})
282    message(STATUS "  openssl found.")
283else (OPENSSL_FOUND)
284    message(STATUS "  openssl not found.")
285    if (WITH_SSL)
286        message(FATAL "  ssl support requested but not found! ")
287    endif (WITH_SSL)
288endif (OPENSSL_FOUND)
289
290if (NOT OSCamOperatingSystem MATCHES "Mac OS X")
291   if (LIBRTDIR)
292        check_include_file ("${LIBRTDIR}/include/time.h" HAVE_LIBRT_STATIC)
293        if (HAVE_LIBRT_STATIC)
294            if (EXISTS ${LIBRTDIR}/lib/librt.a)
295                message(STATUS "  static librt found : ${LIBRTDIR}/lib/librt.a (needed by libusb).")
296                add_definitions ("-I${LIBRTDIR}/include/")
297                add_library(imp_librt STATIC IMPORTED)
298                set_property(TARGET imp_librt PROPERTY IMPORTED_LOCATION ${LIBRTDIR}/lib/librt.a)
299            else (EXISTS ${LIBRTDIR}/lib/librt.a)
300                message(STATUS " ${LIBRTDIR}/lib/librt.a not found (needed by libusb). No smartreader support)")
301                set (HAVE_LIBRT_STATIC False)
302            endif (EXISTS ${LIBRTDIR}/lib/librt.a)
303        else (HAVE_LIBRT_STATIC)
304            message(STATUS "  no librt found (needed by libusb). No smartreader support")
305        endif (HAVE_LIBRT_STATIC)
306    else (LIBRTDIR)
307        check_include_file ("time.h" HAVE_LIBRT)
308        if (HAVE_LIBRT)
309            message(STATUS "  librt found (needed by libusb).")
310        else (HAVE_LIBRT)
311            message(STATUS "  no librt found (needed by libusb. No smartreader support")
312        endif (HAVE_LIBRT)
313    endif (LIBRTDIR)
314else (NOT OSCamOperatingSystem MATCHES "Mac OS X")
315    set (HAVE_LIBRT True)
316endif (NOT OSCamOperatingSystem MATCHES "Mac OS X")
317
318
319if( HAVE_LIBRT OR HAVE_LIBRT_STATIC)
320    if (LIBUSBDIR)
321        check_include_file ("${LIBUSBDIR}/include/libusb-1.0/libusb.h" HAVE_LIBUSB)
322        if (HAVE_LIBUSB AND HAVE_PTHREAD)
323            if (EXISTS ${LIBUSBDIR}/lib/libusb-1.0.a)
324                message(STATUS "  static libusb 1.0 found (${LIBUSBDIR}/lib/libusb-1.0.a). Adding smartreader support ")
325                add_definitions ("-DLIBUSB")
326                add_definitions ("-I${LIBUSBDIR}/include/")
327                add_library(imp_libusb STATIC IMPORTED)
328                set_property(TARGET imp_libusb PROPERTY IMPORTED_LOCATION ${LIBUSBDIR}/lib/libusb-1.0.a)
329            else (EXISTS ${LIBUSBDIR}/lib/libusb-1.0.a)
330                message(STATUS "  static libusb 1.0 not found (${LIBUSBDIR}/lib/libusb-1.0.a). No smartreader support ")
331                set (HAVE_LIBUSB False)
332                set (HAVE_LIBRT False)
333                set (HAVE_LIBRT_STATIC False)
334            endif (EXISTS ${LIBUSBDIR}/lib/libusb-1.0.a)
335        else (HAVE_LIBUSB AND HAVE_PTHREAD)
336            message(STATUS "  no libusb 1.0 found. No smartreader support")
337        endif (HAVE_LIBUSB AND HAVE_PTHREAD)
338    else (LIBUSBDIR)
339        check_include_file ("libusb-1.0/libusb.h" HAVE_LIBUSB)
340        if (HAVE_LIBUSB AND HAVE_PTHREAD)
341            if (EXISTS /usr/local/lib/libusb-1.0.a)
342                message(STATUS "  static libusb 1.0 found : /usr/local/lib/libusb-1.0.a . Adding smartreader support ")
343                add_definitions ("-DLIBUSB")
344                add_definitions ("-I/usr/local/include")
345                add_library(imp_libusb STATIC IMPORTED)
346                set_property(TARGET imp_libusb PROPERTY IMPORTED_LOCATION /usr/local/lib/libusb-1.0.a)
347            elseif (EXISTS /usr/lib/libusb-1.0.a)
348                message(STATUS "  static libusb 1.0 found : /usr/lib/libusb-1.0.a . Adding smartreader support ")
349                add_definitions ("-DLIBUSB")
350                add_library(imp_libusb STATIC IMPORTED)
351                set_property(TARGET imp_libusb PROPERTY IMPORTED_LOCATION /usr/lib/libusb-1.0.a)
352            else (EXISTS /usr/local/lib/libusb-1.0.a)
353                message(STATUS "  static libusb 1.0 not found (not in /usr/local/lib/ or /usr/lib/) . No smartreader support ")
354                set (HAVE_LIBUSB False)
355                set (HAVE_LIBRT False)
356                set (HAVE_LIBRT_STATIC False)
357            endif (EXISTS /usr/local/lib/libusb-1.0.a)
358        else (HAVE_LIBUSB AND HAVE_PTHREAD)
359            message(STATUS "  no libusb 1.0 found. No smartreader support")
360        endif (HAVE_LIBUSB AND HAVE_PTHREAD)
361    endif (LIBUSBDIR)
362endif( HAVE_LIBRT OR HAVE_LIBRT_STATIC)
363
364
365check_include_file ("PCSC/wintypes.h" HAVE_PCSC)
366if (HAVE_PCSC)
367    add_definitions ("-DHAVE_PCSC")
368if (OSCamOperatingSystem MATCHES "Linux")
369    add_definitions ("-I/usr/include/PCSC")
370endif (OSCamOperatingSystem MATCHES "Linux")
371else (HAVE_PCSC)
372if (OSCamOperatingSystem MATCHES "Windows/Cygwin")
373    add_definitions ("-Icygwin")
374    set (HAVE_PCSC "1")
375endif (OSCamOperatingSystem MATCHES "Windows/Cygwin")
376endif (HAVE_PCSC)
377
378
379#----------------------- subdirectories ------------------------------
380
381add_subdirectory (csctapi)
382add_subdirectory (algo)
383add_subdirectory (cscrypt)
384if( HAVE_LIBRT OR HAVE_LIBRT_STATIC)
385    if (HAVE_LIBUSB)
386        add_subdirectory (utils)
387    endif (HAVE_LIBUSB)
388endif( HAVE_LIBRT OR HAVE_LIBRT_STATIC)
389
390#----------------------- file groups ------------------------------
391
392file (GLOB csmodules_srcs "module-*.c")
393file (GLOB csmodules_hdrs "module-*.h")
394file (GLOB csreaders_srcs "reader-*.c")
395file (GLOB csreaders_hdrs "reader-*.h")
396file (GLOB csoscam_srcs "oscam-*.c")
397file (GLOB csoscam_hdrs "oscam-*.h")
398file (GLOB exe_srcs "oscam.c")
399file (GLOB exe_hdrs "globals.h")
400file (GLOB all_srcs ${csmodules_srcs} ${csreaders_srcs} ${csoscam_srcs} ${exe_srcs})
401
402#----------------------- modules ------------------------------
403
404set (csmodules "csmodules")
405add_library (${csmodules} STATIC ${csmodules_srcs} ${csmodules_hdrs})
406
407#----------------------- readers ------------------------------
408
409set (csreaders "csreaders")
410add_library (${csreaders} STATIC ${csreaders_srcs} ${csreaders_hdrs})
411
412#----------------------- other oscam files ------------------------------
413
414set (csoscam "csoscam")
415add_library (${csoscam} STATIC ${csoscam_srcs} ${csoscam_hdrs})
416
417#----------------------- the executable ------------------------------
418
419set (exe_name "oscam")
420add_executable (${exe_name} ${exe_srcs} ${exe_hdrs})
421target_link_libraries (${exe_name} ${csoscam} ${csmodules} ${csreaders} csctapi cscrypt algo)
422if(HAVE_LIBRT AND HAVE_LIBUSB)
423    target_link_libraries (${exe_name} imp_libusb)
424    if (NOT OSCamOperatingSystem MATCHES "Mac OS X")
425        target_link_libraries (${exe_name} rt)
426    endif (NOT OSCamOperatingSystem MATCHES "Mac OS X")
427    if (OSCamOperatingSystem MATCHES "Windows/Cygwin")
428        target_link_libraries (${exe_name} setupapi)
429        target_link_libraries (${exe_name} ole32)
430        target_link_libraries (${exe_name} shell32)
431    endif (OSCamOperatingSystem MATCHES "Windows/Cygwin")
432endif(HAVE_LIBRT AND HAVE_LIBUSB)
433
434if (HAVE_LIBRT_STATIC AND HAVE_LIBUSB)
435    target_link_libraries (${exe_name} imp_libusb)
436    if (NOT OSCamOperatingSystem MATCHES "Mac OS X")
437    target_link_libraries (${exe_name} imp_librt)
438    endif (NOT OSCamOperatingSystem MATCHES "Mac OS X")
439    if (OSCamOperatingSystem MATCHES "Windows/Cygwin")
440        target_link_libraries (${exe_name} setupapi)
441        target_link_libraries (${exe_name} ole32)
442        target_link_libraries (${exe_name} shell32)
443    endif (OSCamOperatingSystem MATCHES "Windows/Cygwin")
444endif (HAVE_LIBRT_STATIC AND HAVE_LIBUSB)
445
446if (HAVE_PTHREAD)
447    target_link_libraries (${exe_name} pthread)
448endif (HAVE_PTHREAD)
449
450if (WITH_SSL)
451    target_link_libraries (${exe_name} ssl)
452endif (WITH_SSL)
453
454if (HAVE_LIBCRYPTO)
455    target_link_libraries (${exe_name} crypto)
456endif (HAVE_LIBCRYPTO)
457
458if (HAVE_PCSC)
459if (NOT OSCamOperatingSystem MATCHES "Mac OS X")
460if (NOT OSCamOperatingSystem MATCHES "Windows/Cygwin")
461    target_link_libraries (${exe_name} pcsclite)
462endif (NOT OSCamOperatingSystem MATCHES "Windows/Cygwin")
463endif (NOT OSCamOperatingSystem MATCHES "Mac OS X")
464endif (HAVE_PCSC)
465
466
467add_dependencies (${exe_name} ${csoscam} ${csreaders} ${csmodules})
468
469#----------------------- specific options ------------------------------
470
471if (OSCamOperatingSystem MATCHES "Linux")
472elseif (OSCamOperatingSystem MATCHES "Mac OS X")
473    FIND_LIBRARY (PCSC_LIBRARY PCSC)
474    message (STATUS "OS X system PCSC : ${PCSC_LIBRARY}")
475    target_link_libraries ( ${exe_name} ${PCSC_LIBRARY})
476    set (HAVE_PCSC "1")
477    FIND_LIBRARY (IOKit_LIBRARY IOKit)
478    target_link_libraries ( ${exe_name} ${IOKit_LIBRARY})
479    FIND_LIBRARY (CoreFoundation_LIBRARY CoreFoundation)
480    target_link_libraries ( ${exe_name} ${CoreFoundation_LIBRARY})
481elseif (OSCamOperatingSystem MATCHES "Tuxbox")
482    target_link_libraries ( ${exe_name} dl)
483elseif (OSCamOperatingSystem MATCHES "TripleDragon")
484    target_link_libraries ( ${exe_name} dl)
485elseif (OSCamOperatingSystem MATCHES "SlugOS")
486elseif (OSCamOperatingSystem MATCHES "OpenWRT")
487elseif (OSCamOperatingSystem MATCHES "Fonera2")
488elseif (OSCamOperatingSystem MATCHES "DIR-825")
489elseif (OSCamOperatingSystem MATCHES "agv2+w")
490elseif (OSCamOperatingSystem MATCHES "WRT54G")
491elseif (OSCamOperatingSystem MATCHES "Amino")
492elseif (OSCamOperatingSystem MATCHES "QboxHD")
493elseif (OSCamOperatingSystem MATCHES "Windows/Cygwin")
494    message (STATUS "Windows system PCSC : winscard.dll")
495    target_link_libraries (${exe_name} winscard)
496    target_link_libraries (${exe_name} setupapi )
497    target_link_libraries (${exe_name} ole32)
498    target_link_libraries (${exe_name} shell32)
499elseif (OSCamOperatingSystem MATCHES "NeutrinoHD")
500    target_link_libraries ( ${exe_name} rt nxp )
501elseif (OSCamOperatingSystem MATCHES "AZBox")
502    add_library(xcas STATIC IMPORTED)
503    set_property(TARGET xcas PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/openxcas/libOpenXCASAPI.a)
504    target_link_libraries(${exe_name} xcas)
505endif (OSCamOperatingSystem MATCHES "Linux")
506
507#----------------------- put svnversion in the build ------------------------------
508# at every target rebuild, we re-build the oscam.c compilation...
509
510# add the needed dependency
511add_dependencies (${exe_name} svnversion)
512add_dependencies (${csoscam} svnversion-log)
513
514# how to re-build the files which printout the version
515add_custom_target (
516    svnversion
517    ALL
518    touch ${CMAKE_CURRENT_SOURCE_DIR}/oscam.c
519)
520add_custom_target (
521    svnversion-log
522    ALL
523    touch ${CMAKE_CURRENT_SOURCE_DIR}/oscam-log.c
524)
525
526#if the svnversion program is absent, this will leave the SVN_REVISION string empty,
527#but won't stop CMake.
528execute_process (COMMAND "svnversion" "-n" "-c" "${CMAKE_CURRENT_SOURCE_DIR}" OUTPUT_VARIABLE OSCAM_SVN_REVISION)
529
530if (OSCAM_SVN_REVISION)
531    string (REGEX REPLACE "[0-9]+:" "" OSCAM_SVN_REVISION "${OSCAM_SVN_REVISION}")
532    string (REPLACE "M" "" OSCAM_SVN_REVISION "${OSCAM_SVN_REVISION}")
533    string (REPLACE "exported" "0" OSCAM_SVN_REVISION "${OSCAM_SVN_REVISION}")
534else (OSCAM_SVN_REVISION)
535    set (OSCAM_SVN_REVISION "0")
536endif (OSCAM_SVN_REVISION)
537
538# pass the version to the compilations as a define
539add_definitions ("-D'CS_SVN_VERSION=\"${OSCAM_SVN_REVISION}\"'")
540
541#----------------------- global compile and link options ------------------------------
542
543# some optimisations
544if (OSCamOperatingSystem MATCHES "Mac OS X")
545    add_definitions ("-O2 -Winline -Wall -Wextra -finline-functions -fomit-frame-pointer -m32 -mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk")
546    set (CMAKE_C_FLAGS_DEBUG "-O0 -g -m32")
547    set (CMAKE_CXX_FLAGS_DEBUG "-O0 -g -m32")
548elseif (OSCAM_SYSTEM_NAME MATCHES "NSLU2")
549    add_definitions ("-O2 -Winline -Wall")
550elseif (OSCAM_SYSTEM_NAME MATCHES "WRT350NV2")
551#    add_definitions ("-O2 -Winline -Wall -finline-functions -fomit-frame-pointer")
552# Definitions above temp. disabled for wrt350nv2 - produces much bigger binary-file in size. -O2 is enough and results in a smaller binary
553    add_definitions ("-O2")
554elseif (OSCAM_SYSTEM_NAME MATCHES "Dockstar")
555    add_definitions ("-O2 -Winline -Wall")
556elseif (OSCAM_SYSTEM_NAME MATCHES "Padre")
557    add_definitions ("-O2 -Winline -Wall -finline-functions -fomit-frame-pointer")
558elseif (OSCAM_SYSTEM_NAME MATCHES "FriendlyARM")
559    add_definitions ("-O2 -Winline -Wall -finline-functions -fomit-frame-pointer")
560else (OSCamOperatingSystem MATCHES "Mac OS X")
561    add_definitions ("-Winline -Wall -Wextra")
562    set (CMAKE_C_FLAGS "-O2")
563    set (CMAKE_C_FLAGS_DEBUG "-O0 -g")
564    set (CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
565endif (OSCamOperatingSystem MATCHES "Mac OS X")
566
567# we don't want the '-rdynamic' in the link command
568set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
569
570# we want to strip if not Debug build
571if (OSCamOperatingSystem MATCHES "Mac OS X")
572  if (NOT CMAKE_BUILD_TYPE STREQUAL Debug)
573    set (CMAKE_EXE_LINKER_FLAGS "-s -m32 -mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk")
574  else (NOT CMAKE_BUILD_TYPE STREQUAL Debug)
575    message (STATUS "  building with debug")
576    set (CMAKE_EXE_LINKER_FLAGS "-ggdb -m32 -mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk")
577  endif (NOT CMAKE_BUILD_TYPE STREQUAL Debug)
578else (OSCamOperatingSystem MATCHES "Mac OS X")
579  if (NOT CMAKE_BUILD_TYPE STREQUAL Debug)
580    set (CMAKE_EXE_LINKER_FLAGS "-s")
581  else (NOT CMAKE_BUILD_TYPE STREQUAL Debug)
582    message (STATUS "  building with debug")
583    set (CMAKE_EXE_LINKER_FLAGS "-ggdb")
584  endif (NOT CMAKE_BUILD_TYPE STREQUAL Debug)
585endif (OSCamOperatingSystem MATCHES "Mac OS X")
586
587if (OSCamOperatingSystem MATCHES "Windows/Cygwin")
588    set (CMAKE_EXE_LINKER_FLAGS "--enable-stdcall-fixup")
589endif (OSCamOperatingSystem MATCHES "Windows/Cygwin")
590
591#----------------------- installation -----------------------------
592
593file (GLOB config_files "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/oscam.*")
594file (GLOB doc_files "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/txt/*.txt")
595file (GLOB man1_files "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/man/*.1")
596file (GLOB man5_files "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/man/*.5")
597file (GLOB example_files "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.ac"
598                         "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.cert"
599                         "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.conf"
600                         "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.guess"
601                         "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.ird"
602                         "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.server"
603                         "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.services"
604                         "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.srvid"
605                         "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.user")
606file (GLOB monitor_files "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/monitor/mpcs*.sh"
607                         "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/monitor/mpcs*.tar")
608
609install (PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${exe_name}${CMAKE_EXECUTABLE_SUFFIX} DESTINATION bin COMPONENT bin)
610install (FILES ${config_files} DESTINATION etc COMPONENT config)
611install (FILES ${doc_files} DESTINATION share/doc/oscam COMPONENT doc)
612install (FILES ${man1_files} DESTINATION share/man/man1 COMPONENT doc)
613install (FILES ${man5_files} DESTINATION share/man/man5 COMPONENT doc)
614install (FILES ${example_files} DESTINATION share/doc/oscam/example COMPONENT doc)
615install (FILES ${monitor_files} DESTINATION share/doc/oscam/monitor COMPONENT doc)
616
617#----------------------- we can use CPack to build pacakges --------------------------
618
619# get version from source file
620execute_process (COMMAND grep CS_VERSION ${CMAKE_CURRENT_SOURCE_DIR}/globals.h
621    OUTPUT_VARIABLE CS_VERSION)
622string (REGEX REPLACE ".*\"\(.*\)\".*" "\\1" CS_VERSION ${CS_VERSION})
623string (REGEX REPLACE "\(.*\)\\..*\\..*" "\\1" CPACK_PACKAGE_VERSION_MAJOR ${CS_VERSION})
624string (REGEX REPLACE ".*\\.\(.*\)\\..*" "\\1" CPACK_PACKAGE_VERSION_MINOR ${CS_VERSION})
625string (REGEX REPLACE ".*\\..*\\.\(.*\)" "\\1" CPACK_PACKAGE_VERSION_PATCH ${CS_VERSION})
626set (CPACK_PACKAGE_VERSION
627     "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
628
629# compute my filename
630set (CPACK_PACKAGE_FILE_NAME
631     "${PROJECT_NAME}-${CPACK_PACKAGE_VERSION}-${CS_OSTYPE}")
632
633# wich archive we want to generate
634set (CPACK_GENERATOR "TGZ")
635
636# what to put in the archive
637set (CPACK_STRIP_FILES TRUE)
638set (CPACK_COMPONENTS_ALL bin)# config doc)
639
640# ok, we can now use CPack
641include (CPack)
642
643#----------------------- printout resume -----------------------------
644
645message (STATUS "")
646message (STATUS "  operating system: ${OSCamOperatingSystem}")
647message (STATUS "  system type: ${CS_OSTYPE}")
648message (STATUS "  system: ${CS_OS_SYS}")
649message (STATUS "  cpu: ${CS_OS_CPU}")
650message (STATUS "  hw: ${CS_OS_HW}")
651if (HAVE_LIBCRYPTO)
652    message (STATUS "  use libcrypto functions")
653else (HAVE_LIBCRYPTO)
654    message (STATUS "  use built-in crypt functions")
655endif (HAVE_LIBCRYPTO)
656if (HAVE_PCSC)
657    message (STATUS "  use system pcsc functions")
658endif (HAVE_PCSC)
659if (HAVE_PTHREAD)
660    message (STATUS "  use system pthread functions")
661endif (HAVE_PTHREAD)
662if (HAVE_LIBUSB)
663    message (STATUS "  use system libusb functions")
664endif (HAVE_LIBUSB)
665
666message (STATUS "")
Note: See TracBrowser for help on using the repository browser.