Skip to content

Commit

Permalink
mk: ninja install
Browse files Browse the repository at this point in the history
  • Loading branch information
yoursunny committed Feb 28, 2020
1 parent 39ec796 commit 117be86
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 40 deletions.
12 changes: 5 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ install:
- |
: install Mbed Crypto
cd $HOME
curl -L https://github.com/ARMmbed/mbed-crypto/archive/mbedcrypto-2.0.0.tar.gz | tar -xz
curl -L https://github.com/ARMmbed/mbed-crypto/archive/mbedcrypto-3.1.0.tar.gz | tar -xz
mkdir mbedcrypto
cd mbedcrypto
cmake -G Ninja ../mbed-crypto-mbedcrypto-2.0.0 -DENABLE_PROGRAMS=0 -DENABLE_TESTING=0
cmake -G Ninja ../mbed-crypto-mbedcrypto-3.1.0 -DENABLE_PROGRAMS=0 -DENABLE_TESTING=0
ninja
sudo ninja install
- |
Expand All @@ -57,14 +57,12 @@ install:
script:
- cd $TRAVIS_BUILD_DIR && mk/update-list.sh
- meson build.coverage -Db_coverage=true -Dwerror=true
- meson build.sanitize -Db_sanitize=address,undefined
- meson build.optimized --buildtype debugoptimized
- LDFLAGS='-fuse-ld=lld -L/usr/local/lib' meson build.llvm --native-file mk/native-llvm.txt
- meson build.coverage -Db_coverage=true -Dwerror=true -Dunittest=enabled
- meson build.sanitize -Db_sanitize=address,undefined -Dunittest=enabled
- LDFLAGS='-fuse-ld=lld -L/usr/local/lib' meson build.llvm --native-file mk/native-llvm.txt --buildtype debugoptimized -Dunittest=enabled
- meson build.thumb --cross-file mk/cross-thumb.txt
- cd $TRAVIS_BUILD_DIR/build.coverage && ninja test
- cd $TRAVIS_BUILD_DIR/build.sanitize && ninja test
- cd $TRAVIS_BUILD_DIR/build.optimized && ninja test
- cd $TRAVIS_BUILD_DIR/build.llvm && ninja test
- cd $TRAVIS_BUILD_DIR/build.thumb && ninja
- cd $TRAVIS_BUILD_DIR
Expand Down
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ For Arduino, see [esp8266ndn](https://github.com/yoursunny/esp8266ndn) instructi

For Linux,

1. Copy `src/*` into `/usr/local/include`.
2. Have a look at `ndnph/port/*/port.hpp`, select an implementation of each feature, and put the appropriate `#define` lines in `NDNph-defines.hpp` file of your project.
3. Add `#include "NDNph-defines.hpp"` and `#include <NDNph.h>` in your project.
1. Install dependencies
* C++ compiler such as GCC, install Ubuntu package `build-essential`
* [Meson](https://mesonbuild.com/), install pip package `meson`
* [Ninja build system](https://ninja-build.org/), install Ubuntu package `ninja-build`
* [Mbed Crypto](https://github.com/ARMmbed/mbed-crypto), install from source
* [Boost](https://www.boost.org/) header-only libraries, install Ubuntu package `libboost-dev`
* [Google Test](https://github.com/google/googletest), install from source (only needed by unit tests)
* Note: all dependencies are optional, but extra porting work will be necessary
2. Create build directory: `meson build`
3. Enter build directory and execute build: `cd build && ninja`
4. Run unit test (optional): `ninja test`
5. Install headers to system: `sudo ninja install`
6. Add `#include <NDNph-config.h>` and `#include <NDNph.h>` in your project, and start coding.
1 change: 1 addition & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
option('unittest', type: 'feature')
31 changes: 15 additions & 16 deletions src/meson.build
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
conf = configuration_data()

boost = dependency('boost', required: false)
if boost.found()
add_project_arguments('-DNDNPH_PORT_QUEUE_BOOSTLF', language: 'cpp')
endif
conf.set('NDNPH_PORT_QUEUE_BOOSTLF', boost.found())

mbedcrypto = meson.get_compiler('cpp').find_library('mbedcrypto', required: false)
if mbedcrypto.found()
add_project_arguments('-DNDNPH_PORT_CRYPTO_MBEDTLS', language: 'cpp')
endif
conf.set('NDNPH_PORT_CRYPTO_MBEDTLS', mbedcrypto.found())

have_urandom = not meson.is_cross_build() and run_command('test', '-r', '/dev/urandom').returncode() == 0
if have_urandom
add_project_arguments('-DNDNPH_PORT_RANDOM_URANDOM', language: 'cpp')
endif
conf.set('NDNPH_PORT_RANDOM_URANDOM', have_urandom)

have_socket_h = not meson.is_cross_build() and meson.get_compiler('cpp').has_header('sys/socket.h')
if have_socket_h
add_project_arguments('-DNDNPH_PORT_TRANSPORT_SOCKET', language: 'cpp')
endif
conf.set('NDNPH_PORT_TRANSPORT_SOCKET', have_socket_h)

have_this_thread = meson.get_compiler('cpp').compiles('''
#include <chrono>
Expand All @@ -26,8 +20,13 @@ int main()
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
''')
if not have_this_thread
add_project_arguments('-DNDNPH_PORT_CHRONO_BUSY_SLEEP', language: 'cpp')
endif
conf.set('NDNPH_PORT_CHRONO_BUSY_SLEEP', not have_this_thread)

config_h = configure_file(output: 'NDNph-config.h', configuration: conf)
lib_dep = declare_dependency(
include_directories: include_directories('.'),
compile_args: ['-include', 'NDNph-config.h'],
dependencies: [boost, mbedcrypto])

lib_dep = declare_dependency(include_directories: ['.'], dependencies: [boost, mbedcrypto])
install_subdir('ndnph', install_dir: 'include')
install_headers('NDNph.h', config_h)
3 changes: 2 additions & 1 deletion tests/meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
if not meson.is_cross_build()
unittest_option = get_option('unittest')
if not unittest_option.disabled()
subdir('unit')
subdir('unittest')
endif
Expand Down
25 changes: 12 additions & 13 deletions tests/unittest/meson.build
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
gmock = dependency('gmock')
gtest = dependency('gtest', main: true)
assert(boost.found(), 'Boost headers are required to build unit tests')
assert(mbedcrypto.found(), 'libmbedcrypto is required to build unit tests')
assert(have_urandom, '/dev/urandom is required to build unit tests')
assert(have_socket_h, 'sys/socket.h is required to build unit tests')

unittest_exe = executable('unittest',
unittest_files,
dependencies: [lib_dep, gmock, gtest],
include_directories: ['..'],
)
test('unittest', unittest_exe)
gmock = dependency('gmock', required: false)
gtest = dependency('gtest', main: true, required: false)
if gmock.found() and gtest.found() and boost.found() and mbedcrypto.found() and have_urandom and have_socket_h
unittest_exe = executable('unittest',
unittest_files,
dependencies: [lib_dep, gmock, gtest],
include_directories: ['..'],
)
test('unittest', unittest_exe)
elif unittest_option.enabled()
error('unittest enabled but is missing dependency')
endif

0 comments on commit 117be86

Please sign in to comment.