CMake buildsystem

This commit is contained in:
Gabriel Ferreira
2021-11-10 22:28:44 -03:00
committed by Tom Henderson
parent a4b86694f8
commit 9c876c7f5a
135 changed files with 8925 additions and 68 deletions

View File

@@ -7,47 +7,44 @@ import shutil
from pathlib import Path
WSCRIPT_TEMPLATE = '''# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
CMAKELISTS_TEMPLATE = '''\
check_include_file_cxx(stdint.h HAVE_STDINT_H)
if(HAVE_STDINT_H)
add_definitions(-DHAVE_STDINT_H)
endif()
# def options(opt):
# pass
set(name {MODULE})
# def configure(conf):
# conf.check_nonfatal(header_name='stdint.h', define_name='HAVE_STDINT_H')
set(source_files
model/{MODULE}.cc
helper/{MODULE}-helper.cc
)
set(header_files
model/{MODULE}.h
helper/{MODULE}-helper.h
)
def build(bld):
module = bld.create_ns3_module({MODULE!r}, ['core'])
module.source = [
'model/{MODULE}.cc',
'helper/{MODULE}-helper.cc',
]
set(libraries_to_link
${{libcore}}
)
module_test = bld.create_ns3_module_test_library('{MODULE}')
module_test.source = [
'test/{MODULE}-test-suite.cc',
]
# Tests encapsulating example programs should be listed here
if (bld.env['ENABLE_EXAMPLES']):
module_test.source.extend([
# 'test/{MODULE}-examples-test-suite.cc',
])
if(${{NS3_EXAMPLES}})
set(examples_as_tests_sources
#test/{MODULE}-examples-test-suite.cc
)
endif()
headers = bld(features='ns3header')
headers.module = {MODULE!r}
headers.source = [
'model/{MODULE}.h',
'helper/{MODULE}-helper.h',
]
if bld.env.ENABLE_EXAMPLES:
bld.recurse('examples')
# bld.ns3_python_bindings()
set(test_sources
test/{MODULE}-test-suite.cc
${{examples_as_tests_sources}}
)
{BUILD_LIB_MACRO}("${{name}}" "${{source_files}}" "${{header_files}}" "${{libraries_to_link}}" "${{test_sources}}")
'''
MODEL_CC_TEMPLATE = '''/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
#include "{MODULE}.h"
@@ -111,11 +108,12 @@ namespace ns3 {{
'''
EXAMPLES_WSCRIPT_TEMPLATE = '''# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
def build(bld):
obj = bld.create_ns3_program('{MODULE}-example', [{MODULE!r}])
obj.source = '{MODULE}-example.cc'
EXAMPLES_CMAKELISTS_TEMPLATE = '''\
set(name {MODULE}-example)
set(source_files ${{name}}.cc)
set(header_files)
set(libraries_to_link ${{lib{MODULE}}})
{BUILD_EXAMPLE_MACRO}("${{name}}" "${{source_files}}" "${{header_files}}" "${{libraries_to_link}}")
'''
@@ -326,12 +324,15 @@ def create_file(path, template, **kwargs):
with artifact_path.open("wt") as f:
f.write(template.format(**kwargs))
def make_wscript(moduledir, modname):
path = Path(moduledir, 'wscript')
create_file(path, WSCRIPT_TEMPLATE, MODULE=modname)
def make_cmakelists(moduledir, modname):
path = Path(moduledir, 'CMakeLists.txt')
macro = "build_lib" if "contrib" not in str(path) else "build_contrib_lib"
create_file(path, CMAKELISTS_TEMPLATE, MODULE=modname, BUILD_LIB_MACRO=macro)
return True
def make_model(moduledir, modname):
modelpath = Path(moduledir, "model")
modelpath.mkdir(parents=True)
@@ -379,8 +380,9 @@ def make_examples(moduledir, modname):
examplespath = Path(moduledir, "examples")
examplespath.mkdir(parents=True)
wscriptpath = Path(examplespath, 'wscript')
create_file(wscriptpath, EXAMPLES_WSCRIPT_TEMPLATE, MODULE=modname)
cmakelistspath = Path(examplespath, 'CMakeLists.txt')
macro = "build_lib_example" if "contrib" not in str(moduledir) else "build_contrib_example"
create_file(cmakelistspath, EXAMPLES_CMAKELISTS_TEMPLATE, MODULE=modname, BUILD_EXAMPLE_MACRO=macro)
examplesfile_path = examplespath.joinpath(modname+'-example').with_suffix('.cc')
create_file(examplesfile_path, EXAMPLE_CC_TEMPLATE, MODULE=modname)
@@ -398,11 +400,11 @@ def make_doc(moduledir, modname):
file_name = '{}.rst'.format(modname)
file_path = Path(docpath, file_name)
create_file(file_path, DOC_RST_TEMPLATE, MODULE=modname,
MODULE_DIR=mod_relpath)
create_file(file_path, DOC_RST_TEMPLATE, MODULE=modname, MODULE_DIR=mod_relpath)
return True
def make_module(modpath, modname):
modulepath = Path(modpath, modname)
@@ -412,7 +414,7 @@ def make_module(modpath, modname):
print("Creating module {}".format(modulepath))
functions = (make_wscript, make_model, make_test,
functions = (make_cmakelists, make_model, make_test,
make_helper, make_examples, make_doc)
try:
@@ -443,12 +445,12 @@ to integrate them into the ns-3 build system.
The following directory structure is generated under the contrib directory:
<modname>
|-- wscript
|-- CMakeLists.txt
|-- doc
|-- <modname>.rst
|-- examples
|-- <modname>-example.cc
|-- wscript
|-- CMakeLists.txt
|-- helper
|-- <modname>-helper.cc
|-- <modname>-helper.h