diff options
-rw-r--r-- | .nix/derivation.nix | 2 | ||||
-rw-r--r-- | SConstruct | 66 | ||||
-rw-r--r-- | c++/SConscript | 37 | ||||
-rw-r--r-- | c++/examples/cavity_2d.cpp | 9 | ||||
-rw-r--r-- | c++/lattice.h | 19 | ||||
-rw-r--r-- | default.nix | 14 |
6 files changed, 145 insertions, 2 deletions
diff --git a/.nix/derivation.nix b/.nix/derivation.nix index 4c28c0b..ece180e 100644 --- a/.nix/derivation.nix +++ b/.nix/derivation.nix @@ -2,6 +2,7 @@ , stdenvNoCC , scons , clang +, clang-tools , forstio , kel-unit }: @@ -14,6 +15,7 @@ stdenvNoCC.mkDerivation { nativeBuildInputs = [ scons clang + clang-tools ]; buildInputs = [ diff --git a/SConstruct b/SConstruct new file mode 100644 index 0000000..b5690d8 --- /dev/null +++ b/SConstruct @@ -0,0 +1,66 @@ +#!/usr/bin/env python3 + +import sys +import os +import os.path +import glob +import re + + +if sys.version_info < (3,): + def isbasestring(s): + return isinstance(s,basestring) +else: + def isbasestring(s): + return isinstance(s, (str,bytes)) + +def add_kel_source_files(self, sources, filetype, lib_env=None, shared=False, target_post=""): + + if isbasestring(filetype): + dir_path = self.Dir('.').abspath + filetype = sorted(glob.glob(dir_path+"/"+filetype)) + + for path in filetype: + target_name = re.sub( r'(.*?)(\.cpp|\.c\+\+)', r'\1' + target_post, path ) + if shared: + target_name+='.os' + sources.append( self.SharedObject( target=target_name, source=path ) ) + else: + target_name+='.o' + sources.append( self.StaticObject( target=target_name, source=path ) ) + pass + +def isAbsolutePath(key, dirname, env): + assert os.path.isabs(dirname), "%r must have absolute path syntax" % (key,) + +env_vars = Variables( + args=ARGUMENTS +) + +env_vars.Add('prefix', + help='Installation target location of build results and headers', + default='/usr/local/', + validator=isAbsolutePath +) + +env=Environment(ENV=os.environ, variables=env_vars, CPPPATH=[], + CPPDEFINES=['SAW_UNIX'], + CXXFLAGS=['-std=c++20','-g','-Wall','-Wextra'], + LIBS=['forstio-core','forstio-codec']) +env.__class__.add_source_files = add_kel_source_files +env.Tool('compilation_db'); +env.cdb = env.CompilationDatabase('compile_commands.json'); + +env.objects = []; +env.sources = []; +env.headers = []; +env.targets = []; + +Export('env') +SConscript('c++/SConscript') + +env.Alias('cdb', env.cdb); +env.Alias('all', [env.targets]); +env.Default('all'); + +env.Alias('install', '$prefix') diff --git a/c++/SConscript b/c++/SConscript new file mode 100644 index 0000000..d696204 --- /dev/null +++ b/c++/SConscript @@ -0,0 +1,37 @@ +#!/bin/false + +import os +import os.path +import glob + + +Import('env') + +dir_path = Dir('.').abspath + +# Environment for base library +core_env = env.Clone(); + +core_env.sources = sorted(glob.glob(dir_path + "/*.cpp")); +core_env.headers = sorted(glob.glob(dir_path + "/*.h")); + +env.sources += core_env.sources; +env.headers += core_env.headers; + + +## Shared lib +objects = [] +core_env.add_source_files(objects, core_env.sources, shared=False); + +# Cavity2D +core_env.cavity_2d_source = sorted(glob.glob(dir_path + "/examples/cavity_2d.cpp")); +env.sources += core_env.cavity_2d_source; +core_env.cavity_2d = core_env.Program('#bin/cavity_2d', [core_env.cavity_2d_source, core_env.objects]); + +# Set Alias +env.Alias('examples', [core_env.cavity_2d]); + +env.targets += ['examples']; + +# Install +env.Install('$prefix/bin', ['examples']); diff --git a/c++/examples/cavity_2d.cpp b/c++/examples/cavity_2d.cpp new file mode 100644 index 0000000..bb21e96 --- /dev/null +++ b/c++/examples/cavity_2d.cpp @@ -0,0 +1,9 @@ +#include "../lattice.h" + +#include <forstio/codec/data.h> + +int main(){ + saw::data<schema::Lattice2D<saw::schema::Float32>, saw::encode::Native> lattice{512, 512}; + + return 0; +} diff --git a/c++/lattice.h b/c++/lattice.h new file mode 100644 index 0000000..62752e8 --- /dev/null +++ b/c++/lattice.h @@ -0,0 +1,19 @@ +#pragma once + +#include <forstio/codec/schema.h> + +namespace kel { +namespace lbm { +namespace schema { +template<typename T, size_t D> +using Lattice = Array<T,D>; + +template<typename T> +using Lattice2D = Lattice<T,2>; + +template<typename T> +using Lattice3D = Lattice<T,3>; +} +} +} +} diff --git a/default.nix b/default.nix index f93b364..0ea5cdf 100644 --- a/default.nix +++ b/default.nix @@ -1,18 +1,28 @@ { pkgs ? import <nixpkgs> {} +, clang ? pkgs.clang_15 +, clang-tools ? pkgs.clang-tools_15 }: let forstio = (import ((builtins.fetchGit { url = "git@git.keldu.de:forstio/forstio"; ref = "dev"; - }).outPath + "/default.nix"){}).forstio; + }).outPath + "/default.nix"){ + inherit clang; + inherit clang-tools; + }).forstio; kel-unit = (import ((builtins.fetchGit { url = "git@git.keldu.de:libs/unit"; ref = "dev"; - }).outPath + "/default.nix"){}); + }).outPath + "/default.nix"){ + inherit clang; + inherit clang-tools; + }); in pkgs.callPackage ./.nix/derivation.nix { inherit forstio; inherit kel-unit; + inherit clang; + inherit clang-tools; } |