Skip to content

Commit

Permalink
Fix compilation in Windows and Macos
Browse files Browse the repository at this point in the history
  • Loading branch information
AbrilRBS committed Nov 14, 2024
1 parent 634a938 commit c226148
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 44 deletions.
5 changes: 5 additions & 0 deletions recipes/libq/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ sources:
"0.0.0.cci.20180504":
url: "https://github.com/grantila/q/archive/0117848bb3e6f0b130b546bc5851caf5f95f8b7e.zip"
sha256: "f5e51c1abbbec8e6da2155740917d7f1f60628745363ebd4e2aadfd7ef2ff682"
patches:
"0.0.0.cci.20180504":
- patch_file: "patches/0001-cmake-remove-hardcoded-flags.patch"
patch_description: "Remove hardcoded flags from CMakeLists.txt"
patch_type: "conan"
48 changes: 19 additions & 29 deletions recipes/libq/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import copy, get, rm, rmdir
from conan.tools.files import copy, get, rm, rmdir, export_conandata_patches, apply_conandata_patches
from conan.tools.microsoft import is_msvc
from conan.tools.scm import Version
from conan.tools.apple import fix_apple_shared_install_name

required_conan_version = ">=1.53.0"
required_conan_version = ">=2.1"

class libqConan(ConanFile):
name = "libq"
Expand All @@ -28,45 +29,28 @@ class libqConan(ConanFile):
"fPIC": True,
}

@property
def _min_cppstd(self):
return 17

@property
def _compilers_minimum_version(self):
return {
"apple-clang": "10",
"clang": "7",
"gcc": "7"
}

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
implements = ["auto_shared_fpic"]

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

def export_sources(self):
export_conandata_patches(self)

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."
)
if self.settings.os in ["Windows"]:
# FIXME: Test package is not capable to find q.lib
raise ConanInvalidConfiguration(f"{self.ref} Conan recipe is not supported in Windows. Contributions are welcome.")
check_min_cppstd(self, 11)
if self.settings.os == "Windows" and self.options.shared:
# It exports no symbols, so it can't be used as a shared library
raise ConanInvalidConfiguration("Does not support shared libraries on Windows")

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

def generate(self):
tc = CMakeToolchain(self)
tc.variables["q_BUILD_TESTS"] = False
tc.variables["q_BUILD_APPS"] = False

tc.generate()

def build(self):
Expand All @@ -88,11 +72,17 @@ def package(self):
rm(self, "*.pdb", os.path.join(self.package_folder, "bin"))

def package_info(self):
self.cpp_info.libs = ["q"]
suffix = ""
if is_msvc(self) and self.settings.build_type == "Debug":
suffix = "d"
self.cpp_info.libs = ["q" + suffix]
self.cpp_info.set_property("cmake_file_name", "libq")
self.cpp_info.set_property("cmake_target_name", "libq::libq")

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

if is_msvc(self):
self.cpp_info.cxxflags.append("/bigobj")
17 changes: 2 additions & 15 deletions recipes/libq/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
#include <cstdlib>
#include <q/lib.hpp>
#include <q/blocking_dispatcher.hpp>
#include <q/execution_context.hpp>
#include <q/promise.hpp>
#include <iostream>
#include <thread>


int main(void) {
q::initialize();

auto ctx = q::make_execution_context<q::blocking_dispatcher>("test");

std::thread t([&ctx](){
ctx->dispatcher()->start();
});
std::this_thread::yield();
ctx->dispatcher()->terminate(q::termination::annihilate);
ctx->dispatcher()->await_termination();
t.join();

std::cout << "q initialized correctly" << std::endl;
q::uninitialize();
return EXIT_SUCCESS;
}

0 comments on commit c226148

Please sign in to comment.