-
-
Save caiorss/5067e2981488aff1b5765b02adbfdffc to your computer and use it in GitHub Desktop.
Sample CMake + Conan Package Manager
This file contains 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 =============== | |
# Automatically install conan packages if they are not installed. | |
# Assumptions: | |
# + The file conanfile.txt is in this directory | |
# + This CMakeLists.txt file is in the project ROOT directory. | |
# + The conan application is the project $PATH environment variable | |
# and accessible from command line. | |
#------------------------------------------------- | |
if(NOT EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake") | |
execute_process( | |
COMMAND conan install . --install-folder "${CMAKE_BINARY_DIR}" | |
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} | |
) | |
endif() | |
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | |
conan_basic_setup() | |
#========== Targets Configurations ============# | |
message(" [INFO] =>> CONAN_LIBS = ${CONAN_LIBS} " ) | |
# ==> 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 ${CONAN_LIBS}) | |
# Add target to run executable | |
add_custom_target(run-poco | |
COMMAND poco | |
DEPENDS poco | |
WORKING_DIRECTORY ${CMAKE_PROJECT_DIR} | |
) | |
add_custom_target(run-gtest | |
COMMAND agtest | |
DEPENDS agtest | |
WORKING_DIRECTORY ${CMAKE_PROJECT_DIR} | |
) | |
install(TARGETS poco agtest DESTINATION ./bin) |
This file contains 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
[requires] | |
Poco/1.9.0@pocoproject/stable | |
gtest/1.8.1@bincrafters/stable | |
[generators] | |
cmake | |
[options] | |
Poco:shared=False |
This file contains 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 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