diff --git a/recipes/miniscript/all/CMakeLists.txt b/recipes/miniscript/all/CMakeLists.txt index b203ccd24f5f1..0e1ecf170face 100644 --- a/recipes/miniscript/all/CMakeLists.txt +++ b/recipes/miniscript/all/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.8) -project(miniscript LANGUAGES CXX) +project(Miniscript LANGUAGES C CXX) set(MINISCRIPT_SRC ${MINISCRIPT_SRC_DIR}/MiniScript-cpp/src/MiniScript/Dictionary.cpp @@ -40,25 +40,51 @@ set(MINISCRIPT_INC ) -add_library(miniscript ${MINISCRIPT_SRC}) -target_include_directories(miniscript PRIVATE ${MINISCRIPT_SRC_DIR}/MiniScript-cpp/src) -set_target_properties(miniscript PROPERTIES +add_library(miniscript-cpp ${MINISCRIPT_SRC}) +target_include_directories(miniscript-cpp PRIVATE ${MINISCRIPT_SRC_DIR}/MiniScript-cpp/src) +set_target_properties(miniscript-cpp PROPERTIES PUBLIC_HEADER "${MINISCRIPT_INC}" WINDOWS_EXPORT_ALL_SYMBOLS ON C_EXTENSIONS OFF ) -target_compile_features(miniscript PRIVATE cxx_std_11) +target_compile_features(miniscript-cpp PRIVATE cxx_std_11) if(MSVC) - target_compile_options(miniscript PRIVATE /EHsc /wd4068) + target_compile_options(miniscript-cpp PRIVATE /EHsc /wd4068) endif() find_library(LIBM m) -target_link_libraries(miniscript PRIVATE $<$:${LIBM}>) +target_link_libraries(miniscript-cpp PRIVATE $<$:${LIBM}>) + +set(MINICMD_HEADERS + ${MINISCRIPT_SRC_DIR}/MiniScript-cpp/src/OstreamSupport.h + ${MINISCRIPT_SRC_DIR}/MiniScript-cpp/src/ShellIntrinsics.h + ${MINISCRIPT_SRC_DIR}/MiniScript-cpp/src/editline/editline.h + ${MINISCRIPT_SRC_DIR}/MiniScript-cpp/src/editline/unix.h +) + +if(NOT WIN32) + set(EDITLINE_SRC + ${MINISCRIPT_SRC_DIR}/MiniScript-cpp/src/editline/complete.c + ${MINISCRIPT_SRC_DIR}/MiniScript-cpp/src/editline/editline.c + ${MINISCRIPT_SRC_DIR}/MiniScript-cpp/src/editline/sysunix.c + ) +endif() + +add_executable(minicmd + ${MINISCRIPT_SRC_DIR}/MiniScript-cpp/src/main.cpp + ${MINISCRIPT_SRC_DIR}/MiniScript-cpp/src/OstreamSupport.cpp + ${MINISCRIPT_SRC_DIR}/MiniScript-cpp/src/ShellIntrinsics.cpp + ${EDITLINE_SRC} + ${MINICMD_HEADERS} +) +target_include_directories(minicmd PRIVATE ${MINISCRIPT_SRC_DIR}/MiniScript-cpp/src/editline) +target_link_libraries(minicmd PRIVATE miniscript-cpp) +target_compile_features(minicmd PRIVATE cxx_std_11) include(GNUInstallDirs) install( - TARGETS miniscript + TARGETS miniscript-cpp minicmd RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} diff --git a/recipes/miniscript/all/conandata.yml b/recipes/miniscript/all/conandata.yml index bafad0fb939fc..3d75c2a6adb07 100644 --- a/recipes/miniscript/all/conandata.yml +++ b/recipes/miniscript/all/conandata.yml @@ -1,4 +1,17 @@ sources: + "1.6.2": + url: "https://github.com/JoeStrout/miniscript/archive/refs/tags/v1.6.2.tar.gz" + sha256: "62df0ce8faca21db588ed5f0abe020a41602c8fc02376f6b2385869863acbefd" "1.5.1": url: "https://github.com/JoeStrout/miniscript/archive/172bea8e762c96b1b2a5ea743228ff6a58702cc3.tar.gz" sha256: "a82ac634621657e14f046b6fd08dbc624e8e9890b646573edef454a2e540a1e2" +patches: + "1.6.2": + - patch_file: "patches/1.6.2-0001-fix-install.patch" + patch_description: "fix install destinations" + patch_type: "portability" + patch_source: "https://github.com/JoeStrout/miniscript/pull/184" + - patch_file: "patches/1.6.2-0002-remove-bit.patch" + patch_description: "remove unused bit header" + patch_type: "portability" + patch_source: "https://github.com/JoeStrout/miniscript/pull/145" diff --git a/recipes/miniscript/all/conanfile.py b/recipes/miniscript/all/conanfile.py index d85d56bf3dc9b..3a00d6386a95a 100644 --- a/recipes/miniscript/all/conanfile.py +++ b/recipes/miniscript/all/conanfile.py @@ -1,7 +1,10 @@ from conan import ConanFile -from conan.tools.files import get, copy +from conan.tools.files import get, copy, apply_conandata_patches, export_conandata_patches from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout - +from conan.errors import ConanInvalidConfiguration +from conan.tools.build import check_min_cppstd +from conan.tools.scm import Version +from conan.tools.microsoft import is_msvc import os required_conan_version = ">=1.53.0" @@ -14,6 +17,7 @@ class MiniscriptConan(ConanFile): homepage = "https://github.com/JoeStrout/miniscript" topics = ("script", "embedded", "programming-language") settings = "os", "arch", "compiler", "build_type" + package_type = "library" options = { "shared": [True, False], "fPIC": [True, False], @@ -24,6 +28,25 @@ class MiniscriptConan(ConanFile): } exports_sources = ["CMakeLists.txt"] + @property + def _min_cppstd(self): + return "11" if Version(self.version) < "1.6.2" else "17" + + @property + def _compilers_minimum_version(self): + return { + "17": { + "gcc": "8", + "clang": "7", + "apple-clang": "12", + "Visual Studio": "16", + "msvc": "192", + }, + }.get(self._min_cppstd, {}) + + def export_sources(self): + export_conandata_patches(self) + def config_options(self): if self.settings.os == 'Windows': del self.options.fPIC @@ -35,17 +58,37 @@ def configure(self): def layout(self): cmake_layout(self, src_folder="src") + def validate(self): + # miniscript doesn't declare export symbols with __declspec. + if is_msvc(self) and self.options.shared: + raise ConanInvalidConfiguration( + f"{self.ref} doesn't support msvc shared build.(yet)" + ) + + if self.settings.compiler.get_safe("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["MINISCRIPT_SRC_DIR"] = self.source_folder.replace("\\", "/") + if Version(self.version) < "1.6.2": + tc.variables["MINISCRIPT_SRC_DIR"] = self.source_folder.replace("\\", "/") tc.generate() def build(self): + apply_conandata_patches(self) cmake = CMake(self) - cmake.configure(build_script_folder=os.path.join(self.source_folder, os.pardir)) + if Version(self.version) >= "1.6.2": + cmake.configure() + else: + cmake.configure(build_script_folder=os.path.join(self.source_folder, os.pardir)) cmake.build() def package(self): @@ -54,7 +97,7 @@ def package(self): cmake.install() def package_info(self): - self.cpp_info.libs = ["miniscript"] + self.cpp_info.libs = ["miniscript-cpp"] if self.settings.os in ["Linux", "FreeBSD"]: self.cpp_info.system_libs.append("m") self.cpp_info.system_libs.append("pthread") diff --git a/recipes/miniscript/all/patches/1.6.2-0001-fix-install.patch b/recipes/miniscript/all/patches/1.6.2-0001-fix-install.patch new file mode 100644 index 0000000000000..ee6363d99e585 --- /dev/null +++ b/recipes/miniscript/all/patches/1.6.2-0001-fix-install.patch @@ -0,0 +1,21 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 0d00a90..5984c15 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -131,4 +131,14 @@ if(MINISCRIPT_BUILD_TESTING) + endif() + endif() + +-install(TARGETS miniscript-cpp minicmd) ++include(GNUInstallDirs) ++install( ++ TARGETS miniscript-cpp minicmd ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ++) ++install( ++ FILES ${MINISCRIPT_HEADERS} ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/MiniScript ++) +\ No newline at end of file diff --git a/recipes/miniscript/all/patches/1.6.2-0002-remove-bit.patch b/recipes/miniscript/all/patches/1.6.2-0002-remove-bit.patch new file mode 100644 index 0000000000000..414f7575cb0fd --- /dev/null +++ b/recipes/miniscript/all/patches/1.6.2-0002-remove-bit.patch @@ -0,0 +1,13 @@ +diff --git a/MiniScript-cpp/src/MiniScript/MiniscriptTypes.cpp b/MiniScript-cpp/src/MiniScript/MiniscriptTypes.cpp +index c406663..696dacf 100644 +--- a/MiniScript-cpp/src/MiniScript/MiniscriptTypes.cpp ++++ b/MiniScript-cpp/src/MiniScript/MiniscriptTypes.cpp +@@ -15,7 +15,7 @@ + + #include + #include +-#include ++ + + namespace MiniScript { + diff --git a/recipes/miniscript/all/test_package/CMakeLists.txt b/recipes/miniscript/all/test_package/CMakeLists.txt index 677b1ee8fe710..5172294b30473 100644 --- a/recipes/miniscript/all/test_package/CMakeLists.txt +++ b/recipes/miniscript/all/test_package/CMakeLists.txt @@ -5,4 +5,9 @@ find_package(miniscript REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.cpp) target_link_libraries(${PROJECT_NAME} PRIVATE miniscript::miniscript) -target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) +if(miniscript_VERSION VERSION_GREATER_EQUAL "1.6.2") + target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20) + target_compile_definitions(${PROJECT_NAME} PRIVATE MINISCRIPT_1_6) +else() + target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) +endif() diff --git a/recipes/miniscript/all/test_package/test_package.cpp b/recipes/miniscript/all/test_package/test_package.cpp index 91d25c569fcf6..4dafbfd87c152 100644 --- a/recipes/miniscript/all/test_package/test_package.cpp +++ b/recipes/miniscript/all/test_package/test_package.cpp @@ -9,6 +9,25 @@ #include "MiniScript/MiniscriptParser.h" #include "MiniScript/MiniscriptInterpreter.h" +#ifdef MINISCRIPT_1_6 + +int main() { + MiniScript::Interpreter interp; + + interp.standardOutput = [](MiniScript::String s, bool lineBreak=true) { std::cout << s.c_str() << std::endl; }; + interp.errorOutput = [](MiniScript::String s, bool lineBreak=true) { std::cerr << s.c_str() << std::endl; }; + interp.implicitOutput = [](MiniScript::String s, bool lineBreak=true) { std::cout << s.c_str() << std::endl; }; + + interp.REPL("x = 5"); + interp.REPL("print \"x = \" + x"); + interp.REPL("y = 5 + x"); + interp.REPL("print \"y = \" + y"); + + return 0; +} + +#else + int main() { MiniScript::Interpreter interp; @@ -23,3 +42,5 @@ int main() { return 0; } + +#endif diff --git a/recipes/miniscript/config.yml b/recipes/miniscript/config.yml index f1c5e3d313178..9583d73d43da2 100644 --- a/recipes/miniscript/config.yml +++ b/recipes/miniscript/config.yml @@ -1,3 +1,5 @@ versions: + "1.6.2": + folder: all "1.5.1": folder: all