summaryrefslogtreecommitdiffstats
path: root/CMakeLists.txt
blob: 2f5e9f01836c1be450c6455f7a41e3167c11cc7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#########################################################################
#
# Copyright (c) 2018 Huawei Technologies Co.,Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#########################################################################


CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11)
PROJECT(nStack)

option(RMWS    "automatically remove trailing whitespace using git pre-commit hook" OFF)
option(WITH_SECUREC_LIB "Option description" OFF)
option(WITH_HAL_LIB "Option description" OFF)

SET(CMAKE_C_COMPILER "gcc")
SET(EXECUTABLE_PATH ${CMAKE_CURRENT_LIST_DIR}/release/bin)
SET(LIB_PATH_STATIC ${PROJECT_BINARY_DIR})
SET(LIB_PATH_SHARED ${CMAKE_CURRENT_LIST_DIR}/release/lib64)
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIB_PATH_STATIC})
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_PATH})
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIB_PATH_SHARED})
SET(DMM_DPDK_INSTALL_DIR "" CACHE STRING "to get the dpdk install path by cmd")
SET(DMM_REL_INC_DIR ${CMAKE_CURRENT_LIST_DIR}/release/include)
SET(DMM_ARCH x86)

SET(GENERATE_RPM_PATH ${CMAKE_CURRENT_LIST_DIR}/release/rpm)
file(MAKE_DIRECTORY ${GENERATE_RPM_PATH})

SET(GENERATE_DEB_PATH ${CMAKE_CURRENT_LIST_DIR}/release/deb)
file(MAKE_DIRECTORY ${GENERATE_DEB_PATH})

MESSAGE(STATUS "Top dir is: " ${CMAKE_CURRENT_LIST_DIR})
MESSAGE(STATUS "Static library dir: " ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})
MESSAGE(STATUS "Executable binary dir: " ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
MESSAGE(STATUS "Shared library dir: " ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})


add_custom_target(clean-cmake-files
  COMMAND ${CMAKE_COMMAND} -P clean-all.cmake
)

if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
  message(STATUS "Setting git commit template...")
  execute_process(COMMAND git config --local commit.template ${CMAKE_SOURCE_DIR}/scripts/git/commit-msg-template
                  RESULT_VARIABLE  git_config_ret)
  if(git_config_ret EQUAL 0)
    message(STATUS "Setting git commit template...done")
  else()
    message(WARNING "Setting git commit template...failed")
  endif()

  find_program(GIT_REVIEW git-review)
  if(NOT GIT_REVIEW)
    if(NOT EXISTS "${CMAKE_SOURCE_DIR}/.git/hooks/commit-msg")
      message(STATUS "git-review not found")
      message(STATUS "Setting git commit hook...")
      execute_process(COMMAND ln -s ${CMAKE_SOURCE_DIR}/scripts/git/commit-msg-hook.py ${CMAKE_SOURCE_DIR}/.git/hooks/commit-msg
                      RESULT_VARIABLE  ln_ret)
      if(ln_ret EQUAL 0)
        message(STATUS "Setting git commit hook...done")
      else()
        message(WARNING "Setting git commit hook...failed")
      endif()
    endif()
  else()
    if(NOT EXISTS "${CMAKE_SOURCE_DIR}/.git/hooks/commit-msg")
      message(AUTHOR_WARNING  "Found git-review but this repo does not seem to have been initialized by git-review. Please manually execute 'git review -s' before cmake.")
    else()
      file(READ ${CMAKE_SOURCE_DIR}/.git/hooks/commit-msg contents)
      string(FIND "${contents}" "commit-msg-hook.py" match_ret)
      if(${match_ret} EQUAL -1)
        file(APPEND ${CMAKE_SOURCE_DIR}/.git/hooks/commit-msg "${CMAKE_SOURCE_DIR}/scripts/git/commit-msg-hook.py $1")
      endif()
    endif()
  endif()

  if(RMWS)
    message(STATUS  "Setting git pre-commit hook...")
    execute_process(COMMAND ln -sf ${CMAKE_SOURCE_DIR}/scripts/git/pre-commit ${CMAKE_SOURCE_DIR}/.git/hooks/pre-commit
                    RESULT_VARIABLE  ln_sf_ret)
    if(ln_sf_ret EQUAL 0)
      message(STATUS  "Setting git pre-commit hook...done")
    else()
      message(WARNING "Setting git pre-commit hook...failed")
    endif()
  endif()
