Github Cmake Example

Example C++ project with Cmake + VCPKG package manager + Nana GUI library
CMakeLists.txt
cmake_minimum_required(VERSION 3.9)
if(DEFINEDENV{VCPKG_ROOT} ANDNOTDEFINED 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 CONFIGREQUIRED)
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)
  • GoogleTest Submodule method (preferred) To use this method, just checkout GoogleTest as a submodule: 1 git submodule add -branch=release-1.8.
  • CMake is a meta build tool. It can generate build files for various build tools such as make, Ninja, Visual Studio. So using CMake is way to make sure that our programs can build across platforms and build tools. Some famous open source projects choose CMake as their build tools. These projects include Neovim, OpenCV, MySQL.
  • FetchContent (CMake 3.11+) Often, you would like to do your download of data or packages as part of the configure instead of the build. This was invented several times in third party modules, but was finally added to CMake itself as part of CMake 3.11 as the FetchContent module. The FetchContent module has excellent documentation that I won't try to repeat.

Feb 26, 2021 CMake examples. Visual studio unreal engine. GitHub Gist: instantly share code, notes, and snippets. The Hello World C Example. #include int main(int argc, char.argv) std::cout.

gui1.cpp
#include<nana/gui.hpp>
#include<nana/gui/widgets/label.hpp>
#include<nana/gui/widgets/button.hpp>
intmain()
{
usingnamespacenana;
//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();
}

commented May 28, 2019

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

There are several ways to install CMake, depending on your platform.

Windows

There are pre-compiled binaries available on the Download page for Windows as MSI packages and ZIP files. One may alternatively download and build CMake from source. The Download page also provides source releases. In order to build CMake from a source tree on Windows, you must first install the latest binary version of CMake because it is used for building the source tree. Once the binary is installed, run it on CMake as you would any other project. Typically this means selecting CMake as the Source directory and then selecting a binary directory for the resulting executables.

Cmake

Github Cmake Example

Linux, macOS, UNIX

Modern Cmake Example

There are pre-compiled binaries available on the Download page for some UNIX platforms. One may alternatively download and build CMake from source. The Download page provides source releases. There are two possible approaches for building CMake from a source tree. If there is no existing CMake installation, a bootstrap script is provided:

(Note: the make install step is optional, cmake will run from the build directory.)

By default bootstrap will build CMake without any debug or optimization flags. To enable optimizations you will need to specify the CMAKE_BUILD_TYPE option to bootstrap like this: ./bootstrap -- -DCMAKE_BUILD_TYPE:STRING=Release

For more options with bootstrap, run ./bootstrap --help .

Or, an existing CMake installation can be used to build a new version:

Cmake If Example

(Note: the make install step is optional, cmake will run from the build directory.) If you are not using the GNU C++ compiler, you need to tell the bootstrap script (or cmake) which compiler you want to use. This is done by setting the environment variables CC and CXX before running it. For example:

Download Verification

Each release on the Download page comes with a file named cmake-$version-SHA-256.txt, where $version is the release version number.
One may use this file to verify other downloads, such as the source tarball. For example:

Github Cmake Example Website

The SHA-256 file itself can be verified by GPG signature:

Cmakelists Tutorial

The GPG key C6C265324BBEBDC350B513D02D2CEF1034921684 is a signing subkey whose expiry is updated yearly.