Use VCPKG and reorganization

* Remove non-pacman exercises.
* Use vcpkg instead of conan ( make vcpkg a submodule)
* Merge the readmem these will need to be improve later
This commit is contained in:
Corentin Jabot 2021-05-10 14:58:00 +02:00
parent 9966892620
commit 164db664ef
58 changed files with 47 additions and 570 deletions

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "vcpkg"]
path = vcpkg
url = https://github.com/microsoft/vcpkg.git

View file

@ -1,20 +1,15 @@
#This needs to be set before project()
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake
CACHE STRING "Vcpkg toolchain file")
cmake_minimum_required(VERSION 3.17) cmake_minimum_required(VERSION 3.17)
project(modern_cpp_exercises ) project(modern_cpp_exercises )
set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD 20)
# Download automatically, you can also just copy the conan.cmake file add_subdirectory(lib)
if (NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake") add_subdirectory(src)
message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan") add_subdirectory(test)
file(DOWNLOAD "https://github.com/conan-io/cmake-conan/raw/v0.15/conan.cmake"
"${CMAKE_BINARY_DIR}/conan.cmake")
endif ()
include(${CMAKE_BINARY_DIR}/conan.cmake) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/assets/maze.png DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/bin)
conan_add_remote(NAME bincrafters INDEX 1 URL https://api.bintray.com/conan/bincrafters/public-conan) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/assets/sprites32.png DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/bin)
set(CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR}/lcd/;${CMAKE_BINARY_DIR}/pacman/;${CMAKE_BINARY_DIR}/pomodoro/)
add_subdirectory(lcd)
add_subdirectory(pacman)
add_subdirectory(pomodoro)

View file

@ -1,24 +0,0 @@
[< Back](README.md)
# Mod(C++) Linux (Ubuntu) Instructions
## Get Clion
https://www.jetbrains.com/clion/download/download-thanks.html
## Get Python 3
## Get Conan
pip3 install conan --upgrade
## Conan on Linux
Set this environment variable and Conan will tell you which packages you need to
intall on Linux.
CONAN_SYSREQUIRES_MODE=verify
In case of link errors around sndio, try to uninstall this package and rebuild the conan cache:
~~~
sudo apt remove libsndio-dev*
~~~
https://bugzilla.libsdl.org/show_bug.cgi?id=5105

View file

