diff --git a/CMakeLists.txt b/CMakeLists.txt index 351f1b0..1eef63a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,75 +1,15 @@ cmake_minimum_required(VERSION 3.12) -project(squirrel VERSION 0.0.1 DESCRIPTION "Simplified, runtime-configurable QMK as a library") +project(squirrel) +# Override this in your build of the library! Otherwise, it will default to 1 key. add_compile_definitions(SQUIRREL_KEYCOUNT=1) if (CMAKE_BUILD_TYPE STREQUAL "Debug") - message(STATUS "Debug/Development build enabled") - set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Autocomplete support - add_compile_options(-Og) # Enable debug optimizations -elseif(CMAKE_BUILD_TYPE STREQUAL "Testing") - message(STATUS "Testing enabled") - add_compile_options(-O3) # Don't include test code in coverage percent. - include(CTest) - enable_testing() - - include_directories(include) - - list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeModules") - if(CMAKE_COMPILER_IS_GNUCXX) - include(CodeCoverage) - APPEND_COVERAGE_COMPILER_FLAGS() - setup_target_for_coverage_gcovr_html(squirrel squirrel_test coverage) - list(APPEND GCOVR_EXCLUDES "tests/") - endif() - - add_executable(keyboard_press_release tests/keyboard_press_release.c) - target_link_libraries(keyboard_press_release squirrel) - add_test(NAME keyboard_press_release COMMAND keyboard_press_release) - - add_executable(keyboard_modifier_press_release tests/keyboard_modifier_press_release.c) - target_link_libraries(keyboard_modifier_press_release squirrel) - add_test(NAME keyboard_modifier_press_release COMMAND keyboard_modifier_press_release) - - add_executable(quantum_passthrough_press_release tests/quantum_passthrough_press_release.c) - target_link_libraries(quantum_passthrough_press_release squirrel) - add_test(NAME quantum_passthrough_press_release COMMAND quantum_passthrough_press_release) - - add_executable(keyboard_get_keycodes tests/keyboard_get_keycodes.c) - target_link_libraries(keyboard_get_keycodes squirrel) - add_test(NAME keyboard_get_keycodes COMMAND keyboard_get_keycodes) - - add_executable(consumer_press_release tests/consumer_press_release.c) - target_link_libraries(consumer_press_release squirrel) - add_test(NAME consumer_press_release COMMAND consumer_press_release) - - add_executable(key tests/key.c) - target_link_libraries(key squirrel) - add_test(NAME key COMMAND key) - - add_executable(layer_press_release tests/layer_press_release.c) - target_link_libraries(layer_press_release squirrel) - add_test(NAME layer_press_release COMMAND layer_press_release) - - add_executable(consumer_activate_deactivate_get_consumer_code tests/consumer_activate_deactivate_get_consumer_code.c) - target_link_libraries(consumer_activate_deactivate_get_consumer_code squirrel) - add_test(NAME consumer_activate_deactivate_get_consumer_code COMMAND consumer_activate_deactivate_get_consumer_code) - - add_executable(keyboard_activate_deactivate_keycode tests/keyboard_activate_deactivate_keycode.c) - target_link_libraries(keyboard_activate_deactivate_keycode squirrel) - add_test(NAME keyboard_activate_deactivate_keycode COMMAND keyboard_activate_deactivate_keycode) - - add_executable(keyboard_activate_deactivate_get_modifier tests/keyboard_activate_deactivate_get_modifier.c) - target_link_libraries(keyboard_activate_deactivate_get_modifier squirrel) - add_test(NAME keyboard_activate_deactivate_get_modifier COMMAND keyboard_activate_deactivate_get_modifier) - - add_executable(keymap tests/keymap.c) - target_link_libraries(keymap squirrel) - target_compile_definitions(keymap PRIVATE SQUIRREL_KEYCOUNT=2) - add_test(NAME keymap COMMAND keymap) + set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + add_compile_options(-Og) else() - add_compile_options(-Os) # Enable size optimizations + add_compile_options(-Os) endif() # Generate a static library archive. @@ -84,7 +24,62 @@ add_library(squirrel STATIC src/squirrel_split.c ) -target_include_directories(squirrel PRIVATE include) - -set_target_properties(squirrel PROPERTIES VERSION ${PROJECT_VERSION}) +target_include_directories(squirrel PUBLIC include) set_target_properties(squirrel PROPERTIES PUBLIC_HEADER include/squirrel.h) + +include(CTest) +enable_testing() + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeModules") +if(CMAKE_COMPILER_IS_GNUCXX) + include(CodeCoverage) + APPEND_COVERAGE_COMPILER_FLAGS() + setup_target_for_coverage_gcovr_html(squirrel squirrel_test coverage) + list(APPEND GCOVR_EXCLUDES "tests/") +endif() + +add_executable(keyboard_press_release tests/keyboard_press_release.c) +target_link_libraries(keyboard_press_release squirrel) +add_test(NAME keyboard_press_release COMMAND keyboard_press_release) + +add_executable(keyboard_modifier_press_release tests/keyboard_modifier_press_release.c) +target_link_libraries(keyboard_modifier_press_release squirrel) +add_test(NAME keyboard_modifier_press_release COMMAND keyboard_modifier_press_release) + +add_executable(quantum_passthrough_press_release tests/quantum_passthrough_press_release.c) +target_link_libraries(quantum_passthrough_press_release squirrel) +add_test(NAME quantum_passthrough_press_release COMMAND quantum_passthrough_press_release) + +add_executable(keyboard_get_keycodes tests/keyboard_get_keycodes.c) +target_link_libraries(keyboard_get_keycodes squirrel) +add_test(NAME keyboard_get_keycodes COMMAND keyboard_get_keycodes) + +add_executable(consumer_press_release tests/consumer_press_release.c) +target_link_libraries(consumer_press_release squirrel) +add_test(NAME consumer_press_release COMMAND consumer_press_release) + +add_executable(key tests/key.c) +target_link_libraries(key squirrel) +add_test(NAME key COMMAND key) + +add_executable(layer_press_release tests/layer_press_release.c) +target_link_libraries(layer_press_release squirrel) +add_test(NAME layer_press_release COMMAND layer_press_release) + +add_executable(consumer_activate_deactivate_get_consumer_code tests/consumer_activate_deactivate_get_consumer_code.c) +target_link_libraries(consumer_activate_deactivate_get_consumer_code squirrel) +add_test(NAME consumer_activate_deactivate_get_consumer_code COMMAND consumer_activate_deactivate_get_consumer_code) + +add_executable(keyboard_activate_deactivate_keycode tests/keyboard_activate_deactivate_keycode.c) +target_link_libraries(keyboard_activate_deactivate_keycode squirrel) +add_test(NAME keyboard_activate_deactivate_keycode COMMAND keyboard_activate_deactivate_keycode) + +add_executable(keyboard_activate_deactivate_get_modifier tests/keyboard_activate_deactivate_get_modifier.c) +target_link_libraries(keyboard_activate_deactivate_get_modifier squirrel) +add_test(NAME keyboard_activate_deactivate_get_modifier COMMAND keyboard_activate_deactivate_get_modifier) + +add_executable(keymap tests/keymap.c) +target_link_libraries(keymap squirrel) +target_compile_definitions(keymap PRIVATE SQUIRREL_KEYCOUNT=2) +add_test(NAME keymap COMMAND keymap) + diff --git a/default.nix b/default.nix deleted file mode 100644 index 86a7fdd..0000000 --- a/default.nix +++ /dev/null @@ -1,35 +0,0 @@ -{ lib -, gcc -, gnumake -, cmake -, stdenv -}: - -stdenv.mkDerivation { - name = "squirrel"; - src = ./.; - - nativeBuildInputs = [ cmake gnumake ]; - buildInputs = [ ]; - - cmakeFlags = [ - "-DCMAKE_BUILD_TYPE=Release" - "-DCMAKE_C_COMPILER=${gcc}/bin/gcc" - "-DCMAKE_CXX_COMPILER=${gcc}/bin/g++" - ]; - - installPhase = '' - mkdir -p $out - mkdir -p $out/lib - cp libsquirrel.a $out/lib/libsquirrel.a - ''; - - checkPhase = ''make -C ./build test''; - - meta = with lib; { - homepage = "https://github.com/headblockhead/squirrel"; - description = "Keyboard firmware library inspired by QMK."; - platforms = with platforms; linux; - }; -} - diff --git a/flake.nix b/flake.nix index fce6bf2..35c2845 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,4 @@ { - description = "Tools for developing, building and testing SQUIRREL"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05"; flake-utils.url = "github:numtide/flake-utils"; @@ -12,24 +11,40 @@ inherit system; }; in - { - # Development shell (nix develop) - devShells.default = pkgs.mkShell { - buildInputs = with pkgs; [ - xc - gcovr - cmake - gcc - ccls - gnumake - git - cacert - ]; - }; + rec { # The library (nix build) - packages.squirrel = pkgs.callPackage ./default.nix { }; - # The tests (nix flake check) - checks.squirrel-tests = pkgs.callPackage ./tests.nix { }; + packages.squirrel = pkgs.stdenv.mkDerivation { + name = "squirrel"; + src = ./.; + + nativeBuildInputs = with pkgs; [ cmake gcovr ]; + + buildPhase = '' + runHook preBuild + cmake . + cmake --build . -t squirrel + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + mkdir -p $out/lib + cp libsquirrel.a $out/lib/libsquirrel.a + runHook postInstall + ''; + + checkPhase = '' + runHook preCheck + cmake . + cmake --build . + ctest --timeout 60 + runHook postCheck + ''; + }; + + checks.squirrel = packages.squirrel.overrideAttrs (oldAttrs: { + doCheck = true; + }); } ); } diff --git a/tests.nix b/tests.nix deleted file mode 100644 index 4972622..0000000 --- a/tests.nix +++ /dev/null @@ -1,33 +0,0 @@ -{ lib -, gcc -, gnumake -, cmake -, stdenv -, gcovr -}: - -stdenv.mkDerivation { - name = "squirrel-tests"; - src = ./.; - - nativeBuildInputs = [ cmake gnumake gcovr ]; - buildInputs = [ ]; - - cmakeFlags = [ - "-DCMAKE_BUILD_TYPE=Testing" - "-DCMAKE_C_COMPILER=${gcc}/bin/gcc" - "-DCMAKE_CXX_COMPILER=${gcc}/bin/g++" - ]; - - installPhase = '' - mkdir -p $out # Output directory must be created for the build to succeed - ctest -T Test -T Coverage --timeout 60 - ''; - - meta = with lib; { - homepage = "https://github.com/headblockhead/squirrel"; - description = "Keyboard firmware library inspired by QMK."; - platforms = with platforms; linux; - }; -} -