blob: 7eb451f76fe3fd3a9919ffb812ad5ebef33341c9 [file] [log] [blame]
Zhiyi Zhang8617a792017-01-17 16:45:56 -08001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
Davide Pesaventoa7fead42019-01-19 21:18:17 -05002
Zhiyi Zhang8617a792017-01-17 16:45:56 -08003import os
Davide Pesavento4ffe19d2023-09-16 21:30:36 -04004from waflib import Utils
Zhiyi Zhang8617a792017-01-17 16:45:56 -08005
Davide Pesaventod78e77e2022-12-31 17:01:32 -05006VERSION = '0.1.0'
Davide Pesavento55d98602019-10-15 22:40:05 -04007APPNAME = 'ndncert'
Davide Pesavento55d98602019-10-15 22:40:05 -04008
Zhiyi Zhang8617a792017-01-17 16:45:56 -08009def options(opt):
10 opt.load(['compiler_cxx', 'gnu_dirs'])
Davide Pesavento573a6212022-07-09 21:56:41 -040011 opt.load(['default-compiler-flags',
12 'coverage', 'sanitizers',
Davide Pesaventoaae119a2019-11-09 18:30:03 -050013 'boost', 'openssl', 'sqlite3'],
Davide Pesavento08994782018-01-22 12:13:41 -050014 tooldir=['.waf-tools'])
Zhiyi Zhang8617a792017-01-17 16:45:56 -080015
Davide Pesaventoaae119a2019-11-09 18:30:03 -050016 optgrp = opt.add_option_group('ndncert Options')
17 optgrp.add_option('--with-tests', action='store_true', default=False,
18 help='Build unit tests')
Davide Pesavento4ffe19d2023-09-16 21:30:36 -040019 optgrp.add_option('--without-tools', action='store_false', default=True, dest='with_tools',
20 help='Do not build tools')
Zhiyi Zhang8617a792017-01-17 16:45:56 -080021
22def configure(conf):
23 conf.load(['compiler_cxx', 'gnu_dirs',
Davide Pesavento573a6212022-07-09 21:56:41 -040024 'default-compiler-flags',
25 'boost', 'openssl', 'sqlite3'])
Zhiyi Zhang8617a792017-01-17 16:45:56 -080026
Davide Pesavento55d98602019-10-15 22:40:05 -040027 conf.env.WITH_TESTS = conf.options.with_tests
Davide Pesavento4ffe19d2023-09-16 21:30:36 -040028 conf.env.WITH_TOOLS = conf.options.with_tools
Davide Pesavento55d98602019-10-15 22:40:05 -040029
Davide Pesavento573a6212022-07-09 21:56:41 -040030 # 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 Pesavento6f1a2ab2022-03-17 03:57:21 -040035 pkg_config_path = os.environ.get('PKG_CONFIG_PATH', f'{conf.env.LIBDIR}/pkgconfig')
Davide Pesaventod78e77e2022-12-31 17:01:32 -050036 conf.check_cfg(package='libndn-cxx', args=['libndn-cxx >= 0.8.1', '--cflags', '--libs'],
Davide Pesavento6f1a2ab2022-03-17 03:57:21 -040037 uselib_store='NDN_CXX', pkg_config_path=pkg_config_path)
Zhiyi Zhang8617a792017-01-17 16:45:56 -080038
Davide Pesavento55d98602019-10-15 22:40:05 -040039 conf.check_sqlite3()
Davide Pesavento5672d292021-11-19 18:19:25 -050040 conf.check_openssl(lib='crypto', atleast_version='1.1.1')
Zhiyi Zhang8617a792017-01-17 16:45:56 -080041
Davide Pesavento55d98602019-10-15 22:40:05 -040042 boost_libs = ['system', 'program_options', 'filesystem']
43 if conf.env.WITH_TESTS:
44 boost_libs.append('unit_test_framework')
Zhiyi Zhang8617a792017-01-17 16:45:56 -080045
Davide Pesavento55d98602019-10-15 22:40:05 -040046 conf.check_boost(lib=boost_libs, mt=True)
Davide Pesaventoa34d6de2021-11-18 22:16:04 -050047 if conf.env.BOOST_VERSION_NUMBER < 106501:
48 conf.fatal('The minimum supported version of Boost is 1.65.1.\n'
49 'Please upgrade your distribution or manually install a newer version of Boost.\n'
50 'For more information, see https://redmine.named-data.net/projects/nfd/wiki/Boost')
Zhiyi Zhang8617a792017-01-17 16:45:56 -080051
Davide Pesavento08994782018-01-22 12:13:41 -050052 conf.check_compiler_flags()
53
54 # Loading "late" to prevent tests from being compiled with profiling flags
Zhiyi Zhang8617a792017-01-17 16:45:56 -080055 conf.load('coverage')
Zhiyi Zhang8617a792017-01-17 16:45:56 -080056 conf.load('sanitizers')
Zhiyi Zhang65ba9322017-01-19 14:15:03 -080057
Zhiyi Zhang7021a932017-03-17 10:26:51 -070058 # If there happens to be a static library, waf will put the corresponding -L flags
59 # before dynamic library flags. This can result in compilation failure when the
60 # system has a different version of the ndncert library installed.
Davide Pesavento55d98602019-10-15 22:40:05 -040061 conf.env.prepend_value('STLIBPATH', ['.'])
Zhiyi Zhang7021a932017-03-17 10:26:51 -070062
Zhiyi Zhang199508a2020-10-21 10:45:50 -070063 conf.define_cond('HAVE_TESTS', conf.env.WITH_TESTS)
Davide Pesavento55d98602019-10-15 22:40:05 -040064 conf.define('SYSCONFDIR', conf.env.SYSCONFDIR)
65 # The config header will contain all defines that were added using conf.define()
66 # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES
67 # will not appear in the config header, but will instead be passed directly to the
68 # compiler on the command line.
Zhiyi Zhang199508a2020-10-21 10:45:50 -070069 conf.write_config_header('src/detail/ndncert-config.hpp', define_prefix='NDNCERT_')
Zhiyi Zhang8617a792017-01-17 16:45:56 -080070
71def build(bld):
Davide Pesaventoa7fead42019-01-19 21:18:17 -050072 bld.shlib(target='ndn-cert',
Davide Pesavento4ffe19d2023-09-16 21:30:36 -040073 name='libndn-cert',
Davide Pesaventoa7fead42019-01-19 21:18:17 -050074 vnum=VERSION,
75 cnum=VERSION,
Davide Pesaventoaae119a2019-11-09 18:30:03 -050076 source=bld.path.ant_glob('src/**/*.cpp'),
Davide Pesavento55d98602019-10-15 22:40:05 -040077 use='NDN_CXX BOOST OPENSSL SQLITE3',
Davide Pesaventoa7fead42019-01-19 21:18:17 -050078 includes='src',
Davide Pesavento4ffe19d2023-09-16 21:30:36 -040079 export_includes='src')
80
81 if bld.env.WITH_TESTS:
82 bld.recurse('tests')
83
84 if bld.env.WITH_TOOLS:
85 bld.recurse('tools')
86
87 # Install header files
88 srcdir = bld.path.find_dir('src')
89 bld.install_files('${INCLUDEDIR}/ndncert',
90 srcdir.ant_glob('**/*.hpp'),
91 cwd=srcdir,
92 relative_trick=True)
93 bld.install_files('${INCLUDEDIR}/ndncert/detail', 'src/detail/ndncert-config.hpp')
94
95 # Install sample configs
96 bld.install_files('${SYSCONFDIR}/ndncert',
97 ['ca.conf.sample',
98 'client.conf.sample',
99 'ndncert-mail.conf.sample'])
Davide Pesaventoa7fead42019-01-19 21:18:17 -0500100
101 bld(features='subst',
102 source='libndn-cert.pc.in',
103 target='libndn-cert.pc',
Davide Pesaventoaae119a2019-11-09 18:30:03 -0500104 install_path='${LIBDIR}/pkgconfig',
105 VERSION=VERSION)
Zhiyi Zhang8617a792017-01-17 16:45:56 -0800106
Davide Pesaventoa7fead42019-01-19 21:18:17 -0500107 bld(features='subst',
108 name='ndncert-send-email-challenge',
Zhiyi Zhang576aad12017-10-03 15:41:53 -0700109 source='ndncert-send-email-challenge.py',
Davide Pesaventoa7fead42019-01-19 21:18:17 -0500110 target='bin/ndncert-send-email-challenge',
111 install_path='${BINDIR}',
112 chmod=Utils.O755)
Zhiyi Zhang1dab2dc2020-10-17 15:39:22 -0700113
Davide Pesavento725d3fc2021-11-19 23:37:03 -0500114 if Utils.unversioned_sys_platform() == 'linux':
115 bld(features='subst',
Davide Pesavento4ffe19d2023-09-16 21:30:36 -0400116 name='systemd-units',
Davide Pesavento725d3fc2021-11-19 23:37:03 -0500117 source='systemd/ndncert-ca.service.in',
118 target='systemd/ndncert-ca.service')