cmake usable?

main
Johannes Hendrik Gerard van der Weide 2023-10-10 21:10:52 +02:00
parent 51d9ce2ed1
commit c18746942d
4 changed files with 48 additions and 12 deletions

View File

@ -26,9 +26,9 @@
default = pkgs.mkShell {
# The Nix packages provided in the environment
packages = with pkgs; [
boost
sfml
cmake
gcc
poco
];
};
});
@ -36,18 +36,18 @@
packages = forAllSystems ({ pkgs }: {
default =
let
binName = "SFML_Game";
binName = "SFMLtest";
cppDependencies = with pkgs; [
boost
sfml
cmake
gcc
poco
];
in
pkgs.stdenv.mkDerivation {
name = "SFML_Game";
name = "SFMLtest";
src = self;
buildInputs = cppDependencies;
buildPhase = "c++ -std=c++17 -o ${binName} ${./main.cpp} -lPocoFoundation -lboost_system";
buildPhase = "c++ -std=c++17 -o ${binName} ${./src/main.cpp} -lPocoFoundation -lboost_system";
installPhase = ''
mkdir -p $out/bin
cp ${binName} $out/bin/

View File

@ -1,5 +0,0 @@
#include <iostream>
int main() {
std::cout << "Hello from Nix + C++!\n";
}

19
src/CMakeLists.txt Normal file
View File

@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.17)
project(SFMLtest)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin/")
find_package(SFML 2.5.1 COMPONENTS system graphics audio REQUIRED)
file(GLOB_RECURSE
SOURCE
"${CMAKE_SOURCE_DIR}/src/**.cpp")
add_executable(SFMLtest ${SOURCE})
target_link_libraries(SFMLtest sfml-system sfml-window sfml-graphics sfml-audio)

22
src/main.cpp Normal file
View File

@ -0,0 +1,22 @@
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(640, 480), "SFML Application");
sf::CircleShape shape;
shape.setRadius(40.f);
shape.setPosition(100.f, 100.f);
shape.setFillColor(sf::Color::Cyan);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
}