source: trunk/CMakeLists.txt @ 431

Last change on this file since 431 was 431, checked in by smurzch2, 10 years ago

Add WRT54G target in the cmake builds.

File size: 10.1 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 "Fonera2")
23        set (OSCamOperatingSystem "Fonera2")
24        set (CS_OS_HW "fonera2")
25        set (CS_OS_SYS "linux")
26    elseif (OSCAM_SYSTEM_NAME MATCHES "WRT54G")
27        set (OSCamOperatingSystem "WRT54G")
28        set (CS_OS_HW "wrt54g")
29        set (CS_OS_SYS "linux")
30    elseif (OSCAM_SYSTEM_NAME MATCHES "Amino")
31        set (OSCamOperatingSystem "Amino")
32        set (CS_OS_HW "amino")
33        set (CS_OS_SYS "linux")
34    else (OSCAM_SYSTEM_NAME MATCHES "Tuxbox")
35        message (STATUS "Unknown cross system name: <${CMAKE_SYSTEM_NAME}>")
36        set (OSCamOperatingSystem "Unknown")
37        set (CS_OS_HW "unknown")
38        set (CS_OS_SYS "unknown")
39    endif (OSCAM_SYSTEM_NAME MATCHES "Tuxbox")
40else (CMAKE_CROSSCOMPILING)
41    if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
42        set (OSCamOperatingSystem "Linux")
43        set (CS_OS_HW "pc")
44        set (CS_OS_SYS "linux")
45    elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
46        set (OSCamOperatingSystem "Mac OS X")
47        set (CS_OS_HW "mac")
48        set (CS_OS_SYS "macosx")
49    elseif (${CYGWIN})
50        set (OSCamOperatingSystem "Windows/Cygwin")
51        set (CS_OS_HW "pc")
52        set (CS_OS_SYS "cygwin")
53        set (CMAKE_SYSTEM_PROCESSOR "i386")
54    else (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
55        message (STATUS "Unknown system name: <${CMAKE_SYSTEM_NAME}>")
56        set (OSCamOperatingSystem "Unknown")
57        set (CS_OS_HW "unknown")
58        set (CS_OS_SYS "unknown")
59    endif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
60endif (CMAKE_CROSSCOMPILING)
61
62#----------------------- some paths ------------------------------
63
64set (OPTIONAL_LINK_DIR "" CACHE STRING "Some optional link directories")
65set (OPTIONAL_INCLUDE_DIR "" CACHE STRING "Some optional include directories")
66
67include_directories (
68    ${CMAKE_CURRENT_SOURCE_DIR}/csctapi
69    ${CMAKE_CURRENT_SOURCE_DIR}/cscrypt
70    ${OPTIONAL_INCLUDE_DIR}
71    )
72link_directories (${OPTIONAL_LINK_DIR})
73
74#----------------------- global options ------------------------------
75
76if (OSCamOperatingSystem MATCHES "Linux")
77    add_definitions ("-DOS_LINUX")
78    set (DEFAULT_CS_CONFDIR "/usr/local/etc")
79elseif (OSCamOperatingSystem MATCHES "Mac OS X")
80    add_definitions ("-DOS_MACOSX -DNEED_DAEMON -DCS_NOSHM -DHAVE_PTHREAD_H -DUSE_PTHREAD")
81    set (DEFAULT_CS_CONFDIR "/usr/local/etc")
82elseif (OSCamOperatingSystem MATCHES "Tuxbox")
83    add_definitions ("-DOS_LINUX -DTUXBOX -DPPC")
84    set (DEFAULT_CS_CONFDIR "/var/tuxbox/config")
85elseif (OSCamOperatingSystem MATCHES "Fonera2")
86    add_definitions ("-DOS_LINUX -DMIPSEL -DUCLIBC")
87    set (DEFAULT_CS_CONFDIR "/var/etc")
88elseif (OSCamOperatingSystem MATCHES "WRT54G")
89    add_definitions ("-DOS_LINUX -DMIPSEL -DUCLIBC -DUSE_GPIO")
90    set (DEFAULT_CS_CONFDIR "/jffs/etc/config/oscam")
91elseif (OSCamOperatingSystem MATCHES "Amino")
92    add_definitions ("-DOS_LINUX")
93    set (DEFAULT_CS_CONFDIR "/usr/local/etc")
94elseif (OSCamOperatingSystem MATCHES "Windows/Cygwin")
95    add_definitions ("-DOS_CYGWIN32")
96    set (DEFAULT_CS_CONFDIR ".")
97endif (OSCamOperatingSystem MATCHES "Linux")
98
99set (CS_CONFDIR ${DEFAULT_CS_CONFDIR} CACHE STRING "Default path for the config files")
100add_definitions ("-DCS_CONFDIR=\\\"${CS_CONFDIR}\\\"")
101
102set (CS_OS_CPU ${CMAKE_SYSTEM_PROCESSOR})
103set (CS_OSTYPE ${CS_OS_CPU}-${CS_OS_HW}-${CS_OS_SYS})
104
105add_definitions ("-DUSE_CMAKE")
106add_definitions ("-DCS_OSTYPE=\\\"${CS_OSTYPE}\\\"")
107add_definitions ("-DCS_OS_CPU=\\\"${CS_OS_CPU}\\\"")
108add_definitions ("-DCS_OS_HW=\\\"${CS_OS_HW}\\\"")
109add_definitions ("-DCS_OS_SYS=\\\"${CS_OS_SYS}\\\"")
110
111#----------------------- subdirectories ------------------------------
112
113include (CheckIncludeFile)
114check_include_file ("openssl/aes.h" HAVE_AES)
115if (HAVE_AES)
116    add_definitions ("-DHAVE_AES")
117endif (HAVE_AES)
118
119#----------------------- subdirectories ------------------------------
120
121add_subdirectory (csctapi)
122add_subdirectory (cscrypt)
123
124#----------------------- file groups ------------------------------
125
126file (GLOB csmodules_srcs "module-*.c")
127file (GLOB csmodules_hdrs "module-*.h")
128file (GLOB csreaders_srcs "reader-*.c")
129file (GLOB csreaders_hdrs "reader-*.h")
130file (GLOB csoscam_srcs "oscam-*.c")
131file (GLOB csoscam_hdrs "oscam-*.h")
132file (GLOB exe_srcs "oscam.c")
133file (GLOB exe_hdrs "globals.h")
134file (GLOB all_srcs ${csmodules_srcs} ${csreaders_srcs} ${csoscam_srcs} ${exe_srcs})
135
136#----------------------- modules ------------------------------
137
138set (csmodules "csmodules")
139add_library (${csmodules} STATIC ${csmodules_srcs} ${csmodules_hdrs})
140
141#----------------------- readers ------------------------------
142
143set (csreaders "csreaders")
144add_library (${csreaders} STATIC ${csreaders_srcs} ${csreaders_hdrs})
145
146#----------------------- other oscam files ------------------------------
147
148set (csoscam "csoscam")
149add_library (${csoscam} STATIC ${csoscam_srcs} ${csoscam_hdrs})
150
151#----------------------- the executable ------------------------------
152
153set (exe_name "oscam")
154add_executable (${exe_name} ${exe_srcs} ${exe_hdrs})
155target_link_libraries (${exe_name} ${csoscam} ${csmodules} ${csreaders} csctapi cscrypt pthread)
156if (HAVE_AES)
157    target_link_libraries (${exe_name} crypto)
158endif (HAVE_AES)
159add_dependencies (${exe_name} ${csoscam} ${csreaders} ${csmodules})
160
161#----------------------- specific options ------------------------------
162
163if (OSCamOperatingSystem MATCHES "Linux")
164elseif (OSCamOperatingSystem MATCHES "Mac OS X")
165elseif (OSCamOperatingSystem MATCHES "Tuxbox")
166    target_link_libraries ( ${exe_name} dl)
167elseif (OSCamOperatingSystem MATCHES "Fonera2")
168elseif (OSCamOperatingSystem MATCHES "WRT54G")
169elseif (OSCamOperatingSystem MATCHES "Amino")
170elseif (OSCamOperatingSystem MATCHES "Windows/cygwin")
171endif (OSCamOperatingSystem MATCHES "Linux")
172
173#----------------------- global compile and link options ------------------------------
174
175# some optimisations
176add_definitions ("-O3 -Winline -Werror -finline-functions -fomit-frame-pointer")
177
178# we don't want the '-rdynamic' in the link command
179set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
180
181# we want to strip
182set (CMAKE_EXE_LINKER_FLAGS "-s")
183
184#----------------------- installation -----------------------------
185
186file (GLOB config_files "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/oscam.*")
187file (GLOB doc_files "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/txt/*.txt")
188file (GLOB man1_files "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/man/*.1")
189file (GLOB man5_files "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/man/*.5")
190file (GLOB example_files "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.ac"
191                         "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.cert"
192                         "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.conf"
193                         "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.guess"
194                         "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.ird"
195                         "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.server"
196                         "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.services"
197                         "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.srvid"
198                         "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/doc/example/oscam.user")
199file (GLOB monitor_files "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/monitor/mpcs*.sh"
200                         "${CMAKE_CURRENT_SOURCE_DIR}/Distribution/monitor/mpcs*.tar")
201
202install (PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${exe_name}${CMAKE_EXECUTABLE_SUFFIX} DESTINATION bin COMPONENT bin)
203install (FILES ${config_files} DESTINATION etc COMPONENT config)
204install (FILES ${doc_files} DESTINATION share/doc/oscam COMPONENT doc)
205install (FILES ${man1_files} DESTINATION share/man/man1 COMPONENT doc)
206install (FILES ${man5_files} DESTINATION share/man/man5 COMPONENT doc)
207install (FILES ${example_files} DESTINATION share/doc/oscam/example COMPONENT doc)
208install (FILES ${monitor_files} DESTINATION share/doc/oscam/monitor COMPONENT doc)
209
210#----------------------- we can use CPack to build pacakges --------------------------
211
212# get version from source file
213execute_process (COMMAND grep CS_VERSION ${CMAKE_CURRENT_SOURCE_DIR}/globals.h
214    OUTPUT_VARIABLE CS_VERSION)
215string (REGEX REPLACE ".*\"\(.*\)\".*" "\\1" CS_VERSION ${CS_VERSION})
216string (REGEX REPLACE "\(.*\)\\..*\\..*" "\\1" CPACK_PACKAGE_VERSION_MAJOR ${CS_VERSION})
217string (REGEX REPLACE ".*\\.\(.*\)\\..*" "\\1" CPACK_PACKAGE_VERSION_MINOR ${CS_VERSION})
218string (REGEX REPLACE ".*\\..*\\.\(.*\)" "\\1" CPACK_PACKAGE_VERSION_PATCH ${CS_VERSION})
219set (CPACK_PACKAGE_VERSION
220     "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
221
222# compute my filename
223set (CPACK_PACKAGE_FILE_NAME
224     "${PROJECT_NAME}-${CPACK_PACKAGE_VERSION}-${CS_OSTYPE}")
225
226# wich archive we want to generate
227set (CPACK_GENERATOR "TGZ")
228
229# what to put in the archive
230set (CPACK_STRIP_FILES TRUE)
231set (CPACK_COMPONENTS_ALL bin)# config doc)
232
233# ok, we can now use CPack
234include (CPack)
235
236#----------------------- printout resume -----------------------------
237
238message (STATUS "")
239message (STATUS "  operating system: ${OSCamOperatingSystem}")
240message (STATUS "  system type: ${CS_OSTYPE}")
241message (STATUS "  system: ${CS_OS_SYS}")
242message (STATUS "  cpu: ${CS_OS_CPU}")
243message (STATUS "  hw: ${CS_OS_HW}")
244if (HAVE_AES)
245    message (STATUS "  use system aes functions")
246else (HAVE_AES)
247    message (STATUS "  use built-in aes functions")
248endif (HAVE_AES)
249message (STATUS "")
Note: See TracBrowser for help on using the repository browser.