@ -1,13 +1,32 @@
![CMake](https://github.com/turtlesec-no/modern_cpp_exercises/workflows/CMake/badge.svg) # Mod(C++) - Pac-Man Exercise
# Mod(C++) Exercises
## Exercises
* [LCD](lcd/README.md) ## Setup VCPKG
* [Pac-Man](pacman/README.md)
* [Pomodoro](pomodoro/README.md)
## Build instructions On windows, run `.\vcpkg\bootstrap-vcpkg.bat`.
On other platforms, run `./vcpkg/bootstrap-vcpkg.sh`
* [Windows](WINDOWS.md) On all platform run `./vcpkg/vcpkg install sdl2-image gtest`
* [Linux](LINUX.md)
## Keep PacMan Score
* Implement score by implementing eating of pellets by Pac-Man
* Use the existing test.cpp file for TDD scoring
* Pellets are worth 10 points - SuperPellets 50 points
* Implement support for the pellets to be eaten
* Implement support for counting pellets eaten by PacMan
* (Extra: Display score - if you have a LOT of time)
## Make a ghost
* Use the PacMan class as inspiration
* Pic a sprite from [sprites32.png](assets/sprites32.png) for the ghost
* Make an algorithm for movement (simple is fine)
* For fancy algorithm see next section
### Ghosts characters and algorithms
These will probably become relevant
* https://en.wikipedia.org/wiki/Ghosts_(Pac-Man)
* https://youtu.be/ataGotQ7ir8
* https://gameinternals.com/understanding-pac-man-ghost-behavior
* https://www.gamasutra.com/view/feature/3938/the_pacman_dossier.php?print=1

View file

@ -1,26 +0,0 @@
[< Back](README.md)
# Mod(C++) Windows Instructions
## Windows Toolchain
Visual Studio Community 2019 - latest (MSVC 19.28.29334.0)
## Get Clion
https://www.jetbrains.com/clion/download/download-thanks.html
## Get Python 3
https://docs.python.org/3/using/windows.html#the-full-installer
## Get Conan
pip3 install conan --upgrade
## Currently does not work on windows - Get Clang
Clang 10 works seamlessly with Conan (version 1.31.4) - with 11 you have to update your
<userhome>/.conan/settings.yml file, add "11" to the list at "clang: version:"
https://releases.llvm.org/download.html
https://www.jetbrains.com/help/clion/quick-tutorial-on-configuring-clion-on-windows.html#clang-cl

View file

Before

Width:  |  Height:  |  Size: 870 KiB

After

Width:  |  Height:  |  Size: 870 KiB

View file

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

View file

@ -1,7 +0,0 @@
conan_cmake_run(CONANFILE conanfile.py BASIC_SETUP CMAKE_TARGETS BUILD missing)
include_directories(lib)
add_subdirectory(lib)
add_subdirectory(src)
add_subdirectory(test)

View file

@ -1,6 +0,0 @@
[< Back](../README.md)
# Mod(C++) - Lcd Exercise
* Add tests in [lcd_tests.cpp](test/lcd_tests.cpp) and implementation in
[lcd.cpp](lib/lcd.cpp) to support printing all two digit numbers
* Set the MAX variable in [main.cpp](src/main.cpp) to 99 and print all the numbers

View file

@ -1,15 +0,0 @@
from conans import ConanFile, CMake
class ConanDependencies(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package"
default_options = {}
def requirements(self):
self.requires("gtest/1.10.0")
def imports(self):
self.copy("*.dll", dst="bin", src="bin")
self.copy("*.dylib*", dst="bin", src="lib")
self.copy('*.so*', dst='lib', src='lib')
self.copy("license*", dst="licenses", folder=True, ignore_case=True)

View file

@ -1,3 +0,0 @@
file(GLOB_RECURSE sources CONFIGURE_DEPENDS "*.cpp")
add_library(liblcd ${sources})
target_link_libraries(liblcd)

View file

@ -1,40 +0,0 @@
#include "lcd.hpp"
lcd_grid lcd(const std::string & s1,
const std::string & s2,
const std::string & s3) {
lcd_grid result;
result.push_back(s1);
result.push_back(s2);
result.push_back(s3);
return result;
}
const lcd_grid digits[] =
{
lcd(" _ ",
"| |",
"|_|"
),
lcd(" ",
" |",
" |"
),
lcd(" _ ",
" _|",
"|_ "
),
};
lcd_grid lcd(int value) {
if (value < 10)
return digits[value];
else {
lcd_grid lhs = lcd(value / 10);
lcd_grid rhs = digits[value % 10];
return lcd(
lhs[0] + ' ' + rhs[0],
lhs[1] + ' ' + rhs[1],
lhs[2] + ' ' + rhs[2]);
}
}

View file

@ -1,12 +0,0 @@
#pragma once
#include <string>
#include <vector>
typedef std::vector<std::string> lcd_grid;
lcd_grid lcd(int value);
lcd_grid lcd(const std::string & s1,
const std::string & s2,
const std::string & s3);

View file

@ -1,68 +0,0 @@
#include "lcd.hpp"
lcd_grid lcd(const std::string & s1,
const std::string & s2,
const std::string & s3) {
lcd_grid result;
result.push_back(s1);
result.push_back(s2);
result.push_back(s3);
return result;
}
const lcd_grid digits[] =
{
lcd(" _ ",
"| |",
"|_|"
),
lcd(" ",
" |",
" |"
),
lcd(" _ ",
" _|",
"|_ "
),
lcd(" _ ",
" _|",
" _|"
),
lcd(" ",
"|_|",
" |"
),
lcd(" _ ",
"|_ ",
" _|"
),
lcd(" _ ",
"|_ ",
"|_|"
),
lcd(" _ ",
" |",
" |"
),
lcd(" _ ",
"|_|",
"|_|"
),
lcd(" _ ",
"|_|",
" |"
),
};
lcd_grid lcd(int value) {
if (value < 10)
return digits[value];
else {
lcd_grid lhs = lcd(value / 10);
lcd_grid rhs = digits[value % 10];
return lcd(
lhs[0] + ' ' + rhs[0],
lhs[1] + ' ' + rhs[1],
lhs[2] + ' ' + rhs[2]);
}
}

View file

@ -1,110 +0,0 @@
#include <gtest/gtest.h>
#include "lcd.hpp"
#include <iostream>
std::string to_string(const lcd_grid & grid) {
std::stringstream output;
for (const auto & str: grid)
output << str;
return output.str();
}
void lcd_spec(int value, const lcd_grid & grid) {
std::string expected = to_string(grid),
actual = to_string(lcd(value));
if (expected != actual) {
std::cerr
<< "lcd(" << value << ")\n"
<< "expected==\n"
<< expected << '\n'
<< "actual==\n"
<< actual << std::endl;
std::exit(EXIT_FAILURE);
}
}
TEST(LcdTest, Zero) {
lcd_spec(0, lcd(
" _ ",
"| |",
"|_|"
));
}
TEST(LcdTest, One) {
lcd_spec(1, lcd(
" ",
" |",
" |"
));
}
TEST(LcdTest, Two) {
lcd_spec(2, lcd(
" _ ",
" _|",
"|_ "
));
}
TEST(LcdTest, Three) {
lcd_spec(3, lcd(
" _ ",
" _|",
" _|"
));
}
TEST(LcdTest, Four) {
lcd_spec(4, lcd(
" ",
"|_|",
" |"
));
}
TEST(LcdTest, Twelve) {
lcd_spec(12, lcd(
" _ ",
" | _|",
" | |_ "
));
}
TEST(LcdTest, TwentyFive) {
lcd_spec(25, lcd(
" _ _ ",
" _| |_ ",
"|_ _|"
));
}
TEST(LcdTest, SixtyFour) {
lcd_spec(64, lcd(
" _ ",
"|_ |_|",
"|_| |"
));
}
TEST(LcdTest, SeventyFour) {
lcd_spec(74, lcd(
" _ ",
" | |_|",
" | |"
));
}
TEST(LcdTest, EightyNine) {
lcd_spec(89, lcd(
" _ _ ",
"|_| |_|",
"|_| |"
));
}
int main(int argc, char * argv[]) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View file

@ -1,12 +0,0 @@
#include <iostream>
#include "lcd.hpp"
static const int MAX = 100;
int main() {
for (int i = 0; i < MAX; i++) {
auto grid = lcd(i);
for (const auto & line: grid)
std::cout << line << "\n";
}
}

View file

@ -1,4 +0,0 @@
file(GLOB_RECURSE sources CONFIGURE_DEPENDS "*.cpp")
add_executable(lcd ${sources})
target_link_libraries(lcd liblcd)

View file

@ -1,12 +0,0 @@
#include <iostream>
#include "lcd.hpp"
static const int MAX = 3;
int main() {
for (int i = 0; i < MAX; i++) {
auto grid = lcd(i);
for (const auto & line: grid)
std::cout << line << "\n";
}
}

View file

@ -1,10 +0,0 @@
enable_testing()
find_package(GTest REQUIRED)
include(GoogleTest)
add_executable(lcd_tests lcd_tests.cpp)
target_link_libraries(lcd_tests GTest::GTest liblcd)
gtest_discover_tests(lcd_tests TEST_PREFIX lcd:)
add_test(NAME monolithic COMMAND lcd_tests)

View file

@ -1,46 +0,0 @@
#include <gtest/gtest.h>
#include "lcd.hpp"
#include <iostream>
std::string to_string(const lcd_grid & grid) {
std::stringstream output;
for (const auto & str: grid)
output << str;
return output.str();
}
void lcd_spec(int value, const lcd_grid & grid) {
std::string expected = to_string(grid),
actual = to_string(lcd(value));
if (expected != actual) {
std::cerr
<< "lcd(" << value << ")\n"
<< "expected==\n"
<< expected << '\n'
<< "actual==\n"
<< actual << std::endl;
std::exit(EXIT_FAILURE);
}
}
TEST(LcdTest, Zero) {
lcd_spec(0, lcd(
" _ ",
"| |",
"|_|"
));
}
TEST(LcdTest, Twelve) {
lcd_spec(12, lcd(
" _ ",
" | _|",
" | |_ "
));
}
int main(int argc, char * argv[]) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

6
lib/CMakeLists.txt Normal file
View file

@ -0,0 +1,6 @@
find_package(sdl2-image CONFIG REQUIRED)
file(GLOB_RECURSE sources CONFIGURE_DEPENDS "*.cpp")
add_library(libpacman ${sources})
target_include_directories(libpacman PUBLIC .)
target_link_libraries(libpacman PUBLIC SDL2::SDL2-static SDL2::SDL2_image)

View file

@ -1,12 +0,0 @@
conan_cmake_run(CONANFILE conanfile.py BASIC_SETUP CMAKE_TARGETS BUILD missing)
find_package(sdl2 REQUIRED)
find_package(sdl2_image REQUIRED)
include_directories(lib ${sdl2_INCLUDE_DIRS} ${sdl2_image_INCLUDE_DIRS})
add_subdirectory(lib)
add_subdirectory(src)
add_subdirectory(test)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/assets/maze.png DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/bin)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/assets/sprites32.png DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/bin)

