From 1b49477c4eb94f444fb6dad899904d96413432eb Mon Sep 17 00:00:00 2001 From: Matias Date: Fri, 11 Oct 2024 16:22:11 +0100 Subject: [PATCH] nix: set CMake version to 3.30.4 --- .gitignore | 1 + CMakeLists.txt | 20 +++++++++++++------- flake.nix | 17 +++++++++++++---- game/CMakeLists.txt | 4 ++++ lib.cxx => game/src/game.cxx | 7 ++++--- main.cxx => src/main.cxx | 2 +- 6 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 .gitignore create mode 100644 game/CMakeLists.txt rename lib.cxx => game/src/game.cxx (71%) rename main.cxx => src/main.cxx (83%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..89f9ac0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +out/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d83bd2..c46b4a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,17 @@ cmake_minimum_required(VERSION 3.28) -project(ModulesHelloWorld CXX) -set(CMAKE_CXX_EXTENSIONS OFF) -set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_EXTENSIONS ON) +set(CMAKE_CXX_STANDARD_REQUIRED ON) -add_library(lib) -target_sources(lib PUBLIC FILE_SET CXX_MODULES FILES lib.cxx) +# enable modules support +set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "0e5b6991-d74f-4b3d-a41c-cf096e0b2508") -add_executable(hellomodules main.cxx) -target_link_libraries(hellomodules lib) +project(gooey LANGUAGES CXX) + +set(CMAKE_CXX_MODULE_STD ON) + +add_subdirectory(game) + +add_executable(gooey src/main.cxx) +target_link_libraries(gooey game) diff --git a/flake.nix b/flake.nix index ae91676..c10a1c3 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,8 @@ }: flake-utils.lib.eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; - inherit (pkgs.llvmPackages_19) stdenv; + stdenv = pkgs.llvmPackages_19.libcxxStdenv; + cmake-version = "3.30.4"; gooey = stdenv.mkDerivation { pname = "gooey"; @@ -19,10 +20,18 @@ # inherit system; src = ./.; - buildInputs = [ - pkgs.cmake + nativeBuildInputs = [ + (pkgs.cmake.overrideAttrs { + version = "3.30.4"; + src = pkgs.fetchurl { + url = "https://cmake.org/files/v${pkgs.lib.versions.majorMinor cmake-version}/cmake-${cmake-version}.tar.gz"; + hash = "sha256-x1nJcnTx56qq/LHw0mH53pvzpdbst+LfYWMkpG/nBLI="; + }; + }) pkgs.ninja + ]; + buildInputs = [ (pkgs.callPackage ./nix/SDL3.nix {}) pkgs.llvmPackages_19.clang-tools ]; @@ -42,7 +51,7 @@ }; in { packages.default = gooey; - devShells.default = pkgs.mkShell { + devShells.default = pkgs.mkShell.override {inherit stdenv;} { name = "gooey"; inputsFrom = [gooey]; CMAKE_GENERATOR = "Ninja"; diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt new file mode 100644 index 0000000..2657692 --- /dev/null +++ b/game/CMakeLists.txt @@ -0,0 +1,4 @@ +cmake_minimum_required(VERSION 3.28) + +add_library(game) +target_sources(game PUBLIC FILE_SET CXX_MODULES FILES src/game.cxx) diff --git a/lib.cxx b/game/src/game.cxx similarity index 71% rename from lib.cxx rename to game/src/game.cxx index 79c9e58..53c4d08 100644 --- a/lib.cxx +++ b/game/src/game.cxx @@ -1,8 +1,9 @@ // Global module fragment, where #includes can happen module; -#include -export module lib; +import std; + +export module game; export class lib { @@ -17,5 +18,5 @@ lib::~lib() = default; void lib::helloworld() { - std::cout << "Hello world!" << std::endl; + std::print("Hello world!\n"); } diff --git a/main.cxx b/src/main.cxx similarity index 83% rename from main.cxx rename to src/main.cxx index 37731d1..b61b478 100644 --- a/main.cxx +++ b/src/main.cxx @@ -1,4 +1,4 @@ -import lib; +import game; int main() {