Skip to content

Commit

Permalink
(#22876) dispenso: Add new recipe
Browse files Browse the repository at this point in the history
* First sketch into adding dispenso/1.2.0 recipe

* Normalize conandata indentation

* Move to version 1.3.0

* Fix conandata

* Fix patches for 1.3.0

* Set C++ if no cppstd is set to support apple-clang in Conan 1

* Improve v1 check

* Better test package

* Add missing m system lib in linux

* Remove todo

* Update recipes/dispenso/all/conanfile.py

Co-authored-by: Uilian Ries <uilianries@gmail.com>

---------

Co-authored-by: Uilian Ries <uilianries@gmail.com>
  • Loading branch information
AbrilRBS and uilianries authored May 14, 2024
1 parent 6c1187c commit 99c3536
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 0 deletions.
9 changes: 9 additions & 0 deletions recipes/dispenso/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sources:
"1.3.0":
url: "https://github.com/facebookincubator/dispenso/archive/refs/tags/v1.3.0.tar.gz"
sha256: "824afe8d0d36bfd9bc9b1cbe9be89e7f3ed642a3612766d1c99d5f8dfc647c63"
patches:
"1.3.0":
- patch_file: "patches/1.3.0-001-unvendorize-concurrentqueue.patch"
patch_type: "conan"
patch_description: "Unvendorize concurrentqueue dependency"
118 changes: 118 additions & 0 deletions recipes/dispenso/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import copy, get, export_conandata_patches, apply_conandata_patches, rm, rmdir
from conan.tools.scm import Version
import os


required_conan_version = ">=1.53.0"


class DispensoPackage(ConanFile):
name = "dispenso"
description = "Dispenso is a library for working with sets of tasks in parallel"
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/facebookincubator/dispenso"
topics = ("tasks", "parallel", "threads")
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

@property
def _min_cppstd(self):
return 14

@property
def _compilers_minimum_version(self):
return {
"apple-clang": "10",
"clang": "7",
"gcc": "7",
"msvc": "191",
"Visual Studio": "15",
}

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

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

def export_sources(self):
export_conandata_patches(self)

def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
# Part of the public api in dispenso/thread_pool.h (and more), unvendorized
self.requires("concurrentqueue/1.0.4", transitive_headers=True)

def validate(self):
if self.settings.compiler.cppstd:
check_min_cppstd(self, self._min_cppstd)
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support."
)

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["DISPENSO_SHARED_LIB"] = self.options.shared
if self.settings.os == "Windows":
tc.preprocessor_definitions["NOMINMAX"] = 1
tc.variables["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = 1
if self.settings.get_safe("compiler.cppstd") is None:
# TODO: Remove once Conan 1 is deprecated, this is needed so apple-clang
# can compile, as it defaults to C++98
tc.variables["CMAKE_CXX_STANDARD"] = self._min_cppstd
tc.generate()
tc = CMakeDeps(self)
tc.generate()

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

def package(self):
copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()

rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "share"))
rm(self, "*.la", os.path.join(self.package_folder, "lib"))
rm(self, "*.pdb", os.path.join(self.package_folder, "lib"))
rm(self, "*.pdb", os.path.join(self.package_folder, "bin"))

def package_info(self):
self.cpp_info.libs = ["dispenso"]

self.cpp_info.set_property("cmake_file_name", "Dispenso")
self.cpp_info.set_property("cmake_target_name", "Dispenso::dispenso")

if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.extend(["pthread", "m"])

if self.settings.os == "Windows":
self.cpp_info.system_libs.extend(["synchronization", "winmm"])
self.cpp_info.defines.append("NOMINMAX")
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7af1b8a..05c86a6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -48,8 +48,6 @@ elseif (THREAD_SANITIZER)
add_link_options(-fsanitize=thread)
endif()

-set(CMAKE_CXX_STANDARD 14 CACHE STRING "the C++ standard to use for this project")
-
###########################################################
# Targets
add_subdirectory(dispenso)
diff --git a/dispenso/CMakeLists.txt b/dispenso/CMakeLists.txt
index 24a8c48..9231949 100644
--- a/dispenso/CMakeLists.txt
+++ b/dispenso/CMakeLists.txt
@@ -33,16 +33,15 @@ endif()
target_include_directories(dispenso
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/..>
- $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/third-party/moodycamel>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
- $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/dispenso/third-party/moodycamel>
)

set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
-target_link_libraries(dispenso PUBLIC Threads::Threads)
+find_package(concurrentqueue REQUIRED)
+target_link_libraries(dispenso PUBLIC Threads::Threads concurrentqueue::concurrentqueue)

check_cxx_source_compiles("
#include <atomic>
9 changes: 9 additions & 0 deletions recipes/dispenso/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.15)

project(test_package LANGUAGES CXX)

find_package(Dispenso REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE Dispenso::dispenso)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
26 changes: 26 additions & 0 deletions recipes/dispenso/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

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

def layout(self):
cmake_layout(self)

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

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
9 changes: 9 additions & 0 deletions recipes/dispenso/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <iostream>
#include "dispenso/parallel_for.h"


int main(void) {
dispenso::parallel_for(0, 5, [] (size_t j) {
std::cout << j << std::endl;
});
}
3 changes: 3 additions & 0 deletions recipes/dispenso/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.3.0":
folder: all

0 comments on commit 99c3536

Please sign in to comment.