View file

@ -1,25 +0,0 @@
[< Back](../README.md)
# Mod(C++) - Pac-Man Exercise
## Keep PacMan Score
* Implement score by implementing eating of pellets by Pac-Man
* Use the existing test.cpp file for TDD scoring
* Pellets are worth 10 points - SuperPellets 50 points
* Implement support for the pellets to be eaten
* Implement support for counting pellets eaten by PacMan
* (Extra: Display score - if you have a LOT of time)
## Make a ghost
* Use the PacMan class as inspiration
* Pic a sprite from [sprites32.png](assets/sprites32.png) for the ghost
* Make an algorithm for movement (simple is fine)
* For fancy algorithm see next section
### Ghosts characters and algorithms
These will probably become relevant
* https://en.wikipedia.org/wiki/Ghosts_(Pac-Man)
* https://youtu.be/ataGotQ7ir8
* https://gameinternals.com/understanding-pac-man-ghost-behavior
* https://www.gamasutra.com/view/feature/3938/the_pacman_dossier.php?print=1

View file

@ -1,20 +0,0 @@
from conans import ConanFile, CMake
class ConanDependencies(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package"
default_options = {
"sdl2_image:jpg": "libjpeg"
}
def requirements(self):
self.requires("gtest/1.10.0")
self.requires("sdl2/2.0.9@bincrafters/stable")
self.requires("sdl2_image/2.0.4@bincrafters/stable")
def imports(self):
self.copy("*.dll", dst="bin", src="bin")
self.copy("*.dylib*", dst="bin", src="lib")
self.copy('*.so*', dst='lib', src='lib')
self.copy("license*", dst="licenses", folder=True, ignore_case=True)

View file

@ -1,8 +0,0 @@
file(GLOB_RECURSE sources CONFIGURE_DEPENDS "*.cpp")
add_library(libpacman ${sources})
target_link_libraries(libpacman sdl2::sdl2 sdl2_image::sdl2_image)
#target_compile_options(libpacman PRIVATE -fsanitize=address) # /MD will be used implicitly
#target_link_directories(libpacman PRIVATE "$ENV{ProgramFiles\(x86\)}/Microsoft Visual Studio/2019/Community/VC/Tools/Llvm/x64/lib/clang/10.0.0/lib/windows")
#target_link_libraries(libpacman PRIVATE sdl2::sdl2 sdl2_image::sdl2_image clang_rt.asan_dynamic-x86_64 clang_rt.asan_dynamic_runtime_thunk-x86_64)
#target_link_options(libpacman PRIVATE /wholearchive:clang_rt.asan_dynamic_runtime_thunk-x86_64.lib /wholearchive:clang_rt.asan_dynamic-x86_64.lib)

View file

@ -1,16 +0,0 @@
conan_cmake_run(CONANFILE conanfile.py BASIC_SETUP CMAKE_TARGETS BUILD missing)
configure_file(${CMAKE_CURRENT_BINARY_DIR}/qt.conf ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/qt.conf COPYONLY)
find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
include_directories(lib)
add_subdirectory(lib)
add_subdirectory(src)
add_subdirectory(test)

View file

@ -1,2 +0,0 @@
[< Back](../README.md)
# Mod(C++) - Pomodoro Exercise

View file

@ -1,23 +0,0 @@
from conans import ConanFile, CMake
class ConanDependencies(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "qt", "virtualrunenv"
default_options = {}
def requirements(self):
self.requires("gtest/1.10.0")
self.requires("qt/5.15.1@bincrafters/stable")
def imports(self):
self.copy("*.dll", dst="bin", src="bin")
self.copy("*.dylib*", dst="bin", src="lib")
self.copy('*.so*', dst='lib', src='lib')
self.copy('*', dst='libexec', src='libexec')
self.copy('*', dst='plugins', src='plugins')
self.copy('*', dst='qml', src='qml')
self.copy('*', dst='translations', src='translations')
self.copy('*', dst='resources', src='resources')
self.copy("license*", dst="licenses", folder=True, ignore_case=True)

View file

@ -1,3 +0,0 @@
file(GLOB_RECURSE sources CONFIGURE_DEPENDS "*.cpp")
add_library(libpomodoro ${sources})
target_link_libraries(libpomodoro Qt5::Core Qt5::Gui Qt5::Widgets)

View file

@ -1 +0,0 @@
#include "Pomodoro.hpp"

View file

@ -1,8 +0,0 @@
#ifndef POMODORO_POMODORO_HPP
#define POMODORO_POMODORO_HPP
class Pomodoro {
};
#endif //POMODORO_POMODORO_HPP

View file

@ -1,3 +0,0 @@
file(GLOB_RECURSE sources CONFIGURE_DEPENDS "*.cpp")
add_executable(pomodoro ${sources})
target_link_libraries(pomodoro libpomodoro Qt5::Core Qt5::Gui Qt5::Widgets)

View file

@ -1,11 +0,0 @@
#include <QApplication>
#include <QPushButton>
#include "Pomodoro.hpp"
int main(int argc, char * argv[]) {
QApplication app(argc, argv);
QPushButton button("Hello world !");
Pomodoro pomodoro;
button.show();
return app.exec();
}

View file

@ -1,10 +0,0 @@
enable_testing()
find_package(GTest REQUIRED)
include(GoogleTest)
add_executable(pomodoro_tests tests.cpp)
target_link_libraries(pomodoro_tests GTest::GTest libpomodoro)
gtest_discover_tests(pomodoro_tests TEST_PREFIX pomodoro:)
add_test(NAME monolithic COMMAND pomodoro_tests)

View file

@ -1,10 +0,0 @@
#include <gtest/gtest.h>
TEST(PomodoroTest, Init) {
EXPECT_EQ(1, 2);
}
int main(int argc, char* argv[]) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

1
vcpkg Submodule

@ -0,0 +1 @@
Subproject commit 5a271a9290282e09149401486f88dc106dc65b71