Skip to content
Merged
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
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ endif()


add_subdirectory(src)
add_subdirectory(examples)

if (${ENABLE_EXAMPLES})
add_subdirectory(examples)
endif()

57 changes: 57 additions & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps


class cpputils2Recipe(ConanFile):
name = "cpputils2"
version = "1.0"
#package_type = "library"

# Optional metadata
license = "MIT"
author = "Yangosoft yangosoft@protonmail.com"
url = "https://github.com/yangosoft/cpputils2"
description = "Set of utils in C++23"
topics = ("shared memory", "mutex", "futex", "memory", "shared")

# Binary configuration
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}

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

#def config_options(self):
#if self.settings.os == "Windows":
#self.options.rm_safe("fPIC")

#def configure(self):
#if self.options.shared:
#self.options.rm_safe("fPIC")

#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 package_info(self):
#self.cpp_info.libs = ["cpputils2"]
self.cpp_info.set_property("cmake_target_name", "CPPUTILS2::cpputils2")
self.cpp_info.bindirs = []
self.cpp_info.libdirs = []
#self.cpp_info.set_property("cmake_find_mode", "none")

2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ FetchContent_Declare(

FetchContent_MakeAvailable(spdlog)

add_subdirectory(shared_memory)
add_subdirectory(shared_memory)
5 changes: 3 additions & 2 deletions examples/shared_memory/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ project(example_shared_memory VERSION 1.0.0 LANGUAGES CXX)


if(NOT TARGET CPPUTILS2::cpputils2)
find_package(cpputils2 REQUIRED)
message("Not target!")
find_package(CPPUTILS2 REQUIRED)

Include(FetchContent)
FetchContent_Declare(
Expand All @@ -18,4 +19,4 @@ endif()

add_executable(shared_memory src/main.cpp)

target_link_libraries(shared_memory PRIVATE CPPUTILS2::cpputils2 spdlog::spdlog)
target_link_libraries(shared_memory PRIVATE CPPUTILS2::cpputils2 spdlog::spdlog)
6 changes: 3 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ configure_package_config_file(
)


install (TARGETS cpputils2 EXPORT cpputils2-targets
install (TARGETS cpputils2 EXPORT cpputils2-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION include/cpputils2/utility)
INCLUDES DESTINATION include/cpputils2)

export(EXPORT cpputils2-targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/CPPUTILS2Targets.cmake"
Expand Down Expand Up @@ -136,7 +136,7 @@ else()
list(APPEND TEST_LIBS rt)
endif()

target_link_libraries(test_cpputils2 PRIVATE cpputils2 ${TEST_LIBS})
target_link_libraries(test_cpputils2 PRIVATE CPPUTILS2::cpputils2 ${TEST_LIBS})
include(CTest)

#add_test(CppUtils2Test test_cpputils2 --gtest_output=xml)
Expand Down
7 changes: 4 additions & 3 deletions src/cmake/Cpputils2Config.cmake.in
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
@PACKAGE_INIT@

get_filename_component(utilities_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(cpputils2_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)


include(CMakeFindDependencyMacro)


if(NOT TARGET CPPUTILS2::cpputils2)
include("${CMAKE_CURRENT_LIST_DIR}/Cpputils2Targets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/CPPUTILS2Targets.cmake")
endif()

check_required_components(cpputils2)
add_library(CPPUTILS2::cpputils2 ALIAS cpputils2)
check_required_components(cpputils2)
7 changes: 7 additions & 0 deletions test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.15)
project(PackageTest CXX)

find_package(CPPUTILS2 REQUIRED)

add_executable(example src/example.cpp)
target_link_libraries(example PRIVATE CPPUTILS2::cpputils2)
9 changes: 9 additions & 0 deletions test_package/CMakeUserPresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"version": 4,
"vendor": {
"conan": {}
},
"include": [
"build/gcc-11-x86_64-gnu17-release/generators/CMakePresets.json"
]
}
26 changes: 26 additions & 0 deletions test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os

from conan import ConanFile
from conan.tools.cmake import CMake, cmake_layout
from conan.tools.build import can_run


class cpputils2TestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeDeps", "CMakeToolchain"

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

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

def layout(self):
cmake_layout(self)

def test(self):
if can_run(self):
cmd = os.path.join(self.cpp.build.bindir, "example")
self.run(cmd, env="conanrun")
16 changes: 16 additions & 0 deletions test_package/src/example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@


#ifdef _WIN32
#include <cpputils2/win/shm/shm.hpp>
#else
#include <cpputils2/linux/shm/shm.hpp>
#endif

#include <iostream>
#include <vector>
#include <string>

int main(int , char**) {
std::cout << "cpputils2 installed!\n";
return 0;
}
Loading