Skip to content

Commit d6b636a

Browse files
committed
fix: modernize and add pinned deps
1 parent 0f73f30 commit d6b636a

16 files changed

+682
-440
lines changed

.clang-format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
BasedOnStyle: Google

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "deps/dlx"]
22
path = deps/dlx
3-
url = git://github.com/patricksjackson/dlx-cpp.git
3+
url = git@github.com:arcuru/dlx-cpp

CMakeLists.txt

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,47 @@
1-
cmake_minimum_required(VERSION 2.8)
1+
cmake_minimum_required(VERSION 3.15)
2+
cmake_policy(SET CMP0048 NEW) # for project version handling
3+
if(POLICY CMP0167)
4+
cmake_policy(SET CMP0167 NEW) # for modern Boost finding
5+
endif()
6+
7+
8+
project(nqueens
9+
VERSION 1.0
10+
LANGUAGES CXX)
11+
12+
# Modern CMake: Set C++ standard globally
13+
set(CMAKE_CXX_STANDARD 14)
14+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
15+
set(CMAKE_CXX_EXTENSIONS OFF)
216

317
# Output compilation database for clangtidy
4-
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
18+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
519

620
# Set default build type to Release
7-
if (NOT CMAKE_BUILD_TYPE)
8-
message(STATUS "No build type selected, default to Release.")
21+
if(NOT CMAKE_BUILD_TYPE)
22+
message(STATUS "No build type selected, default to Release")
923
set(CMAKE_BUILD_TYPE "Release")
1024
endif()
1125

12-
# Enable C++14 features on gcc/clang
13-
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "(GNU|Clang)")
14-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
15-
endif()
16-
17-
# Enable Warnings
18-
# Clang has different warnings
19-
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
20-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcolor-diagnostics -pedantic -Wall -Wextra -Wshadow -Werror")
21-
set(CMAKE_CXX_FLAGS_DEBUG "-Og")
22-
set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG -O3")
23-
else()
24-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
25-
endif()
26+
# Modern threading support
27+
find_package(Threads REQUIRED)
2628

27-
# Add library includes
28-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
29+
# Configure Boost
30+
set(Boost_USE_STATIC_LIBS OFF)
31+
set(Boost_USE_MULTITHREADED ON)
32+
set(Boost_USE_STATIC_RUNTIME OFF)
33+
find_package(Boost REQUIRED COMPONENTS unit_test_framework)
2934

3035
# Include DLX
31-
add_subdirectory(${CMAKE_SOURCE_DIR}/deps/dlx EXCLUDE_FROM_ALL)
32-
include_directories(${CMAKE_SOURCE_DIR}/deps/dlx)
36+
add_subdirectory(${CMAKE_SOURCE_DIR}/deps/dlx)
37+
target_include_directories(dlx
38+
PUBLIC
39+
${CMAKE_SOURCE_DIR}/deps/dlx
40+
)
3341

34-
# Build nqueens lib and add to include path
42+
# Build nqueens lib
3543
add_subdirectory(src)
36-
include_directories(src)
37-
38-
# Add tests
39-
enable_testing()
40-
add_subdirectory(test)
4144

45+
# Enable testing
46+
include(CTest)
47+
add_subdirectory(test)

flake.lock

Lines changed: 138 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{
2+
description = "NQueens solutions";
3+
4+
inputs = {
5+
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
6+
pre-commit-hooks = {
7+
url = "github:cachix/pre-commit-hooks.nix";
8+
inputs.nixpkgs.follows = "nixpkgs";
9+
};
10+
# Utility functions to configure for multiple systems
11+
flake-utils.url = "github:numtide/flake-utils";
12+
};
13+
14+
# `inputs @` allows all the inputs to be accessed later if they're unnamed in the args.
15+
outputs = {
16+
self,
17+
flake-utils,
18+
nixpkgs,
19+
pre-commit-hooks,
20+
...
21+
}:
22+
with flake-utils;
23+
lib.eachSystem [lib.system.aarch64-linux lib.system.x86_64-linux] (system: let
24+
pkgs = import nixpkgs {inherit system;};
25+
in {
26+
# Install devshell packages
27+
devShells.default = pkgs.mkShell {
28+
inherit (self.checks.${system}.pre-commit) shellHook;
29+
packages = with pkgs; [
30+
# General formatters/tools
31+
deadnix
32+
nixfmt
33+
nodePackages.prettier
34+
statix
35+
shellcheck
36+
37+
# Generic C++ packages
38+
cmake
39+
gcc
40+
ninja
41+
clang
42+
43+
# Boost is needed for this repo
44+
# (boost159.override { enableStatic = true; })
45+
(boost.override {
46+
enableStatic = true;
47+
enableShared = true;
48+
components = [
49+
"unit_test_framework"
50+
];
51+
})
52+
pkg-config
53+
];
54+
CMAKE_GENERATOR = "Ninja";
55+
};
56+
57+
checks = {
58+
# Add pre-commit-hooks. Note that these only run on the files in a commit unless running `nix flake check`.
59+
pre-commit = pre-commit-hooks.lib.${system}.run {
60+
src = ./.;
61+
default_stages = ["commit"];
62+
hooks = {
63+
# Format any nix files
64+
alejandra.enable = true;
65+
66+
# Lint/format the shell files.
67+
shellcheck.enable = true;
68+
69+
# Format any changed files
70+
# Formatting settings are contained in .clang-format
71+
clang-format = {
72+
enable = true;
73+
types_or = ["c" "c++"];
74+
excludes = ["catch.hpp"];
75+
};
76+
};
77+
};
78+
};
79+
});
80+
}

src/CMakeLists.txt

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
2-
set(NQUEENS_SOURCE_FILES
3-
array_queens.cpp
4-
flat_queens.cpp
1+
add_library(nqueens_core
52
dlx_queens.cpp
6-
bit_queens.cpp
73
thread_queens.cpp
8-
super_queens.cpp
4+
flat_queens.cpp # Added
5+
array_queens.cpp # Added
6+
bit_queens.cpp # Added
7+
super_queens.cpp # Added
98
)
109

11-
add_library(nqueens_core ${NQUEENS_SOURCE_FILES})
12-
13-
target_link_libraries(nqueens_core dlx)
10+
target_include_directories(nqueens_core
11+
PUBLIC
12+
${CMAKE_CURRENT_SOURCE_DIR}
13+
)
1414

15+
target_link_libraries(nqueens_core
16+
PUBLIC
17+
dlx
18+
Threads::Threads
19+
)

0 commit comments

Comments
 (0)