Feb 26, 2021 CMake examples. GitHub Gist: instantly share code, notes, and snippets. So let’s look at each step in more detail and how to implement it in CMake. Step 0: Look for a pre-compiled binary The easy way. CMake provides the findpackage function to look for a package installed on your computer. A package is basically a CMake file that setups a target that you can use just as if it was defined in your CMakeLists.txt. CMake packaging with CPack example 13 February, 2021. CMake is a meta build system that generates build files such as Makefile, build.ninja,.sln, etc. Consumed by the build system such as GNU Make, Ninja, Visual Studio, etc. Corresponding to the CMake Generator selected. CMake has a corresponding meta package system CPack. CPack generates configuration files for numerous packaging systems.
CMakeLists.txt
Modern Cmake Example
cmake_minimum_required(VERSION 3.9) |
# Global Configurations # |
#----------------------------------------------# |
project(ConanTesting CXX) |
set(CMAKE_CXX_STANDARD 17) |
set(CMAKE_VERBOSE_MAKEFILE ON) |
# Conan Bootstrap # |
# Download automatically, you can also just copy the conan.cmake file |
if(NOTEXISTS'${CMAKE_BINARY_DIR}/conan.cmake') |
message(STATUS 'Downloading conan.cmake from https://github.com/conan-io/cmake-conan') |
file(DOWNLOAD'https://github.com/conan-io/cmake-conan/raw/v0.13/conan.cmake' |
'${CMAKE_BINARY_DIR}/conan.cmake') |
endif() |
include(${CMAKE_BINARY_DIR}/conan.cmake) |
conan_cmake_run(REQUIRES |
# Libraries to be installed locally |
Poco/1.9.0@pocoproject/stable |
gtest/1.8.1@bincrafters/stable |
BASIC_SETUP |
BUILD missing |
) |
# Find Packages # |
find_package(GTest REQUIRED) |
# find_package(Poco REQUIRED Foundation) |
# Targets Configurations # |
# > Target for testing POCO Libraries |
add_executable(poco demo-poco.cpp) |
target_link_libraries(poco PRIVATE${CONAN_LIBS}) |
# > Target for testing GogleTest |
add_executable(agtest demo-gtest.cpp) |
target_link_libraries(agtest PRIVATE GTest::GTest GTest::Main) |
add_test(MyGoogleTest agtest) |
install(TARGETS poco agtest DESTINATION ./bin) |
Github Cmake Example Online
demo-gtest.cpp
Github Cmake Example Website
#include<iostream> |
#include<Poco/Process.h> |
#include<gtest/gtest.h> |
auto FunctionObject = [](int n){ return5 * n + 4; }; |
TEST(testA, FunctionObject) |
{ |
EXPECT_EQ(19, FunctionObject(3)); |
} |
TEST(testC, FunctionObject) |
{ |
EXPECT_EQ(123, FunctionObject(5)); |
} |
TEST(testB, FunctionObject) |
{ |
EXPECT_EQ(24, FunctionObject(4)); |
} |
demo-poco.cpp
#include<iostream> |
#include<Poco/Process.h> |
intmain() |
{ |
std::cout << 'Running POCO Libraries Launch.' << std::endl; |
std::cout << 'Poco Libraries are AWESOME!' << std::endl; |
#if !defined(_WIN32) |
std::cerr << ' [INFO] I am running on some Unix-like Operating System.' << std::endl; |
Poco::Process::launch('cat', {'/etc/protocols'}); |
#else |
std::cerr << ' [INFO] I am running on Windows.' << std::endl; |
Poco::Process::launch('notepad.exe', {}); |
#endif |
return0; |
} |
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment