Compare commits

...

5 commits

Author SHA1 Message Date
Bruno BELANYI 171ef10a6d abacus: fix include directories
All checks were successful
continuous-integration/drone/push Build is passing
This cleans up one of my major pain points with the Meson way of doing
things.

The Meson solution to have nice includes would have been to create an
`include/<name>` directory per library I create...
2021-09-01 19:43:02 +02:00
Bruno BELANYI eb9295cfcd abacus: remove meson build system 2021-09-01 19:37:00 +02:00
Bruno BELANYI 6c0950dbe1 nix: use cmake instead of meson
All checks were successful
continuous-integration/drone/push Build is passing
2021-09-01 19:35:54 +02:00
Bruno BELANYI 09c628be60 nix: set 'doCheck'
It ensures that the `checkInputs` are being made part of
`nativeBuildInputs`.
2021-09-01 19:35:07 +02:00
Bruno BELANYI 331089d101 abacus: add cmake-based build system 2021-09-01 19:27:55 +02:00
17 changed files with 82 additions and 125 deletions

18
CMakeLists.txt Normal file
View 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)

View file

@ -76,8 +76,8 @@
nativeBuildInputs = with pkgs; [ nativeBuildInputs = with pkgs; [
bison bison
cmake
flex flex
meson
ninja ninja
pkg-config pkg-config
]; ];
@ -86,6 +86,8 @@
gtest gtest
]; ];
doCheck = true;
meta = with pkgs.lib; { meta = with pkgs.lib; {
description = "A simple calculator using big numbers"; description = "A simple calculator using big numbers";
homepage = "https://gitea.belanyi.fr/ambroisie/abacus"; homepage = "https://gitea.belanyi.fr/ambroisie/abacus";

View file

@ -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
View 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)

View file

@ -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() { int main() {
abacus::parse::ParserDriver driver{}; abacus::parse::ParserDriver driver{};

View file

@ -0,0 +1,5 @@
add_library(bignum STATIC
bignum.cc
bignum.hh
)
target_link_libraries(bignum PRIVATE common_options)

View file

@ -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,
)

View file

@ -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
View 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}>
)

View file

@ -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,
)

View file

@ -4,7 +4,7 @@
#include "parser.hh" #include "parser.hh"
#include "bignum.hh" // FIXME: I would like `bignum/bignum.hh` path instead... #include "bignum/bignum.hh"
namespace abacus::parse { namespace abacus::parse {

View file

@ -36,7 +36,7 @@ namespace abacus::parse {
class ParserDriver; class ParserDriver;
} // namespace abacus::parse } // namespace abacus::parse
#include "bignum.hh" // FIXME: I would like `bignum/bignum.hh` path instead... #include "bignum/bignum.hh"
} }
%code provides { %code provides {

1
tests/CMakeLists.txt Normal file
View file

@ -0,0 +1 @@
add_subdirectory(unit)

View file

@ -1 +0,0 @@
subdir('unit')

16
tests/unit/CMakeLists.txt Normal file
View 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})

View file

@ -2,7 +2,7 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "bignum.hh" #include "bignum/bignum.hh"
using namespace abacus::bignum; using namespace abacus::bignum;

View file

@ -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