From 331089d10158553e4d056624d311e4fc9914f86e Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 1 Sep 2021 19:00:51 +0200 Subject: [PATCH 1/5] abacus: add cmake-based build system --- CMakeLists.txt | 15 +++++++++++++++ src/CMakeLists.txt | 12 ++++++++++++ src/bignum/CMakeLists.txt | 9 +++++++++ src/parse/CMakeLists.txt | 23 +++++++++++++++++++++++ tests/CMakeLists.txt | 1 + tests/unit/CMakeLists.txt | 16 ++++++++++++++++ 6 files changed, 76 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 src/CMakeLists.txt create mode 100644 src/bignum/CMakeLists.txt create mode 100644 src/parse/CMakeLists.txt create mode 100644 tests/CMakeLists.txt create mode 100644 tests/unit/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..4ef9a7b --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,15 @@ +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 +) + +add_subdirectory(src) +add_subdirectory(tests) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..531ca47 --- /dev/null +++ b/src/CMakeLists.txt @@ -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) diff --git a/src/bignum/CMakeLists.txt b/src/bignum/CMakeLists.txt new file mode 100644 index 0000000..b2434b7 --- /dev/null +++ b/src/bignum/CMakeLists.txt @@ -0,0 +1,9 @@ +add_library(bignum STATIC + bignum.cc + bignum.hh +) +target_link_libraries(bignum PRIVATE common_options) + +target_include_directories(bignum PUBLIC + $ +) diff --git a/src/parse/CMakeLists.txt b/src/parse/CMakeLists.txt new file mode 100644 index 0000000..3c87a92 --- /dev/null +++ b/src/parse/CMakeLists.txt @@ -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 + $ + $ +) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..269aea0 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(unit) diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt new file mode 100644 index 0000000..bdf51ae --- /dev/null +++ b/tests/unit/CMakeLists.txt @@ -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}) From 09c628be6055a97edee8dd94458e712170828151 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 1 Sep 2021 19:34:33 +0200 Subject: [PATCH 2/5] nix: set 'doCheck' It ensures that the `checkInputs` are being made part of `nativeBuildInputs`. --- flake.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flake.nix b/flake.nix index 56d4ecf..5173318 100644 --- a/flake.nix +++ b/flake.nix @@ -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"; From 6c0950dbe15af558c2ba6fe2ad47f26d5dd44847 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 1 Sep 2021 19:35:54 +0200 Subject: [PATCH 3/5] nix: use cmake instead of meson --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 5173318..cdf39b2 100644 --- a/flake.nix +++ b/flake.nix @@ -76,8 +76,8 @@ nativeBuildInputs = with pkgs; [ bison + cmake flex - meson ninja pkg-config ]; From eb9295cfcdf89ade8b65f5fc9afc695ce30b7f68 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 1 Sep 2021 19:37:00 +0200 Subject: [PATCH 4/5] abacus: remove meson build system --- meson.build | 13 ------------ src/bignum/meson.build | 16 -------------- src/meson.build | 16 -------------- src/parse/meson.build | 48 ------------------------------------------ tests/meson.build | 1 - tests/unit/meson.build | 26 ----------------------- 6 files changed, 120 deletions(-) delete mode 100644 meson.build delete mode 100644 src/bignum/meson.build delete mode 100644 src/meson.build delete mode 100644 src/parse/meson.build delete mode 100644 tests/meson.build delete mode 100644 tests/unit/meson.build diff --git a/meson.build b/meson.build deleted file mode 100644 index 4910f6a..0000000 --- a/meson.build +++ /dev/null @@ -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') diff --git a/src/bignum/meson.build b/src/bignum/meson.build deleted file mode 100644 index af1e4e5..0000000 --- a/src/bignum/meson.build +++ /dev/null @@ -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, -) diff --git a/src/meson.build b/src/meson.build deleted file mode 100644 index a6c5cb2..0000000 --- a/src/meson.build +++ /dev/null @@ -1,16 +0,0 @@ -abacus_sources = files( - 'abacus.cc', -) - -subdir('bignum') -subdir('parse') - -abacus = executable( - 'abacus', - sources: abacus_sources, - dependencies: [ - bignum, - parse, - ], - install: true, -) diff --git a/src/parse/meson.build b/src/parse/meson.build deleted file mode 100644 index 1a3bdcb..0000000 --- a/src/parse/meson.build +++ /dev/null @@ -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, -) diff --git a/tests/meson.build b/tests/meson.build deleted file mode 100644 index 082b746..0000000 --- a/tests/meson.build +++ /dev/null @@ -1 +0,0 @@ -subdir('unit') diff --git a/tests/unit/meson.build b/tests/unit/meson.build deleted file mode 100644 index db8eddd..0000000 --- a/tests/unit/meson.build +++ /dev/null @@ -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 From 171ef10a6d8f0626e1e3e289b868f2a1dfd23c9b Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 1 Sep 2021 19:42:58 +0200 Subject: [PATCH 5/5] abacus: fix include directories 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/` directory per library I create... --- CMakeLists.txt | 3 +++ src/abacus.cc | 2 +- src/bignum/CMakeLists.txt | 4 ---- src/parse/CMakeLists.txt | 2 +- src/parse/parser-driver.hh | 2 +- src/parse/parser.yy | 2 +- tests/unit/bignum.cc | 2 +- 7 files changed, 8 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ef9a7b..d343e5a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,9 @@ target_compile_options(common_options INTERFACE -Wall -Wextra ) +target_include_directories(common_options INTERFACE + src +) add_subdirectory(src) add_subdirectory(tests) diff --git a/src/abacus.cc b/src/abacus.cc index 3e735a0..45d2394 100644 --- a/src/abacus.cc +++ b/src/abacus.cc @@ -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{}; diff --git a/src/bignum/CMakeLists.txt b/src/bignum/CMakeLists.txt index b2434b7..6b64eb6 100644 --- a/src/bignum/CMakeLists.txt +++ b/src/bignum/CMakeLists.txt @@ -3,7 +3,3 @@ add_library(bignum STATIC bignum.hh ) target_link_libraries(bignum PRIVATE common_options) - -target_include_directories(bignum PUBLIC - $ -) diff --git a/src/parse/CMakeLists.txt b/src/parse/CMakeLists.txt index 3c87a92..22a706c 100644 --- a/src/parse/CMakeLists.txt +++ b/src/parse/CMakeLists.txt @@ -18,6 +18,6 @@ target_link_libraries(parse PRIVATE ) target_include_directories(parse PUBLIC - $ $ + $ ) diff --git a/src/parse/parser-driver.hh b/src/parse/parser-driver.hh index d5ba7ea..ad88efd 100644 --- a/src/parse/parser-driver.hh +++ b/src/parse/parser-driver.hh @@ -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 { diff --git a/src/parse/parser.yy b/src/parse/parser.yy index d8fbc87..07e3e3a 100644 --- a/src/parse/parser.yy +++ b/src/parse/parser.yy @@ -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 { diff --git a/tests/unit/bignum.cc b/tests/unit/bignum.cc index f584778..b7306f4 100644 --- a/tests/unit/bignum.cc +++ b/tests/unit/bignum.cc @@ -2,7 +2,7 @@ #include -#include "bignum.hh" +#include "bignum/bignum.hh" using namespace abacus::bignum;