Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getopt-for-visual-studio/20200201 recipe #877

Merged
merged 3 commits into from Mar 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions recipes/getopt-for-visual-studio/all/conandata.yml
@@ -0,0 +1,8 @@
sources:
"20200201":
url: "https://github.com/skandhurkat/Getopt-for-Visual-Studio/archive/6708172892a4d89042b743315e8a52e2d9d5defc.zip"
sha256: "9b50026b3f10c3f6a7340e0074a898d6d1105eef068bf98d90af99770375a465"
patches:
"20200201":
- patch_file: "patches/0001-allow-usage-in-multiple-compilation-units.patch"
base_path: "source_subfolder"
42 changes: 42 additions & 0 deletions recipes/getopt-for-visual-studio/all/conanfile.py
@@ -0,0 +1,42 @@
from conans import ConanFile, tools
from conans.errors import ConanInvalidConfiguration
import os


class GetoptForVisualStudio(ConanFile):
name = "getopt-for-visual-studio"
description = "GNU getopt for Visual Studio"
topics = ("conan", "getopt", "cli", "command line", "options")
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/skandhurkat/Getopt-for-Visual-Studio"
license = "MIT", "BSD-2-Clause"
exports_sources = "patches/**"
settings = "compiler"
madebr marked this conversation as resolved.
Show resolved Hide resolved

def configure(self):
if self.settings.compiler != "Visual Studio":
raise ConanInvalidConfiguration("getopt-for-visual-studio is only supported for Visual Studio")

@property
def _source_subfolder(self):
return "source_subfolder"

def source(self):
tools.get(**self.conan_data["sources"][self.version])
os.rename("Getopt-for-Visual-Studio-{}".format(os.path.splitext(os.path.basename(self.conan_data["sources"][self.version]["url"]))[0]), self._source_subfolder)

def build(self):
for patch in self.conan_data["patches"][self.version]:
tools.patch(**patch)

@property
def _license_text(self):
content = tools.load(os.path.join(self._source_subfolder, "getopt.h"))
return "\n".join(list(l.strip() for l in content[content.find("/**", 3):content.find("#pragma")].split("\n")))

def package(self):
tools.save(os.path.join(self.package_folder, "licenses", "LICENSE"), self._license_text)
self.copy("getopt.h", src=self._source_subfolder, dst="include")

def package_id(self):
self.info.header_only()
@@ -0,0 +1,59 @@
--- getopt.h
+++ getopt.h
@@ -56,7 +56,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/

-#pragma warning(disable:4996);
+#pragma warning(disable:4996)

#define __GETOPT_H__

@@ -76,13 +76,13 @@ extern "C" {
#define REPLACE_GETOPT /* use this getopt as the system getopt(3) */

#ifdef REPLACE_GETOPT
-int opterr = 1; /* if error message should be printed */
-int optind = 1; /* index into parent argv vector */
-int optopt = '?'; /* character checked for validity */
-#undef optreset /* see getopt.h */
+static int opterr = 1; /* if error message should be printed */
+static int optind = 1; /* index into parent argv vector */
+static int optopt = '?'; /* character checked for validity */
+#undef optreset /* see getopt.h */
#define optreset __mingw_optreset
-int optreset; /* reset getopt */
-char *optarg; /* argument associated with option */
+static int optreset; /* reset getopt */
+static char *optarg; /* argument associated with option */
#endif

//extern int optind; /* index of first non-option in argv */
@@ -216,7 +216,7 @@ permute_args(int panonopt_start, int panonopt_end, int opt_end,
*
* [eventually this will replace the BSD getopt]
*/
-int
+static int
getopt(int nargc, char * const *nargv, const char *options)
{

@@ -610,7 +610,7 @@ start:
* getopt_long --
* Parse argc/argv argument vector.
*/
-int
+static int
getopt_long(int nargc, char * const *nargv, const char *options,
const struct option *long_options, int *idx)
{
@@ -623,7 +623,7 @@ getopt_long(int nargc, char * const *nargv, const char *options,
* getopt_long_only --
* Parse argc/argv argument vector.
*/
-int
+static int
getopt_long_only(int nargc, char * const *nargv, const char *options,
const struct option *long_options, int *idx)
{

10 changes: 10 additions & 0 deletions recipes/getopt-for-visual-studio/all/test_package/CMakeLists.txt
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.0)
project(test_package)

set(CMAKE_VERBOSE_MAKEFILE ON)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
17 changes: 17 additions & 0 deletions recipes/getopt-for-visual-studio/all/test_package/conanfile.py
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"

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

def test(self):
if not tools.cross_building(self.settings):
self.run(os.path.join("bin", "test_package"), run_environment=True)
21 changes: 21 additions & 0 deletions recipes/getopt-for-visual-studio/all/test_package/test_package.c
@@ -0,0 +1,21 @@
#include <stdlib.h>
#include <stdio.h>

#include <getopt.h>

int main(int argc, char * argv[])
{
int option_index = 0;
int c = getopt(argc, argv, "v");
switch (c) {
case -1:
puts("No more options");
break;
case 'v':
puts("version : 1");
break;
default:
puts("no option found");
}
return EXIT_SUCCESS;
}
3 changes: 3 additions & 0 deletions recipes/getopt-for-visual-studio/config.yml
@@ -0,0 +1,3 @@
versions:
"20200201":
folder: all