diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..d343e5a --- /dev/null +++ b/CMakeLists.txt @@ -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) diff --git a/flake.nix b/flake.nix index 56d4ecf..cdf39b2 100644 --- a/flake.nix +++ b/flake.nix @@ -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"; 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/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/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 new file mode 100644 index 0000000..6b64eb6 --- /dev/null +++ b/src/bignum/CMakeLists.txt @@ -0,0 +1,5 @@ +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 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/CMakeLists.txt b/src/parse/CMakeLists.txt new file mode 100644 index 0000000..22a706c --- /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/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/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/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/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/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}) 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; 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