diff --git a/CMakeLists.txt b/CMakeLists.txt index 15bb36a..b070773 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,8 @@ endif() add_subdirectory(src) -add_subdirectory(examples) +if (${ENABLE_EXAMPLES}) + add_subdirectory(examples) +endif() diff --git a/conanfile.py b/conanfile.py new file mode 100644 index 0000000..5434bc6 --- /dev/null +++ b/conanfile.py @@ -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") + diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index cb3c7f7..8ecdcef 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -9,4 +9,4 @@ FetchContent_Declare( FetchContent_MakeAvailable(spdlog) -add_subdirectory(shared_memory) \ No newline at end of file +add_subdirectory(shared_memory) diff --git a/examples/shared_memory/CMakeLists.txt b/examples/shared_memory/CMakeLists.txt index 14181ee..0f91ac2 100644 --- a/examples/shared_memory/CMakeLists.txt +++ b/examples/shared_memory/CMakeLists.txt @@ -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( @@ -18,4 +19,4 @@ endif() add_executable(shared_memory src/main.cpp) -target_link_libraries(shared_memory PRIVATE CPPUTILS2::cpputils2 spdlog::spdlog) \ No newline at end of file +target_link_libraries(shared_memory PRIVATE CPPUTILS2::cpputils2 spdlog::spdlog) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8c6556e..72ffedc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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" @@ -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) diff --git a/src/cmake/Cpputils2Config.cmake.in b/src/cmake/Cpputils2Config.cmake.in index 546ef01..07705c3 100644 --- a/src/cmake/Cpputils2Config.cmake.in +++ b/src/cmake/Cpputils2Config.cmake.in @@ -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) \ No newline at end of file +add_library(CPPUTILS2::cpputils2 ALIAS cpputils2) +check_required_components(cpputils2) diff --git a/test_package/CMakeLists.txt b/test_package/CMakeLists.txt new file mode 100644 index 0000000..006a891 --- /dev/null +++ b/test_package/CMakeLists.txt @@ -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) diff --git a/test_package/CMakeUserPresets.json b/test_package/CMakeUserPresets.json new file mode 100644 index 0000000..9bead93 --- /dev/null +++ b/test_package/CMakeUserPresets.json @@ -0,0 +1,9 @@ +{ + "version": 4, + "vendor": { + "conan": {} + }, + "include": [ + "build/gcc-11-x86_64-gnu17-release/generators/CMakePresets.json" + ] +} \ No newline at end of file diff --git a/test_package/conanfile.py b/test_package/conanfile.py new file mode 100644 index 0000000..4636cca --- /dev/null +++ b/test_package/conanfile.py @@ -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") diff --git a/test_package/src/example.cpp b/test_package/src/example.cpp new file mode 100644 index 0000000..5d8de04 --- /dev/null +++ b/test_package/src/example.cpp @@ -0,0 +1,16 @@ + + +#ifdef _WIN32 +#include +#else +#include +#endif + +#include +#include +#include + +int main(int , char**) { + std::cout << "cpputils2 installed!\n"; + return 0; +}