Skip to content

Commit 35ca80d

Browse files
committed
Added ccache examples
1 parent 13c1bd7 commit 35ca80d

File tree

8 files changed

+270
-0
lines changed

8 files changed

+270
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
project(ccache_demo)
3+
4+
add_executable(ccache_demo src/main.cpp)
5+
6+
find_package(fmt REQUIRED)
7+
find_package(cpr REQUIRED)
8+
find_package(RapidJSON REQUIRED)
9+
10+
target_link_libraries(ccache_demo
11+
PRIVATE
12+
cpr::cpr
13+
fmt::fmt
14+
rapidjson
15+
)
16+
17+
install(TARGETS ccache_demo DESTINATION "."
18+
RUNTIME DESTINATION bin
19+
ARCHIVE DESTINATION lib
20+
LIBRARY DESTINATION lib
21+
)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from conan import ConanFile
2+
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps
3+
4+
5+
class CCacheDemoRecipe(ConanFile):
6+
name = "ccache_demo"
7+
version = "1.0"
8+
package_type = "application"
9+
10+
# Binary configuration
11+
settings = "os", "compiler", "build_type", "arch"
12+
13+
# Sources are located in the same place as this recipe, copy them to the recipe
14+
exports_sources = "CMakeLists.txt", "src/*"
15+
16+
def layout(self):
17+
cmake_layout(self)
18+
19+
def generate(self):
20+
deps = CMakeDeps(self)
21+
deps.generate()
22+
tc = CMakeToolchain(self)
23+
tc.generate()
24+
25+
def build(self):
26+
cmake = CMake(self)
27+
cmake.configure()
28+
cmake.build()
29+
30+
def package(self):
31+
cmake = CMake(self)
32+
cmake.install()
33+
34+
def requirements(self):
35+
self.requires("cpr/1.11.2")
36+
self.requires("fmt/11.2.0")
37+
self.requires("rapidjson/1.1.0")
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <cpr/cpr.h>
2+
#include <fmt/core.h>
3+
#include <rapidjson/document.h>
4+
5+
6+
int main() {
7+
cpr::Response r = cpr::Get(cpr::Url{"https://api.github.com/repos/conan-io/conan"});
8+
if (r.status_code != 200) {
9+
fmt::print("Failed to fetch data: {}\n", r.status_code);
10+
return 1;
11+
}
12+
13+
rapidjson::Document doc;
14+
if (doc.Parse(r.text.c_str()).HasParseError()) {
15+
fmt::print("Error parsing JSON response\n");
16+
return 1;
17+
}
18+
19+
if (doc.HasMember("full_name") && doc["full_name"].IsString()) {
20+
fmt::print("Repository: {}\n", doc["full_name"].GetString());
21+
}
22+
if (doc.HasMember("stargazers_count") && doc["stargazers_count"].IsInt()) {
23+
fmt::print("Stars: {}\n", doc["stargazers_count"].GetInt());
24+
}
25+
if (doc.HasMember("forks_count") && doc["forks_count"].IsInt()) {
26+
fmt::print("Forks: {}\n", doc["forks_count"].GetInt());
27+
}
28+
29+
return 0;
30+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import os
2+
from conan import ConanFile
3+
from conan.tools.build import can_run
4+
5+
6+
class pkgTestConan(ConanFile):
7+
settings = "os", "compiler", "build_type", "arch"
8+
9+
def requirements(self):
10+
self.requires(self.tested_reference_str)
11+
12+
def test(self):
13+
if can_run(self):
14+
self.run("ccache_demo", env="conanrun")
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
3+
project(basic CXX)
4+
5+
find_program(CCACHE_PROGRAM NAMES ccache)
6+
if(CCACHE_PROGRAM)
7+
message(STATUS "ccache found: ${CCACHE_PROGRAM}, enabling compiler launcher.")
8+
# Set the compiler launcher property on the targets
9+
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_PROGRAM} CACHE FILEPATH "CXX compiler cache used")
10+
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_PROGRAM} CACHE FILEPATH "C compiler cache used")
11+
else()
12+
message(WARNING "ccache not found. Compiler cache disabled.")
13+
endif()
14+
15+
16+
add_executable(basic src/basic.cpp src/main.cpp)
17+
18+
install(TARGETS basic DESTINATION "."
19+
RUNTIME DESTINATION bin
20+
ARCHIVE DESTINATION lib
21+
LIBRARY DESTINATION lib
22+
)
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#include <iostream>
2+
#include "basic.h"
3+
4+
5+
6+
void basic(){
7+
8+
9+
#ifdef NDEBUG
10+
std::cout << "basic/1.0: Hello World Release!\n";
11+
#else
12+
std::cout << "basic/1.0: Hello World Debug!\n";
13+
#endif
14+
15+
// ARCHITECTURES
16+
#ifdef _M_X64
17+
std::cout << " basic/1.0: _M_X64 defined\n";
18+
#endif
19+
20+
#ifdef _M_IX86
21+
std::cout << " basic/1.0: _M_IX86 defined\n";
22+
#endif
23+
24+
#ifdef _M_ARM64
25+
std::cout << " basic/1.0: _M_ARM64 defined\n";
26+
#endif
27+
28+
#if __i386__
29+
std::cout << " basic/1.0: __i386__ defined\n";
30+
#endif
31+
32+
#if __x86_64__
33+
std::cout << " basic/1.0: __x86_64__ defined\n";
34+
#endif
35+
36+
#if __aarch64__
37+
std::cout << " basic/1.0: __aarch64__ defined\n";
38+
#endif
39+
40+
// Libstdc++
41+
#if defined _GLIBCXX_USE_CXX11_ABI
42+
std::cout << " basic/1.0: _GLIBCXX_USE_CXX11_ABI "<< _GLIBCXX_USE_CXX11_ABI << "\n";
43+
#endif
44+
45+
// MSVC runtime
46+
#if defined(_DEBUG)
47+
#if defined(_MT) && defined(_DLL)
48+
std::cout << " basic/1.0: MSVC runtime: MultiThreadedDebugDLL\n";
49+
#elif defined(_MT)
50+
std::cout << " basic/1.0: MSVC runtime: MultiThreadedDebug\n";
51+
#endif
52+
#else
53+
#if defined(_MT) && defined(_DLL)
54+
std::cout << " basic/1.0: MSVC runtime: MultiThreadedDLL\n";
55+
#elif defined(_MT)
56+
std::cout << " basic/1.0: MSVC runtime: MultiThreaded\n";
57+
#endif
58+
#endif
59+
60+
// COMPILER VERSIONS
61+
#if _MSC_VER
62+
std::cout << " basic/1.0: _MSC_VER" << _MSC_VER<< "\n";
63+
#endif
64+
65+
#if _MSVC_LANG
66+
std::cout << " basic/1.0: _MSVC_LANG" << _MSVC_LANG<< "\n";
67+
#endif
68+
69+
#if __cplusplus
70+
std::cout << " basic/1.0: __cplusplus" << __cplusplus<< "\n";
71+
#endif
72+
73+
#if __INTEL_COMPILER
74+
std::cout << " basic/1.0: __INTEL_COMPILER" << __INTEL_COMPILER<< "\n";
75+
#endif
76+
77+
#if __GNUC__
78+
std::cout << " basic/1.0: __GNUC__" << __GNUC__<< "\n";
79+
#endif
80+
81+
#if __GNUC_MINOR__
82+
std::cout << " basic/1.0: __GNUC_MINOR__" << __GNUC_MINOR__<< "\n";
83+
#endif
84+
85+
#if __clang_major__
86+
std::cout << " basic/1.0: __clang_major__" << __clang_major__<< "\n";
87+
#endif
88+
89+
#if __clang_minor__
90+
std::cout << " basic/1.0: __clang_minor__" << __clang_minor__<< "\n";
91+
#endif
92+
93+
#if __apple_build_version__
94+
std::cout << " basic/1.0: __apple_build_version__" << __apple_build_version__<< "\n";
95+
#endif
96+
97+
// SUBSYSTEMS
98+
99+
#if __MSYS__
100+
std::cout << " basic/1.0: __MSYS__" << __MSYS__<< "\n";
101+
#endif
102+
103+
#if __MINGW32__
104+
std::cout << " basic/1.0: __MINGW32__" << __MINGW32__<< "\n";
105+
#endif
106+
107+
#if __MINGW64__
108+
std::cout << " basic/1.0: __MINGW64__" << __MINGW64__<< "\n";
109+
#endif
110+
111+
#if __CYGWIN__
112+
std::cout << " basic/1.0: __CYGWIN__" << __CYGWIN__<< "\n";
113+
#endif
114+
}
115+
116+
void basic_print_vector(const std::vector<std::string> &strings) {
117+
for(std::vector<std::string>::const_iterator it = strings.begin(); it != strings.end(); ++it) {
118+
std::cout << "basic/1.0 " << *it << std::endl;
119+
}
120+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
3+
#include <vector>
4+
#include <string>
5+
6+
7+
#ifdef _WIN32
8+
#define BASIC_EXPORT __declspec(dllexport)
9+
#else
10+
#define BASIC_EXPORT
11+
#endif
12+
13+
BASIC_EXPORT void basic();
14+
BASIC_EXPORT void basic_print_vector(const std::vector<std::string> &strings);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "basic.h"
2+
#include <vector>
3+
#include <string>
4+
5+
int main() {
6+
basic();
7+
8+
std::vector<std::string> vec;
9+
vec.push_back("test_package");
10+
11+
basic_print_vector(vec);
12+
}

0 commit comments

Comments
 (0)