Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
Davide Pesavento | a7fead4 | 2019-01-19 21:18:17 -0500 | [diff] [blame] | 2 | |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 3 | import os |
Davide Pesavento | 4ffe19d | 2023-09-16 21:30:36 -0400 | [diff] [blame] | 4 | from waflib import Utils |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 5 | |
Davide Pesavento | d78e77e | 2022-12-31 17:01:32 -0500 | [diff] [blame] | 6 | VERSION = '0.1.0' |
Davide Pesavento | 55d9860 | 2019-10-15 22:40:05 -0400 | [diff] [blame] | 7 | APPNAME = 'ndncert' |
Davide Pesavento | 55d9860 | 2019-10-15 22:40:05 -0400 | [diff] [blame] | 8 | |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 9 | def options(opt): |
| 10 | opt.load(['compiler_cxx', 'gnu_dirs']) |
Davide Pesavento | 573a621 | 2022-07-09 21:56:41 -0400 | [diff] [blame] | 11 | opt.load(['default-compiler-flags', |
| 12 | 'coverage', 'sanitizers', |
Davide Pesavento | aae119a | 2019-11-09 18:30:03 -0500 | [diff] [blame] | 13 | 'boost', 'openssl', 'sqlite3'], |
Davide Pesavento | 0899478 | 2018-01-22 12:13:41 -0500 | [diff] [blame] | 14 | tooldir=['.waf-tools']) |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 15 | |
Davide Pesavento | aae119a | 2019-11-09 18:30:03 -0500 | [diff] [blame] | 16 | optgrp = opt.add_option_group('ndncert Options') |
| 17 | optgrp.add_option('--with-tests', action='store_true', default=False, |
| 18 | help='Build unit tests') |
Davide Pesavento | 4ffe19d | 2023-09-16 21:30:36 -0400 | [diff] [blame] | 19 | optgrp.add_option('--without-tools', action='store_false', default=True, dest='with_tools', |
| 20 | help='Do not build tools') |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 21 | |
| 22 | def configure(conf): |
| 23 | conf.load(['compiler_cxx', 'gnu_dirs', |
Davide Pesavento | 573a621 | 2022-07-09 21:56:41 -0400 | [diff] [blame] | 24 | 'default-compiler-flags', |
| 25 | 'boost', 'openssl', 'sqlite3']) |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 26 | |
Davide Pesavento | 55d9860 | 2019-10-15 22:40:05 -0400 | [diff] [blame] | 27 | conf.env.WITH_TESTS = conf.options.with_tests |
Davide Pesavento | 4ffe19d | 2023-09-16 21:30:36 -0400 | [diff] [blame] | 28 | conf.env.WITH_TOOLS = conf.options.with_tools |
Davide Pesavento | 55d9860 | 2019-10-15 22:40:05 -0400 | [diff] [blame] | 29 | |
Davide Pesavento | 573a621 | 2022-07-09 21:56:41 -0400 | [diff] [blame] | 30 | # Prefer pkgconf if it's installed, because it gives more correct results |
| 31 | # on Fedora/CentOS/RHEL/etc. See https://bugzilla.redhat.com/show_bug.cgi?id=1953348 |
| 32 | # Store the result in env.PKGCONFIG, which is the variable used inside check_cfg() |
| 33 | conf.find_program(['pkgconf', 'pkg-config'], var='PKGCONFIG') |
| 34 | |
Davide Pesavento | 6f1a2ab | 2022-03-17 03:57:21 -0400 | [diff] [blame] | 35 | pkg_config_path = os.environ.get('PKG_CONFIG_PATH', f'{conf.env.LIBDIR}/pkgconfig') |
Davide Pesavento | d78e77e | 2022-12-31 17:01:32 -0500 | [diff] [blame] | 36 | conf.check_cfg(package='libndn-cxx', args=['libndn-cxx >= 0.8.1', '--cflags', '--libs'], |
Davide Pesavento | 6f1a2ab | 2022-03-17 03:57:21 -0400 | [diff] [blame] | 37 | uselib_store='NDN_CXX', pkg_config_path=pkg_config_path) |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 38 | |
Davide Pesavento | 55d9860 | 2019-10-15 22:40:05 -0400 | [diff] [blame] | 39 | conf.check_sqlite3() |
Davide Pesavento | 5672d29 | 2021-11-19 18:19:25 -0500 | [diff] [blame] | 40 | conf.check_openssl(lib='crypto', atleast_version='1.1.1') |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 41 | |
Davide Pesavento | fd19485 | 2023-09-16 21:48:21 -0400 | [diff] [blame] | 42 | conf.check_boost(lib='filesystem', mt=True) |
Davide Pesavento | a3dbb94 | 2023-09-16 22:30:35 -0400 | [diff] [blame] | 43 | if conf.env.BOOST_VERSION_NUMBER < 107100: |
| 44 | conf.fatal('The minimum supported version of Boost is 1.71.0.\n' |
Davide Pesavento | a34d6de | 2021-11-18 22:16:04 -0500 | [diff] [blame] | 45 | 'Please upgrade your distribution or manually install a newer version of Boost.\n' |
| 46 | 'For more information, see https://redmine.named-data.net/projects/nfd/wiki/Boost') |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 47 | |
Davide Pesavento | fd19485 | 2023-09-16 21:48:21 -0400 | [diff] [blame] | 48 | if conf.env.WITH_TESTS: |
Davide Pesavento | 3e48184 | 2023-11-11 18:01:32 -0500 | [diff] [blame^] | 49 | conf.check_boost(lib='unit_test_framework', mt=True, uselib_store='BOOST_TESTS') |
Davide Pesavento | fd19485 | 2023-09-16 21:48:21 -0400 | [diff] [blame] | 50 | |
| 51 | if conf.env.WITH_TOOLS: |
| 52 | conf.check_boost(lib='program_options', mt=True, uselib_store='BOOST_TOOLS') |
| 53 | |
Davide Pesavento | 0899478 | 2018-01-22 12:13:41 -0500 | [diff] [blame] | 54 | conf.check_compiler_flags() |
| 55 | |
| 56 | # Loading "late" to prevent tests from being compiled with profiling flags |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 57 | conf.load('coverage') |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 58 | conf.load('sanitizers') |
Zhiyi Zhang | 65ba932 | 2017-01-19 14:15:03 -0800 | [diff] [blame] | 59 | |
Zhiyi Zhang | 7021a93 | 2017-03-17 10:26:51 -0700 | [diff] [blame] | 60 | # If there happens to be a static library, waf will put the corresponding -L flags |
| 61 | # before dynamic library flags. This can result in compilation failure when the |
| 62 | # system has a different version of the ndncert library installed. |
Davide Pesavento | 55d9860 | 2019-10-15 22:40:05 -0400 | [diff] [blame] | 63 | conf.env.prepend_value('STLIBPATH', ['.']) |
Zhiyi Zhang | 7021a93 | 2017-03-17 10:26:51 -0700 | [diff] [blame] | 64 | |
Zhiyi Zhang | 199508a | 2020-10-21 10:45:50 -0700 | [diff] [blame] | 65 | conf.define_cond('HAVE_TESTS', conf.env.WITH_TESTS) |
Davide Pesavento | 55d9860 | 2019-10-15 22:40:05 -0400 | [diff] [blame] | 66 | conf.define('SYSCONFDIR', conf.env.SYSCONFDIR) |
| 67 | # The config header will contain all defines that were added using conf.define() |
| 68 | # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES |
| 69 | # will not appear in the config header, but will instead be passed directly to the |
| 70 | # compiler on the command line. |
Zhiyi Zhang | 199508a | 2020-10-21 10:45:50 -0700 | [diff] [blame] | 71 | conf.write_config_header('src/detail/ndncert-config.hpp', define_prefix='NDNCERT_') |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 72 | |
| 73 | def build(bld): |
Davide Pesavento | fd19485 | 2023-09-16 21:48:21 -0400 | [diff] [blame] | 74 | bld.shlib( |
| 75 | target='ndn-cert', |
| 76 | name='libndn-cert', |
| 77 | vnum=VERSION, |
| 78 | cnum=VERSION, |
| 79 | source=bld.path.ant_glob('src/**/*.cpp'), |
| 80 | use='BOOST NDN_CXX OPENSSL SQLITE3', |
| 81 | includes='src', |
| 82 | export_includes='src') |
Davide Pesavento | 4ffe19d | 2023-09-16 21:30:36 -0400 | [diff] [blame] | 83 | |
| 84 | if bld.env.WITH_TESTS: |
| 85 | bld.recurse('tests') |
| 86 | |
| 87 | if bld.env.WITH_TOOLS: |
| 88 | bld.recurse('tools') |
| 89 | |
| 90 | # Install header files |
| 91 | srcdir = bld.path.find_dir('src') |
| 92 | bld.install_files('${INCLUDEDIR}/ndncert', |
| 93 | srcdir.ant_glob('**/*.hpp'), |
| 94 | cwd=srcdir, |
| 95 | relative_trick=True) |
| 96 | bld.install_files('${INCLUDEDIR}/ndncert/detail', 'src/detail/ndncert-config.hpp') |
| 97 | |
| 98 | # Install sample configs |
| 99 | bld.install_files('${SYSCONFDIR}/ndncert', |
| 100 | ['ca.conf.sample', |
| 101 | 'client.conf.sample', |
| 102 | 'ndncert-mail.conf.sample']) |
Davide Pesavento | a7fead4 | 2019-01-19 21:18:17 -0500 | [diff] [blame] | 103 | |
| 104 | bld(features='subst', |
| 105 | source='libndn-cert.pc.in', |
| 106 | target='libndn-cert.pc', |
Davide Pesavento | aae119a | 2019-11-09 18:30:03 -0500 | [diff] [blame] | 107 | install_path='${LIBDIR}/pkgconfig', |
| 108 | VERSION=VERSION) |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 109 | |
Davide Pesavento | a7fead4 | 2019-01-19 21:18:17 -0500 | [diff] [blame] | 110 | bld(features='subst', |
| 111 | name='ndncert-send-email-challenge', |
Zhiyi Zhang | 576aad1 | 2017-10-03 15:41:53 -0700 | [diff] [blame] | 112 | source='ndncert-send-email-challenge.py', |
Davide Pesavento | a7fead4 | 2019-01-19 21:18:17 -0500 | [diff] [blame] | 113 | target='bin/ndncert-send-email-challenge', |
| 114 | install_path='${BINDIR}', |
| 115 | chmod=Utils.O755) |
Zhiyi Zhang | 1dab2dc | 2020-10-17 15:39:22 -0700 | [diff] [blame] | 116 | |
Davide Pesavento | 725d3fc | 2021-11-19 23:37:03 -0500 | [diff] [blame] | 117 | if Utils.unversioned_sys_platform() == 'linux': |
| 118 | bld(features='subst', |
Davide Pesavento | 4ffe19d | 2023-09-16 21:30:36 -0400 | [diff] [blame] | 119 | name='systemd-units', |
Davide Pesavento | 725d3fc | 2021-11-19 23:37:03 -0500 | [diff] [blame] | 120 | source='systemd/ndncert-ca.service.in', |
| 121 | target='systemd/ndncert-ca.service') |
Davide Pesavento | c2fedec | 2023-09-19 16:30:30 -0400 | [diff] [blame] | 122 | |
| 123 | def dist(ctx): |
| 124 | ctx.algo = 'tar.xz' |
| 125 | |
| 126 | def distcheck(ctx): |
| 127 | ctx.algo = 'tar.xz' |