Compare commits
5 commits
549c1f0574
...
171ef10a6d
Author | SHA1 | Date | |
---|---|---|---|
Bruno BELANYI | 171ef10a6d | ||
Bruno BELANYI | eb9295cfcd | ||
Bruno BELANYI | 6c0950dbe1 | ||
Bruno BELANYI | 09c628be60 | ||
Bruno BELANYI | 331089d101 |
18
CMakeLists.txt
Normal file
18
CMakeLists.txt
Normal file
|
@ -0,0 +1,18 @@
|
|||
cmake_minimum_required(VERSION 3.10)
|
||||
project(abacus VERSION 0.0.0 LANGUAGES CXX)
|
||||
enable_testing()
|
||||
|
||||
add_library(common_options INTERFACE)
|
||||
target_compile_features(common_options INTERFACE
|
||||
cxx_std_17
|
||||
)
|
||||
target_compile_options(common_options INTERFACE
|
||||
-Wall
|
||||
-Wextra
|
||||
)
|
||||
target_include_directories(common_options INTERFACE
|
||||
src
|
||||
)
|
||||
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(tests)
|
|
@ -76,8 +76,8 @@
|
|||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
bison
|
||||
cmake
|
||||
flex
|
||||
meson
|
||||
ninja
|
||||
pkg-config
|
||||
];
|
||||
|
@ -86,6 +86,8 @@
|
|||
gtest
|
||||
];
|
||||
|
||||
doCheck = true;
|
||||
|
||||
meta = with pkgs.lib; {
|
||||
description = "A simple calculator using big numbers";
|
||||
homepage = "https://gitea.belanyi.fr/ambroisie/abacus";
|
||||
|
|
13
meson.build
13
meson.build
|
@ -1,13 +0,0 @@
|
|||
project(
|
||||
'abacus',
|
||||
'cpp',
|
||||
version: '0.0.0',
|
||||
license: 'MIT',
|
||||
default_options: [
|
||||
'warning_level=3',
|
||||
'cpp_std=c++17',
|
||||
],
|
||||
)
|
||||
|
||||
subdir('src')
|
||||
subdir('tests')
|
12
src/CMakeLists.txt
Normal file
12
src/CMakeLists.txt
Normal file
|
@ -0,0 +1,12 @@
|
|||
add_executable(abacus abacus.cc)
|
||||
target_link_libraries(abacus PRIVATE common_options)
|
||||
|
||||
add_subdirectory(bignum)
|
||||
add_subdirectory(parse)
|
||||
|
||||
target_link_libraries(abacus PRIVATE
|
||||
bignum
|
||||
parse
|
||||
)
|
||||
|
||||
install(TARGETS abacus)
|
|
@ -1,4 +1,4 @@
|
|||
#include "parser-driver.hh" // FIXME: I would like `parse/parser-driver.hh` path instead...
|
||||
#include "parse/parser-driver.hh"
|
||||
|
||||
int main() {
|
||||
abacus::parse::ParserDriver driver{};
|
||||
|
|
5
src/bignum/CMakeLists.txt
Normal file
5
src/bignum/CMakeLists.txt
Normal file
|
@ -0,0 +1,5 @@
|
|||
add_library(bignum STATIC
|
||||
bignum.cc
|
||||
bignum.hh
|
||||
)
|
||||
target_link_libraries(bignum PRIVATE common_options)
|
|
@ -1,16 +0,0 @@
|
|||
bignum_sources = files(
|
||||
'bignum.cc',
|
||||
'bignum.hh',
|
||||
)
|
||||
|
||||
bignum_inc = include_directories('.')
|
||||
|
||||
bignum_lib = static_library(
|
||||
'bignum',
|
||||
sources: bignum_sources,
|
||||
)
|
||||
|
||||
bignum = declare_dependency(
|
||||
link_with: bignum_lib,
|
||||
include_directories: bignum_inc,
|
||||
)
|
|
@ -1,16 +0,0 @@
|
|||
abacus_sources = files(
|
||||
'abacus.cc',
|
||||
)
|
||||
|
||||
subdir('bignum')
|
||||
subdir('parse')
|
||||
|
||||
abacus = executable(
|
||||
'abacus',
|
||||
sources: abacus_sources,
|
||||
dependencies: [
|
||||
bignum,
|
||||
parse,
|
||||
],
|
||||
install: true,
|
||||
)
|
23
src/parse/CMakeLists.txt
Normal file
23
src/parse/CMakeLists.txt
Normal file
|
@ -0,0 +1,23 @@
|
|||
find_package(BISON REQUIRED)
|
||||
find_package(FLEX REQUIRED)
|
||||
|
||||
bison_target(parser_sources parser.yy ${CMAKE_CURRENT_BINARY_DIR}/parser.cc DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/parser.hh)
|
||||
flex_target(scanner_sources scanner.ll ${CMAKE_CURRENT_BINARY_DIR}/scanner.cc)
|
||||
add_flex_bison_dependency(scanner_sources parser_sources)
|
||||
|
||||
add_library(parse STATIC
|
||||
parser-driver.cc
|
||||
parser-driver.hh
|
||||
${BISON_parser_sources_OUTPUTS}
|
||||
${FLEX_scanner_sources_OUTPUTS}
|
||||
)
|
||||
target_link_libraries(parse PRIVATE common_options)
|
||||
|
||||
target_link_libraries(parse PRIVATE
|
||||
bignum
|
||||
)
|
||||
|
||||
target_include_directories(parse PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||
)
|
|
@ -1,48 +0,0 @@
|
|||
flex_binary = find_program('flex', required: true)
|
||||
lexer_sources = custom_target(
|
||||
'lexer_sources',
|
||||
input: 'scanner.ll',
|
||||
output: 'scanner.cc',
|
||||
command: [
|
||||
flex_binary,
|
||||
'-o',
|
||||
'@OUTPUT@',
|
||||
'@INPUT@',
|
||||
],
|
||||
)
|
||||
|
||||
bison_binary = find_program('bison', required: true)
|
||||
parser_sources = custom_target(
|
||||
'parser_sources',
|
||||
input: 'parser.yy',
|
||||
output: [
|
||||
'parser.cc',
|
||||
'parser.hh',
|
||||
],
|
||||
command: [
|
||||
bison_binary,
|
||||
'@INPUT@',
|
||||
'--output=@OUTPUT0@',
|
||||
'--defines=@OUTPUT1@',
|
||||
'--graph',
|
||||
# FIXME: html output in bison 3.7.90
|
||||
],
|
||||
)
|
||||
|
||||
parse_inc = include_directories('.')
|
||||
|
||||
parse_lib = static_library(
|
||||
'parser',
|
||||
'parser-driver.cc',
|
||||
'parser-driver.hh',
|
||||
lexer_sources,
|
||||
parser_sources,
|
||||
dependencies: [
|
||||
bignum,
|
||||
],
|
||||
)
|
||||
|
||||
parse = declare_dependency(
|
||||
link_with: parse_lib,
|
||||
include_directories: parse_inc,
|
||||
)
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "parser.hh"
|
||||
|
||||
#include "bignum.hh" // FIXME: I would like `bignum/bignum.hh` path instead...
|
||||
#include "bignum/bignum.hh"
|
||||
|
||||
namespace abacus::parse {
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace abacus::parse {
|
|||
class ParserDriver;
|
||||
} // namespace abacus::parse
|
||||
|
||||
#include "bignum.hh" // FIXME: I would like `bignum/bignum.hh` path instead...
|
||||
#include "bignum/bignum.hh"
|
||||
}
|
||||
|
||||
%code provides {
|
||||
|
|
1
tests/CMakeLists.txt
Normal file
1
tests/CMakeLists.txt
Normal file
|
@ -0,0 +1 @@
|
|||
add_subdirectory(unit)
|
|
@ -1 +0,0 @@
|
|||
subdir('unit')
|
16
tests/unit/CMakeLists.txt
Normal file
16
tests/unit/CMakeLists.txt
Normal file
|
@ -0,0 +1,16 @@
|
|||
find_package(GTest)
|
||||
|
||||
if (${GTest_FOUND})
|
||||
include(GoogleTest)
|
||||
|
||||
add_executable(bignum_test bignum.cc)
|
||||
target_link_libraries(bignum_test PRIVATE common_options)
|
||||
|
||||
target_link_libraries(bignum_test PRIVATE
|
||||
bignum
|
||||
GTest::gtest
|
||||
GTest::gtest_main
|
||||
)
|
||||
|
||||
gtest_discover_tests(bignum_test)
|
||||
endif (${GTest_FOUND})
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "bignum.hh"
|
||||
#include "bignum/bignum.hh"
|
||||
|
||||
using namespace abacus::bignum;
|
||||
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
gtest = dependency(
|
||||
'gtest',
|
||||
main: true,
|
||||
required: false,
|
||||
)
|
||||
|
||||
if gtest.found()
|
||||
unit_test_sources = files(
|
||||
'bignum.cc',
|
||||
)
|
||||
|
||||
unit_tests = executable(
|
||||
'unit_tests',
|
||||
sources: unit_test_sources,
|
||||
dependencies: [
|
||||
bignum,
|
||||
gtest,
|
||||
],
|
||||
)
|
||||
|
||||
test(
|
||||
'unit tests',
|
||||
unit_tests,
|
||||
protocol: 'gtest',
|
||||
)
|
||||
endif
|
Loading…
Reference in a new issue