diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index d343e5a..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -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) diff --git a/flake.nix b/flake.nix index cdf39b2..56d4ecf 100644 --- a/flake.nix +++ b/flake.nix @@ -76,8 +76,8 @@ nativeBuildInputs = with pkgs; [ bison - cmake flex + meson ninja pkg-config ]; @@ -86,8 +86,6 @@ gtest ]; - doCheck = true; - meta = with pkgs.lib; { description = "A simple calculator using big numbers"; homepage = "https://gitea.belanyi.fr/ambroisie/abacus"; diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..4910f6a --- /dev/null +++ b/meson.build @@ -0,0 +1,13 @@ +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/CMakeLists.txt b/src/CMakeLists.txt deleted file mode 100644 index 531ca47..0000000 --- a/src/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -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/abacus.cc b/src/abacus.cc index 45d2394..3e735a0 100644 --- a/src/abacus.cc +++ b/src/abacus.cc @@ -1,4 +1,4 @@ -#include "parse/parser-driver.hh" +#include "parser-driver.hh" // FIXME: I would like `parse/parser-driver.hh` path instead... int main() { abacus::parse::ParserDriver driver{}; diff --git a/src/bignum/CMakeLists.txt b/src/bignum/CMakeLists.txt deleted file mode 100644 index 6b64eb6..0000000 --- a/src/bignum/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -add_library(bignum STATIC - bignum.cc - bignum.hh -) -target_link_libraries(bignum PRIVATE common_options) diff --git a/src/bignum/meson.build b/src/bignum/meson.build new file mode 100644 index 0000000..af1e4e5 --- /dev/null +++ b/src/bignum/meson.build @@ -0,0 +1,16 @@ +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 new file mode 100644 index 0000000..a6c5cb2 --- /dev/null +++ b/src/meson.build @@ -0,0 +1,16 @@ +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/CMakeLists.txt b/src/parse/CMakeLists.txt deleted file mode 100644 index 22a706c..0000000 --- a/src/parse/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -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/src/parse/meson.build b/src/parse/meson.build new file mode 100644 index 0000000..1a3bdcb --- /dev/null +++ b/src/parse/meson.build @@ -0,0 +1,48 @@ +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/src/parse/parser-driver.hh b/src/parse/parser-driver.hh index ad88efd..d5ba7ea 100644 --- a/src/parse/parser-driver.hh +++ b/src/parse/parser-driver.hh @@ -4,7 +4,7 @@ #include "parser.hh" -#include "bignum/bignum.hh" +#include "bignum.hh" // FIXME: I would like `bignum/bignum.hh` path instead... namespace abacus::parse { diff --git a/src/parse/parser.yy b/src/parse/parser.yy index 07e3e3a..d8fbc87 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/bignum.hh" +#include "bignum.hh" // FIXME: I would like `bignum/bignum.hh` path instead... } %code provides { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt deleted file mode 100644 index 269aea0..0000000 --- a/tests/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_subdirectory(unit) diff --git a/tests/meson.build b/tests/meson.build new file mode 100644 index 0000000..082b746 --- /dev/null +++ b/tests/meson.build @@ -0,0 +1 @@ +subdir('unit') diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt deleted file mode 100644 index bdf51ae..0000000 --- a/tests/unit/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -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}) diff --git a/tests/unit/bignum.cc b/tests/unit/bignum.cc index b7306f4..f584778 100644 --- a/tests/unit/bignum.cc +++ b/tests/unit/bignum.cc @@ -2,7 +2,7 @@ #include -#include "bignum/bignum.hh" +#include "bignum.hh" using namespace abacus::bignum; diff --git a/tests/unit/meson.build b/tests/unit/meson.build new file mode 100644 index 0000000..db8eddd --- /dev/null +++ b/tests/unit/meson.build @@ -0,0 +1,26 @@ +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