source: trunk/CMakeLists.txt @ 1184

Last change on this file since 1184 was 1184, checked in by rorothetroll, 10 years ago

fix OS X g++ CXX_FLAGS

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