Skip to content

Instantly share code, notes, and snippets.

@dr3mro
Forked from raspberrypisig/CMakeLists.txt
Created June 4, 2023 14:18
Show Gist options
  • Save dr3mro/fbc2a0f5bad65e55b0f539dbc145df77 to your computer and use it in GitHub Desktop.
Save dr3mro/fbc2a0f5bad65e55b0f539dbc145df77 to your computer and use it in GitHub Desktop.
msys2 vscode integration c++ vcpkg cmake
MSYS2 Setup
------------
1. Install MSYS2
2. Follow normal install instructions, update packages with pacman etc.
3. Add the following directories to PATH :
C:\msys64\mingw64\bin
4. Run the following commands in a MSYS2 console:
pacman -S --needed git base-devel mingw-w64-x86_64-toolchain mingw-w64-x86_64-clang mingw-w64-x86_64-cmake
cd /mingw64/bin
ln -s mingw32-make.exe make.exe
VSCode
---------
1. Install VSCode
2. Left click on Extensions on left sidebar, then search and install the C/C++ Extension Pack from Microsoft
3. Press F1 to open the Command Palette, type: settings json
pick the option "Preferences: Open Workspace Settings(JSON)"
4. [THIS IS AN OPTIONAL STEP TO HAVE MSYS2 as an integrated terminal in VSCode]
Copy/paste the settings.json file in this gist.
Terminal->New terminal. An MSYS2 MINGW64 terminal will open. Verify the following on the prompt:
5. Type the following in a Windows Command Prompt to verify installation:
g++ --version
g++ -dumpmachine
make --version
cmake --version
6. In this gist, you will find main.cpp and CMakeLists.txt. Include them in your project.
7. Press F1 to open the Command Palette: cmake edit
pick "CMake: Edit User-Local CMake Kits"
8. Append to the list with a comma, the fragment from cmake-tools-kits.json in this append. Do not overwrite the entries all ready
there.
9. Where it says "No active kit" on the CMake toolbar at the bottom of the screen. select it and you should see the entry just created
"Mingw64 GCC 11.2.0" (if not, click Scan Kits)
10. To build, click Build on the CMake toolbar at the bottom of the screen.
11. To run, click the play button on the CMake toolbar at the bottom of the screen.
install vcpkg in msys2 mingw64
-------------------------------
From
https://github.com/microsoft/vcpkg/blob/master/docs/users/mingw.md
https://github.com/microsoft/vcpkg/blob/master/docs/users/integration.md
1. Open MSys2 MingW64 variant of the console.
or type: source shell mingw64
2.
cd /mingw64/bin
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.bat
export VCPKG_DEFAULT_TRIPLET=x64-mingw-dynamic
export VCPKG_DEFAULT_HOST_TRIPLET=x64-mingw-dynamic
To test setup
./vcpkg install zlib
/*
This command ends with:
The package zlib is compatible with built-in CMake targets:
find_package(ZLIB REQUIRED)
target_link_libraries(main PRIVATE ZLIB::ZLIB)
*/
For the real deal
./vcpkg install libtcod
{
"name": "Mingw64 GCC 11.2.0",
"compilers": {
"C": "C:\\msys64\\mingw64\\bin\\gcc.exe",
"CXX": "C:\\msys64\\mingw64\\bin\\g++.exe"
},
"preferredGenerator": {
"name": "MinGW Makefiles"
},
"environmentVariables": {
"CMT_MINGW_PATH": "C:\\msys64\\mingw64\\bin",
"VCPKG_TARGET_TRIPLET": "x64-mingw-static"
},
"toolchainFile": "C:\\msys64\\mingw64\\bin\\vcpkg\\scripts\\buildsystems\\vcpkg.cmake"
}
cmake_minimum_required(VERSION 3.10)
project (roguelike-firststab)
set(SDL2_DIR "C:/msys64/mingw64/bin/vcpkg/installed/x64-mingw-static/share/sdl2")
set(glad_DIR "C:/msys64/mingw64/bin/vcpkg/installed/x64-mingw-static/share/glad")
set(lodepng-c_DIR "C:/msys64/mingw64/bin/vcpkg/installed/x64-mingw-static/share/lodepng-c")
set(libtcod_DIR "C:/msys64/mingw64/bin/vcpkg/installed/x64-mingw-static/share/libtcod")
find_package(libtcod CONFIG REQUIRED)
add_executable(roguelike-firststab main.cpp)
target_link_libraries(roguelike-firststab PRIVATE libtcod::libtcod)
add_definitions(-DSDL_MAIN_HANDLED)
#set(CPM_DOWNLOAD_VERSION 0.31.1)
#set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
#if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
# message(STATUS "Downloading CPM.cmake")
# file(DOWNLOAD https://github.com/TheLartians/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake ${CPM_DOWNLOAD_LOCATION})
#endif()
#include(${CPM_DOWNLOAD_LOCATION})
#CPMAddPackage(
# NAME SDL2
# VERSION 2.0.18
# URL https://libsdl.org/release/SDL2-2.0.18.zip
#)
#if (SDL2_ADDED)
# add_library(SDL2::SDL2 ALIAS SDL2)
#endif()
#CPMAddPackage("gh:libtcod/libtcod#1.19.0")
#include <fmt/core.h>
int main() {
fmt::print("Such a relief when it works!\n");
}
/*
#include <iostream>
int main() {
auto hello = "Hello World\n";
std::cout << hello;
}
*/
{
"terminal.integrated.profiles.windows": {
"msys2": {
"path": [
"C:\\msys64\\usr\\bin\\bash.exe"
],
"args": [
"--login"
],
"env": {
"MSYSTEM": "MINGW64",
"CHERE_INVOKING": "1"
}
}
},
"terminal.integrated.defaultProfile.windows": "msys2"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment