Skip to content

Commit b17e9c6

Browse files
authored
Merge pull request #4 from yangosoft/feature/conan2
Initial conan2 support
2 parents ef69c96 + 47a6d27 commit b17e9c6

File tree

10 files changed

+129
-10
lines changed

10 files changed

+129
-10
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ endif()
4444

4545

4646
add_subdirectory(src)
47-
add_subdirectory(examples)
4847

48+
if (${ENABLE_EXAMPLES})
49+
add_subdirectory(examples)
50+
endif()
4951

conanfile.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from conan import ConanFile
2+
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps
3+
4+
5+
class cpputils2Recipe(ConanFile):
6+
name = "cpputils2"
7+
version = "1.0"
8+
#package_type = "library"
9+
10+
# Optional metadata
11+
license = "MIT"
12+
author = "Yangosoft yangosoft@protonmail.com"
13+
url = "https://github.com/yangosoft/cpputils2"
14+
description = "Set of utils in C++23"
15+
topics = ("shared memory", "mutex", "futex", "memory", "shared")
16+
17+
# Binary configuration
18+
settings = "os", "compiler", "build_type", "arch"
19+
options = {"shared": [True, False], "fPIC": [True, False]}
20+
default_options = {"shared": False, "fPIC": True}
21+
22+
# Sources are located in the same place as this recipe, copy them to the recipe
23+
exports_sources = "CMakeLists.txt", "src/*", "include/*", "examples/*"
24+
25+
#def config_options(self):
26+
#if self.settings.os == "Windows":
27+
#self.options.rm_safe("fPIC")
28+
29+
#def configure(self):
30+
#if self.options.shared:
31+
#self.options.rm_safe("fPIC")
32+
33+
#def layout(self):
34+
# cmake_layout(self)
35+
36+
def generate(self):
37+
deps = CMakeDeps(self)
38+
deps.generate()
39+
tc = CMakeToolchain(self)
40+
tc.generate()
41+
42+
def build(self):
43+
cmake = CMake(self)
44+
cmake.configure()
45+
cmake.build()
46+
47+
def package(self):
48+
cmake = CMake(self)
49+
cmake.install()
50+
51+
def package_info(self):
52+
#self.cpp_info.libs = ["cpputils2"]
53+
self.cpp_info.set_property("cmake_target_name", "CPPUTILS2::cpputils2")
54+
self.cpp_info.bindirs = []
55+
self.cpp_info.libdirs = []
56+
#self.cpp_info.set_property("cmake_find_mode", "none")
57+

examples/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ FetchContent_Declare(
99

1010
FetchContent_MakeAvailable(spdlog)
1111

12-
add_subdirectory(shared_memory)
12+
add_subdirectory(shared_memory)

examples/shared_memory/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ project(example_shared_memory VERSION 1.0.0 LANGUAGES CXX)
33

44

55
if(NOT TARGET CPPUTILS2::cpputils2)
6-
find_package(cpputils2 REQUIRED)
6+
message("Not target!")
7+
find_package(CPPUTILS2 REQUIRED)
78

89
Include(FetchContent)
910
FetchContent_Declare(
@@ -18,4 +19,4 @@ endif()
1819

1920
add_executable(shared_memory src/main.cpp)
2021

21-
target_link_libraries(shared_memory PRIVATE CPPUTILS2::cpputils2 spdlog::spdlog)
22+
target_link_libraries(shared_memory PRIVATE CPPUTILS2::cpputils2 spdlog::spdlog)

src/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ configure_package_config_file(
8484
)
8585

8686

87-
install (TARGETS cpputils2 EXPORT cpputils2-targets
87+
install (TARGETS cpputils2 EXPORT cpputils2-targets
8888
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
89-
INCLUDES DESTINATION include/cpputils2/utility)
89+
INCLUDES DESTINATION include/cpputils2)
9090

9191
export(EXPORT cpputils2-targets
9292
FILE "${CMAKE_CURRENT_BINARY_DIR}/CPPUTILS2Targets.cmake"
@@ -136,7 +136,7 @@ else()
136136
list(APPEND TEST_LIBS rt)
137137
endif()
138138

139-
target_link_libraries(test_cpputils2 PRIVATE cpputils2 ${TEST_LIBS})
139+
target_link_libraries(test_cpputils2 PRIVATE CPPUTILS2::cpputils2 ${TEST_LIBS})
140140
include(CTest)
141141

142142
#add_test(CppUtils2Test test_cpputils2 --gtest_output=xml)

src/cmake/Cpputils2Config.cmake.in

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
@PACKAGE_INIT@
22

3-
get_filename_component(utilities_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
3+
get_filename_component(cpputils2_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
44

55

66
include(CMakeFindDependencyMacro)
77

88

99
if(NOT TARGET CPPUTILS2::cpputils2)
10-
include("${CMAKE_CURRENT_LIST_DIR}/Cpputils2Targets.cmake")
10+
include("${CMAKE_CURRENT_LIST_DIR}/CPPUTILS2Targets.cmake")
1111
endif()
1212

13-
check_required_components(cpputils2)
13+
add_library(CPPUTILS2::cpputils2 ALIAS cpputils2)
14+
check_required_components(cpputils2)

test_package/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
project(PackageTest CXX)
3+
4+
find_package(CPPUTILS2 REQUIRED)
5+
6+
add_executable(example src/example.cpp)
7+
target_link_libraries(example PRIVATE CPPUTILS2::cpputils2)

test_package/CMakeUserPresets.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"version": 4,
3+
"vendor": {
4+
"conan": {}
5+
},
6+
"include": [
7+
"build/gcc-11-x86_64-gnu17-release/generators/CMakePresets.json"
8+
]
9+
}

test_package/conanfile.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import os
2+
3+
from conan import ConanFile
4+
from conan.tools.cmake import CMake, cmake_layout
5+
from conan.tools.build import can_run
6+
7+
8+
class cpputils2TestConan(ConanFile):
9+
settings = "os", "compiler", "build_type", "arch"
10+
generators = "CMakeDeps", "CMakeToolchain"
11+
12+
def requirements(self):
13+
self.requires(self.tested_reference_str)
14+
15+
def build(self):
16+
cmake = CMake(self)
17+
cmake.configure()
18+
cmake.build()
19+
20+
def layout(self):
21+
cmake_layout(self)
22+
23+
def test(self):
24+
if can_run(self):
25+
cmd = os.path.join(self.cpp.build.bindir, "example")
26+
self.run(cmd, env="conanrun")

test_package/src/example.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
3+
#ifdef _WIN32
4+
#include <cpputils2/win/shm/shm.hpp>
5+
#else
6+
#include <cpputils2/linux/shm/shm.hpp>
7+
#endif
8+
9+
#include <iostream>
10+
#include <vector>
11+
#include <string>
12+
13+
int main(int , char**) {
14+
std::cout << "cpputils2 installed!\n";
15+
return 0;
16+
}

0 commit comments

Comments
 (0)