Skip to content

Instantly share code, notes, and snippets.

@caiorss
Created January 9, 2019 00:38
Show Gist options
  • Save caiorss/724942d43cd11c6ee5b3461ac067c846 to your computer and use it in GitHub Desktop.
Save caiorss/724942d43cd11c6ee5b3461ac067c846 to your computer and use it in GitHub Desktop.
Example C++ project with Cmake + VCPKG package manager + Nana GUI library
cmake_minimum_required(VERSION 3.9)
if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "")
message(" [INFO] VCPKG CMAKE_TOOLCHAIN_FILE = ${CMAKE_TOOLCHAIN_FILE}")
endif()
#======= Global Project Configuration =========#
project(DummyProject)
set(CMAKE_CXX_STANDARD 17)
#========== Targets Configurations ============#
## ==> Target: gui1 - Executable: gui1
find_package(unofficial-nana CONFIG REQUIRED)
add_executable(gui1 gui1.cpp)
target_link_libraries(gui1 PRIVATE
unofficial::nana::nana fontconfig stdc++fs)
# Add target to run executable gui1 (similar to $ make run)
add_custom_target(run-gui1
COMMAND gui1
DEPENDS gui1
WORKING_DIRECTORY ${CMAKE_PROJECT_DIR}
)
# Install directory relative to ${CMAKE_PREFIX_PATH}
install(TARGETS gui1 DESTINATION ./bin)
#include <nana/gui.hpp>
#include <nana/gui/widgets/label.hpp>
#include <nana/gui/widgets/button.hpp>
int main()
{
using namespace nana;
//Define a form.
form fm;
//Define a label and display a text.
label lab{fm, "Hello, <bold blue size=16>Nana C++ Library</>"};
lab.format(true);
//Define a button and answer the click event.
button btn{fm, "Quit"};
btn.events().click([&fm]{
fm.close();
});
//Layout management
fm.div("vert <><<><weight=80% text><>><><weight=24<><button><>><>");
fm["text"]<<lab;
fm["button"] << btn;
fm.collocate();
//Show the form
fm.show();
//Start to event loop process, it blocks until the form is closed.
exec();
}
@linonetwo
Copy link

How to use boost?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment