Skip to content

Added ccache examples #191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions examples/tools/ccache/advanced/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 3.15)
project(ccache_demo)

add_executable(ccache_demo src/main.cpp)

find_package(fmt REQUIRED)
find_package(cpr REQUIRED)
find_package(RapidJSON REQUIRED)

target_link_libraries(ccache_demo
PRIVATE
cpr::cpr
fmt::fmt
rapidjson
)

install(TARGETS ccache_demo DESTINATION "."
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
)
37 changes: 37 additions & 0 deletions examples/tools/ccache/advanced/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps


class CCacheDemoRecipe(ConanFile):
name = "ccache_demo"
version = "1.0"
package_type = "application"

# Binary configuration
settings = "os", "compiler", "build_type", "arch"

# Sources are located in the same place as this recipe, copy them to the recipe
exports_sources = "CMakeLists.txt", "src/*"

def layout(self):
cmake_layout(self)

def generate(self):
deps = CMakeDeps(self)
deps.generate()
tc = CMakeToolchain(self)
tc.generate()

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
cmake = CMake(self)
cmake.install()

def requirements(self):
self.requires("cpr/1.11.2")
self.requires("fmt/11.2.0")
self.requires("rapidjson/1.1.0")
30 changes: 30 additions & 0 deletions examples/tools/ccache/advanced/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <cpr/cpr.h>
#include <fmt/core.h>
#include <rapidjson/document.h>


int main() {
cpr::Response r = cpr::Get(cpr::Url{"https://api.github.com/repos/conan-io/conan"});
if (r.status_code != 200) {
fmt::print("Failed to fetch data: {}\n", r.status_code);
return 1;
}

rapidjson::Document doc;
if (doc.Parse(r.text.c_str()).HasParseError()) {
fmt::print("Error parsing JSON response\n");
return 1;
}

if (doc.HasMember("full_name") && doc["full_name"].IsString()) {
fmt::print("Repository: {}\n", doc["full_name"].GetString());
}
if (doc.HasMember("stargazers_count") && doc["stargazers_count"].IsInt()) {
fmt::print("Stars: {}\n", doc["stargazers_count"].GetInt());
}
if (doc.HasMember("forks_count") && doc["forks_count"].IsInt()) {
fmt::print("Forks: {}\n", doc["forks_count"].GetInt());
}

return 0;
}
14 changes: 14 additions & 0 deletions examples/tools/ccache/advanced/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os
from conan import ConanFile
from conan.tools.build import can_run


class pkgTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"

def requirements(self):
self.requires(self.tested_reference_str)

def test(self):
if can_run(self):
self.run("ccache_demo", env="conanrun")
22 changes: 22 additions & 0 deletions examples/tools/ccache/basic/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 3.15)

project(basic CXX)

find_program(CCACHE_PROGRAM NAMES ccache)
if(CCACHE_PROGRAM)
message(STATUS "ccache found: ${CCACHE_PROGRAM}, enabling compiler launcher.")
# Set the compiler launcher property on the targets
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_PROGRAM} CACHE FILEPATH "CXX compiler cache used")
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_PROGRAM} CACHE FILEPATH "C compiler cache used")
else()
message(WARNING "ccache not found. Compiler cache disabled.")
endif()


add_executable(basic src/basic.cpp src/main.cpp)

install(TARGETS basic DESTINATION "."
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
)
120 changes: 120 additions & 0 deletions examples/tools/ccache/basic/src/basic.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#include <iostream>
#include "basic.h"



void basic(){


#ifdef NDEBUG
std::cout << "basic/1.0: Hello World Release!\n";
#else
std::cout << "basic/1.0: Hello World Debug!\n";
#endif

// ARCHITECTURES
#ifdef _M_X64
std::cout << " basic/1.0: _M_X64 defined\n";
#endif

#ifdef _M_IX86
std::cout << " basic/1.0: _M_IX86 defined\n";
#endif

#ifdef _M_ARM64
std::cout << " basic/1.0: _M_ARM64 defined\n";
#endif

#if __i386__
std::cout << " basic/1.0: __i386__ defined\n";
#endif

#if __x86_64__
std::cout << " basic/1.0: __x86_64__ defined\n";
#endif

#if __aarch64__
std::cout << " basic/1.0: __aarch64__ defined\n";
#endif

// Libstdc++
#if defined _GLIBCXX_USE_CXX11_ABI
std::cout << " basic/1.0: _GLIBCXX_USE_CXX11_ABI "<< _GLIBCXX_USE_CXX11_ABI << "\n";
#endif

// MSVC runtime
#if defined(_DEBUG)
#if defined(_MT) && defined(_DLL)
std::cout << " basic/1.0: MSVC runtime: MultiThreadedDebugDLL\n";
#elif defined(_MT)
std::cout << " basic/1.0: MSVC runtime: MultiThreadedDebug\n";
#endif
#else
#if defined(_MT) && defined(_DLL)
std::cout << " basic/1.0: MSVC runtime: MultiThreadedDLL\n";
#elif defined(_MT)
std::cout << " basic/1.0: MSVC runtime: MultiThreaded\n";
#endif
#endif

// COMPILER VERSIONS
#if _MSC_VER
std::cout << " basic/1.0: _MSC_VER" << _MSC_VER<< "\n";
#endif

#if _MSVC_LANG
std::cout << " basic/1.0: _MSVC_LANG" << _MSVC_LANG<< "\n";
#endif

#if __cplusplus
std::cout << " basic/1.0: __cplusplus" << __cplusplus<< "\n";
#endif

#if __INTEL_COMPILER
std::cout << " basic/1.0: __INTEL_COMPILER" << __INTEL_COMPILER<< "\n";
#endif

#if __GNUC__
std::cout << " basic/1.0: __GNUC__" << __GNUC__<< "\n";
#endif

#if __GNUC_MINOR__
std::cout << " basic/1.0: __GNUC_MINOR__" << __GNUC_MINOR__<< "\n";
#endif

#if __clang_major__
std::cout << " basic/1.0: __clang_major__" << __clang_major__<< "\n";
#endif

#if __clang_minor__
std::cout << " basic/1.0: __clang_minor__" << __clang_minor__<< "\n";
#endif

#if __apple_build_version__
std::cout << " basic/1.0: __apple_build_version__" << __apple_build_version__<< "\n";
#endif

// SUBSYSTEMS

#if __MSYS__
std::cout << " basic/1.0: __MSYS__" << __MSYS__<< "\n";
#endif

#if __MINGW32__
std::cout << " basic/1.0: __MINGW32__" << __MINGW32__<< "\n";
#endif

#if __MINGW64__
std::cout << " basic/1.0: __MINGW64__" << __MINGW64__<< "\n";
#endif

#if __CYGWIN__
std::cout << " basic/1.0: __CYGWIN__" << __CYGWIN__<< "\n";
#endif
}

void basic_print_vector(const std::vector<std::string> &strings) {
for(std::vector<std::string>::const_iterator it = strings.begin(); it != strings.end(); ++it) {
std::cout << "basic/1.0 " << *it << std::endl;
}
}
14 changes: 14 additions & 0 deletions examples/tools/ccache/basic/src/basic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include <vector>
#include <string>


#ifdef _WIN32
#define BASIC_EXPORT __declspec(dllexport)
#else
#define BASIC_EXPORT
#endif

BASIC_EXPORT void basic();
BASIC_EXPORT void basic_print_vector(const std::vector<std::string> &strings);
12 changes: 12 additions & 0 deletions examples/tools/ccache/basic/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "basic.h"
#include <vector>
#include <string>

int main() {
basic();

std::vector<std::string> vec;
vec.push_back("test_package");

basic_print_vector(vec);
}