Created
June 16, 2019 00:14
-
-
Save caiorss/7b0732f5de5ebc40981521e63a122d8e to your computer and use it in GitHub Desktop.
Cmake conan C++ project example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(NOT EXISTS "${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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <Poco/Process.h> | |
#include <gtest/gtest.h> | |
auto FunctionObject = [](int n){ return 5 * 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)); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <Poco/Process.h> | |
int main() | |
{ | |
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 | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment