add abseil recipe
This commit is contained in:
52
recipes/abseil/all/test_package/CMakeLists.txt
Normal file
52
recipes/abseil/all/test_package/CMakeLists.txt
Normal file
@@ -0,0 +1,52 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
project(test_package LANGUAGES CXX)
|
||||
|
||||
find_package(absl REQUIRED CONFIG)
|
||||
|
||||
# Test components
|
||||
add_executable(${PROJECT_NAME} test_package.cpp)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE absl::strings absl::flat_hash_map absl::flat_hash_set absl::int128 absl::time)
|
||||
# Abseil now requires at least C++14 since 20230125.0
|
||||
if(absl_VERSION VERSION_LESS "20230125.0")
|
||||
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
|
||||
else()
|
||||
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
|
||||
endif()
|
||||
|
||||
if(cxx_std_14 IN_LIST CMAKE_CXX_COMPILE_FEATURES)
|
||||
add_executable(${PROJECT_NAME}_14 test_package.cpp)
|
||||
target_link_libraries(${PROJECT_NAME}_14 PRIVATE absl::strings absl::flat_hash_map absl::flat_hash_set absl::int128 absl::time)
|
||||
target_compile_features(${PROJECT_NAME}_14 PRIVATE cxx_std_14)
|
||||
endif()
|
||||
if(cxx_std_17 IN_LIST CMAKE_CXX_COMPILE_FEATURES)
|
||||
add_executable(${PROJECT_NAME}_17 test_package.cpp)
|
||||
target_link_libraries(${PROJECT_NAME}_17 PRIVATE absl::strings absl::flat_hash_map absl::flat_hash_set absl::int128 absl::time)
|
||||
target_compile_features(${PROJECT_NAME}_17 PRIVATE cxx_std_17)
|
||||
endif()
|
||||
# old abseil used std::result_of (which was removed in C++20) https://github.com/abseil/abseil-cpp/issues/649
|
||||
if(CXX20_SUPPORTED)
|
||||
if(cxx_std_20 IN_LIST CMAKE_CXX_COMPILE_FEATURES)
|
||||
add_executable(${PROJECT_NAME}_20 test_package.cpp)
|
||||
target_link_libraries(${PROJECT_NAME}_20 PRIVATE absl::strings absl::flat_hash_map absl::flat_hash_set absl::int128 absl::time)
|
||||
target_compile_features(${PROJECT_NAME}_20 PRIVATE cxx_std_20)
|
||||
endif()
|
||||
if(cxx_std_23 IN_LIST CMAKE_CXX_COMPILE_FEATURES)
|
||||
add_executable(${PROJECT_NAME}_23 test_package.cpp)
|
||||
target_link_libraries(${PROJECT_NAME}_23 PRIVATE absl::strings absl::flat_hash_map absl::flat_hash_set absl::int128 absl::time)
|
||||
target_compile_features(${PROJECT_NAME}_23 PRIVATE cxx_std_23)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Test also (unofficial) global target
|
||||
add_executable(${PROJECT_NAME}_global test_package.cpp)
|
||||
if(TARGET abseil::abseil)
|
||||
target_link_libraries(${PROJECT_NAME}_global PRIVATE abseil::abseil)
|
||||
else()
|
||||
target_link_libraries(${PROJECT_NAME}_global PRIVATE absl::absl)
|
||||
endif()
|
||||
# Abseil now requires at least C++14 since 20230125.0
|
||||
if(absl_VERSION VERSION_LESS "20230125.0")
|
||||
target_compile_features(${PROJECT_NAME}_global PRIVATE cxx_std_11)
|
||||
else()
|
||||
target_compile_features(${PROJECT_NAME}_global PRIVATE cxx_std_14)
|
||||
endif()
|
||||
33
recipes/abseil/all/test_package/conanfile.py
Normal file
33
recipes/abseil/all/test_package/conanfile.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from conan import ConanFile
|
||||
from conan.tools.build import cross_building
|
||||
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
|
||||
from conan.tools.scm import Version
|
||||
import os
|
||||
|
||||
|
||||
class TestPackageConan(ConanFile):
|
||||
settings = "os", "arch", "compiler", "build_type"
|
||||
generators = "CMakeDeps", "VirtualRunEnv"
|
||||
|
||||
def requirements(self):
|
||||
self.requires(self.tested_reference_str)
|
||||
|
||||
def layout(self):
|
||||
cmake_layout(self)
|
||||
|
||||
def generate(self):
|
||||
tc = CMakeToolchain(self)
|
||||
tc.variables["CXX20_SUPPORTED"] = Version(self.dependencies["abseil"].ref.version) > "20210324.2"
|
||||
tc.generate()
|
||||
|
||||
def build(self):
|
||||
cmake = CMake(self)
|
||||
cmake.configure()
|
||||
cmake.build()
|
||||
|
||||
def test(self):
|
||||
if not cross_building(self):
|
||||
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
|
||||
self.run(f"{bin_path} -s", env="conanrun")
|
||||
bin_global_path = os.path.join(self.cpp.build.bindirs[0], "test_package_global")
|
||||
self.run(f"{bin_global_path} -s", env="conanrun")
|
||||
56
recipes/abseil/all/test_package/test_package.cpp
Normal file
56
recipes/abseil/all/test_package/test_package.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "absl/strings/str_split.h"
|
||||
#include "absl/container/flat_hash_map.h"
|
||||
#include "absl/container/flat_hash_set.h"
|
||||
#include "absl/numeric/int128.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "absl/types/variant.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
absl::flat_hash_set<std::string> set1;
|
||||
absl::flat_hash_map<int, std::string> map1;
|
||||
absl::flat_hash_set<std::string> set2 = {
|
||||
{"huey"},
|
||||
{"dewey"},
|
||||
{"louie"},
|
||||
};
|
||||
absl::flat_hash_map<int, std::string> map2 = {
|
||||
{1, "huey"},
|
||||
{2, "dewey"},
|
||||
{3, "louie"},
|
||||
};
|
||||
absl::flat_hash_set<std::string> set3(set2);
|
||||
absl::flat_hash_map<int, std::string> map3(map2);
|
||||
|
||||
absl::flat_hash_set<std::string> set4;
|
||||
set4 = set3;
|
||||
absl::flat_hash_map<int, std::string> map4;
|
||||
map4 = map3;
|
||||
|
||||
absl::flat_hash_set<std::string> set5(std::move(set4));
|
||||
absl::flat_hash_map<int, std::string> map5(std::move(map4));
|
||||
absl::flat_hash_set<std::string> set6;
|
||||
set6 = std::move(set5);
|
||||
absl::flat_hash_map<int, std::string> map6;
|
||||
map6 = std::move(map5);
|
||||
|
||||
const absl::uint128 big = absl::Uint128Max();
|
||||
std::cout << absl::StrCat("Arg ", "foo", "\n");
|
||||
std::vector<std::string> v = absl::StrSplit("a,b,,c", ',');
|
||||
|
||||
absl::Time t1 = absl::Now();
|
||||
absl::Time t2 = absl::Time();
|
||||
absl::Time t3 = absl::UnixEpoch();
|
||||
|
||||
absl::variant<int> v1 = absl::variant<int>();
|
||||
absl::bad_variant_access e1;
|
||||
|
||||
std::string const year = absl::FormatTime("%Y", absl::Now(), absl::UTCTimeZone());
|
||||
std::cout << "year " << year << std::endl;
|
||||
}
|
||||
Reference in New Issue
Block a user