endif()

if(WITH_SECUREC_LIB)
  add_definitions(-DSECUREC_LIB)
endif()

if(WITH_HAL_LIB)
  add_definitions(-DHAL_LIB)
endif()

SET(post_compile "${PROJECT_BINARY_DIR}/post_compile.sh")
FILE(WRITE ${post_compile} "#!/bin/bash\n")
if(WITH_HAL_LIB)
else()
FILE(APPEND ${post_compile}
"

cp -f ${CMAKE_CURRENT_LIST_DIR}/src/nSocket/include/nstack_dmm_api.h ${CMAKE_CURRENT_LIST_DIR}/release/include/
cp -f ${CMAKE_CURRENT_LIST_DIR}/src/adapt/nstack_dmm_adpt.h ${CMAKE_CURRENT_LIST_DIR}/release/include/
cp -f ${CMAKE_CURRENT_LIST_DIR}/src/adapt/nstack_share_res.h ${CMAKE_CURRENT_LIST_DIR}/release/include/
cp -f ${CMAKE_CURRENT_LIST_DIR}/src/nSocket/include/declare_syscalls.h ${CMAKE_CURRENT_LIST_DIR}/release/include/
cp -f ${CMAKE_CURRENT_LIST_DIR}/src/framework/include/* ${CMAKE_CURRENT_LIST_DIR}/release/include/
cp -rf ${CMAKE_CURRENT_LIST_DIR}/src/framework/common/base/include/*.h ${CMAKE_CURRENT_LIST_DIR}/release/include/
cp -rf ${CMAKE_CURRENT_LIST_DIR}/src/framework/common/base/include/common/* ${CMAKE_CURRENT_LIST_DIR}/release/include/

cp -f ${CMAKE_CURRENT_LIST_DIR}/src/framework/common/include/*.h ${CMAKE_CURRENT_LIST_DIR}/release/include/
cp -rf ${CMAKE_CURRENT_LIST_DIR}/src/framework/common/include/generic ${CMAKE_CURRENT_LIST_DIR}/release/include/
cp -f ${CMAKE_CURRENT_LIST_DIR}/src/framework/common/include/arch/${DMM_ARCH}/* ${CMAKE_CURRENT_LIST_DIR}/release/include/
cp -f ${CMAKE_CURRENT_LIST_DIR}/src/framework/ipc/mgr_com/mgr_com.h ${CMAKE_CURRENT_LIST_DIR}/release/include/
cp -f ${CMAKE_CURRENT_LIST_DIR}/src/framework/hal/hal.h ${CMAKE_CURRENT_LIST_DIR}/release/include/
cp -f ${CMAKE_CURRENT_LIST_DIR}/src/nSocket/include/nstack_dmm_api.h ${CMAKE_CURRENT_LIST_DIR}/release/include/
echo post compile process success.
"
)
endif()

SET(clean_compile "${PROJECT_BINARY_DIR}/clean_compile.sh")
FILE(WRITE ${clean_compile} "#!/bin/bash\n")
FILE(APPEND ${clean_compile}
"

rm -rf ${CMAKE_CURRENT_LIST_DIR}/release/include/*.h
rm -rf ${CMAKE_CURRENT_LIST_DIR}/release/include/generic
rm -rf ${CMAKE_CURRENT_LIST_DIR}/release/lib64/libdmm_api.so

echo post clean process success.
"
)

ADD_CUSTOM_TARGET(DPDK ALL COMMAND sh post_compile.sh)
ADD_DEPENDENCIES(DPDK dmm_api)

ADD_CUSTOM_TARGET(pkg-rpm COMMAND sh ../scripts/generate_dmm_rpm.sh)

ADD_CUSTOM_TARGET(pkg-deb COMMAND sh ../scripts/generate_dmm_deb.sh)

ADD_CUSTOM_TARGET(vpp-stack COMMAND sh ../scripts/build_vpp.sh)
ADD_DEPENDENCIES(vpp-stack DPDK)

ADD_CUSTOM_TARGET(checkstyle
 COMMAND bash  ${CMAKE_CURRENT_LIST_DIR}/scripts/checkstyle.sh -c)
ADD_CUSTOM_TARGET(fixstyle
 COMMAND bash  ${CMAKE_CURRENT_LIST_DIR}/scripts/checkstyle.sh -f)

ADD_CUSTOM_TARGET(clean-all
 COMMAND ${CMAKE_BUILD_TOOL} clean
 COMMAND sh clean_compile.sh)

SET(JSON_C_URL https://github.com/json-c/json-c/archive/json-c-0.12.1-20160607.tar.gz)
SET(JSON_C_DOWNLOAD_DIR ${CMAKE_CURRENT_LIST_DIR}/thirdparty/json/)
SET(JSON_C_SRC ${CMAKE_CURRENT_LIST_DIR}/thirdparty/json/json-c-0.12.1)
if(EXISTS "${JSON_C_DOWNLOAD_DIR}/json-c-0.12.1.tar.gz")
    SET(JSON_DOWNLOAD_CMD tar -xvf ${JSON_C_DOWNLOAD_DIR}/json-c-0.12.1.tar.gz  -C ${JSON_C_DOWNLOAD_DIR}/json-c-0.12.1 --strip-components 1)
else()
    SET(JSON_DOWNLOAD_CMD wget --no-check-certificate -O json-c-0.12.1.tar.gz ${JSON_C_URL} || rm -f json-c-0.12.1.tar.gz && tar -xvf ${JSON_C_DOWNLOAD_DIR}/json-c-0.12.1.tar.gz  -C ${JSON_C_DOWNLOAD_DIR}/json-c-0.12.1 --strip-components 1)
endif()
INCLUDE(ExternalProject)
ExternalProject_Add(
		JSON
		DOWNLOAD_DIR ${JSON_C_DOWNLOAD_DIR}
		DOWNLOAD_COMMAND ${JSON_DOWNLOAD_CMD}
		BUILD_IN_SOURCE 1
		SOURCE_DIR ${JSON_C_SRC}
		CONFIGURE_COMMAND sh autogen.sh COMMAND sh ./configure --enable-static --with-pic
        BUILD_COMMAND make -j 8
		INSTALL_COMMAND cp -f .libs/libjson-c.a ${LIB_PATH_STATIC}/
)

SET(SECUREC_SRC ${CMAKE_CURRENT_LIST_DIR}/thirdparty/SecureC/src)
SET(SECUREC_SRC_H ${CMAKE_CURRENT_LIST_DIR}/thirdparty/SecureC/include)

if(WITH_SECUREC_LIB)
INCLUDE(ExternalProject)
ExternalProject_Add(
		SECUREC
		SOURCE_DIR ${SECUREC_SRC}
		BUILD_IN_SOURCE 1
		CONFIGURE_COMMAND ""
        BUILD_COMMAND COMMAND make -j 8
		INSTALL_COMMAND cp -f ${SECUREC_SRC}/../lib/libsecurec.so ${LIB_PATH_SHARED}/
)
endif()

SET(GLOG_SRC ${CMAKE_CURRENT_LIST_DIR}/thirdparty/glog/glog-0.3.4)
INCLUDE(ExternalProject)
ExternalProject_Add(
		GLOG
		SOURCE_DIR ${GLOG_SRC}
		BUILD_IN_SOURCE 1
		CONFIGURE_COMMAND autoreconf -ivf COMMAND sh configure CFLAGS=-fPIC CXXFLAGS=-fPIC
        BUILD_COMMAND COMMAND make -j 8
		INSTALL_COMMAND cp -f ${GLOG_SRC}/.libs/libglog.a ${LIB_PATH_STATIC}/
)

ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(app_example)

ADD_SUBDIRECTORY(stacks/rsocket)
ADD_SUBDIRECTORY(thirdparty/apps)
ion}-%{_release}.tar.xz # Source: vpp-latest.tar.xz %description This package provides VPP executables: vpp, vpp_api_test, vpp_json_test vpp - the vector packet engine vpp_api_test - vector packet engine API test tool vpp_json_test - vector packet engine JSON test tool %package lib Summary: VPP libraries Group: System Environment/Libraries %description lib This package contains the VPP shared libraries, including: vppinfra - foundation library supporting vectors, hashes, bitmaps, pools, and string formatting. svm - vm library vlib - vector processing library vlib-api - binary API library vnet - network stack library %package devel Summary: VPP header files, static libraries Group: Development/Libraries Requires: vpp-lib %description devel This package contains the header files for VPP. Install this package if you want to write a program for compilation and linking with vpp lib. vlib vlibmemory vnet - devices, classify, dhcp, ethernet flow, gre, ip, etc. vpp-api vppinfra %package plugins Summary: Vector Packet Processing--runtime plugins Group: System Environment/Libraries Requires: vpp = %{_version}-%{_release} numactl-libs %description plugins This package contains VPP plugins %package api-lua Summary: VPP api lua bindings Group: Development/Libraries Requires: vpp = %{_version}-%{_release}, vpp-lib = %{_version}-%{_release} %description api-lua This package contains the lua bindings for the vpp api %package api-java Summary: VPP api java bindings Group: Development/Libraries Requires: vpp = %{_version}-%{_release}, vpp-lib = %{_version}-%{_release} %description api-java This package contains the java bindings for the vpp api %package api-python Summary: VPP api python bindings Group: Development/Libraries Requires: vpp = %{_version}-%{_release}, vpp-lib = %{_version}-%{_release}, python-setuptools libffi-devel %description api-python This package contains the python bindings for the vpp api %prep # Unpack into dir with longer name as work around of debugedit bug in in rpm-build 4.13 rm -rf %{name}-%{_version} rm -rf %{_tmp_build_dir} /usr/bin/xz -dc '%{_sourcedir}/%{name}-%{_version}-%{_release}.tar.xz' | /usr/bin/tar -xf - mv %{name}-%{_version} %{_tmp_build_dir} cd '%{_tmp_build_dir}' /usr/bin/chmod -Rf a+rX,u+w,g-w,o-w . %pre # Add the vpp group groupadd -f -r vpp %build cd '%{_tmp_build_dir}' %if %{with aesni} make bootstrap make -C build-root PLATFORM=vpp TAG=%{_vpp_tag} install-packages %else make bootstrap AESNI=n make -C build-root PLATFORM=vpp AESNI=n TAG=%{_vpp_tag} install-packages %endif cd %{_mu_build_dir}/../src/vpp-api/python && %py2_build %install # # binaries # mkdir -p -m755 %{buildroot}%{_bindir} mkdir -p -m755 %{buildroot}%{_unitdir} install -p -m 755 %{_mu_build_dir}/%{_vpp_install_dir}/vpp/bin/* %{buildroot}%{_bindir} # api mkdir -p -m755 %{buildroot}/usr/share/vpp/api # # configs # mkdir -p -m755 %{buildroot}/etc/vpp mkdir -p -m755 %{buildroot}/etc/sysctl.d install -p -m 644 %{_mu_build_dir}/../extras/rpm/vpp.service %{buildroot}%{_unitdir} install -p -m 644 %{_mu_build_dir}/../src/vpp/conf/startup.conf %{buildroot}/etc/vpp/startup.conf install -p -m 644 %{_mu_build_dir}/../src/vpp/conf/80-vpp.conf %{buildroot}/etc/sysctl.d # # libraries # mkdir -p -m755 %{buildroot}%{_libdir} mkdir -p -m755 %{buildroot}/etc/bash_completion.d mkdir -p -m755 %{buildroot}/usr/share/vpp for file in $(find %{_mu_build_dir}/%{_vpp_install_dir}/*/lib* -type f -name '*.so.*.*.*' -print ) do install -p -m 755 $file %{buildroot}%{_libdir} done for file in $(cd %{buildroot}%{_libdir} && find . -type f -print | sed -e 's/^\.\///') do # make lib symlinks ( cd %{buildroot}%{_libdir} && ln -fs $file $(echo $file | sed -e 's/\(\.so\.[0-9]\+\).*/\1/') ) ( cd %{buildroot}%{_libdir} && ln -fs $file $(echo $file | sed -e 's/\(\.so\)\.[0-9]\+.*/\1/') ) done for file in $(find %{_mu_build_dir}/%{_vpp_install_dir}/vpp/share/vpp/api -type f -name '*.api.json' -print ) do install -p -m 644 $file %{buildroot}/usr/share/vpp/api done install -p -m 644 %{_mu_build_dir}/../src/scripts/vppctl_completion %{buildroot}/etc/bash_completion.d install -p -m 644 %{_mu_build_dir}/../src/scripts/vppctl-cmd-list %{buildroot}/usr/share/vpp # Lua bindings mkdir -p -m755 %{buildroot}/usr/share/doc/vpp/examples/lua/examples/cli mkdir -p -m755 %{buildroot}/usr/share/doc/vpp/examples/lua/examples/lute # for file in $(cd %{_mu_build_dir}/%{_vpp_install_dir}/../../src/vpp-api/lua && git ls-files .) for file in $(cd %{_mu_build_dir}/%{_vpp_install_dir}/../../src/vpp-api/lua && find . -type f -regex '.*/*.[luteamd]' -print | sed -e 's/^\.\///') do ( cd %{_mu_build_dir}/%{_vpp_install_dir}/../../src/vpp-api/lua && install -p -m 644 $file \ %{buildroot}/usr/share/doc/vpp/examples/lua/$file ) done # Java bindings mkdir -p -m755 %{buildroot}/usr/share/java for file in $(find %{_mu_build_dir}/%{_vpp_install_dir}/vpp/share/java -type f -name '*.jar' -print ) do install -p -m 644 $file %{buildroot}/usr/share/java done # Python bindings cd %{_mu_build_dir}/../src/vpp-api/python && %py2_install # # devel # for dir in $(find %{_mu_build_dir}/%{_vpp_install_dir}/*/include/ -maxdepth 0 -type d -print | grep -v dpdk) do for subdir in $(cd ${dir} && find . -type d -print) do mkdir -p -m755 %{buildroot}/usr/include/${subdir} done for file in $(cd ${dir} && find . -type f -print) do install -p -m 644 $dir/$file %{buildroot}%{_includedir}/$file done done mkdir -p -m755 %{buildroot}%{python2_sitelib}/jvppgen install -p -m755 %{_mu_build_dir}/../src/vpp-api/java/jvpp/gen/jvpp_gen.py %{buildroot}/usr/bin for i in $(ls %{_mu_build_dir}/../src/vpp-api/java/jvpp/gen/jvppgen/*.py); do install -p -m666 ${i} %{buildroot}%{python2_sitelib}/jvppgen done; # sample plugin mkdir -p -m755 %{buildroot}/usr/share/doc/vpp/examples/sample-plugin/sample #for file in $(cd %{_mu_build_dir}/%{_vpp_install_dir}/../../src/examples/sample-plugin && git ls-files .) for file in $(cd %{_mu_build_dir}/%{_vpp_install_dir}/../../src/examples/sample-plugin && find . -type f -regex '.*/*.[acdhimp]' -print | sed -e 's/^\.\///') do ( cd %{_mu_build_dir}/%{_vpp_install_dir}/../../src/examples/sample-plugin && install -p -m 644 $file \ %{buildroot}/usr/share/doc/vpp/examples/sample-plugin/$file ) done # # vpp-plugins # mkdir -p -m755 %{buildroot}/usr/lib/vpp_plugins mkdir -p -m755 %{buildroot}/usr/lib/vpp_api_test_plugins for file in $(cd %{_mu_build_dir}/%{_vpp_install_dir}/vpp/lib64/vpp_plugins && find -type f -print) do install -p -m 644 %{_mu_build_dir}/%{_vpp_install_dir}/vpp/lib64/vpp_plugins/$file \ %{buildroot}/usr/lib/vpp_plugins/$file done for file in $(cd %{_mu_build_dir}/%{_vpp_install_dir}/vpp/lib64/vpp_api_test_plugins && find -type f -print) do install -p -m 644 %{_mu_build_dir}/%{_vpp_install_dir}/vpp/lib64/vpp_api_test_plugins/$file \ %{buildroot}/usr/lib/vpp_api_test_plugins/$file done for file in $(find %{_mu_build_dir}/%{_vpp_install_dir}/plugins -type f -name '*.api.json' -print ) do install -p -m 644 $file %{buildroot}/usr/share/vpp/api done # # remove RPATH from ELF binaries # %{_mu_build_dir}/scripts/remove-rpath %{buildroot} %post if [ $1 -eq 1 ] ; then sysctl --system fi %systemd_post vpp.service %preun %systemd_preun vpp.service %postun %systemd_postun if [ $1 -eq 0 ] ; then echo "Uninstalling, unbind user-mode PCI drivers" # Unbind user-mode PCI drivers removed= pci_dirs=`find /sys/bus/pci/drivers -type d -name igb_uio -o -name uio_pci_generic -o -name vfio-pci` for d in $pci_dirs; do for f in ${d}/*; do [ -e "${f}/config" ] || continue echo ${f##*/} > ${d}/unbind basename `dirname ${f}` | xargs echo -n "Removing driver"; echo " for PCI ID" `basename ${f}` removed=y done done if [ -n "${removed}" ]; then echo "There are changes in PCI drivers, rescaning" echo 1 > /sys/bus/pci/rescan else echo "There weren't PCI devices binded" fi else echo "Upgrading package, dont' unbind interfaces" fi %files %defattr(-,bin,bin) %{_unitdir}/vpp.service /usr/bin/vpp* /usr/bin/svm* /usr/bin/elftool %config(noreplace) /etc/sysctl.d/80-vpp.conf %config(noreplace) /etc/vpp/startup.conf /usr/share/vpp/api/* %files lib %defattr(-,bin,bin) %exclude %{_libdir}/vpp_plugins %exclude %{_libdir}/vpp_api_test_plugins %{_libdir}/* /usr/share/vpp/api/* /etc/bash_completion.d/vppctl_completion /usr/share/vpp/vppctl-cmd-list %files api-lua %defattr(644,root,root,644) /usr/share/doc/vpp/examples/lua %files api-java %defattr(644,root,root) /usr/share/java/* %files api-python %defattr(644,root,root) %{python2_sitelib}/vpp_papi* %files devel %defattr(-,bin,bin) /usr/bin/vppapigen /usr/bin/jvpp_gen.py %{_includedir}/* %{python2_sitelib}/jvppgen/* /usr/share/doc/vpp/examples/sample-plugin /usr/share/vpp %files plugins %defattr(-,bin,bin) /usr/lib/vpp_plugins/* /usr/lib/vpp_api_test_plugins/* /usr/share/vpp/api/*