Browse Source

fix: Fail to build Conan package

pull/31/head
Tom G. Huang 6 years ago
parent
commit
9ccdf04796
  1. 2
      CMakeLists.txt
  2. 29
      conanfile.py
  3. 63
      test_package/CMakeLists.txt
  4. 2
      test_package/conanfile.py
  5. 6
      test_package/testargtable3.c

2
CMakeLists.txt

@ -59,7 +59,7 @@ set(ARGTABLE3_FULL_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${P
if(ARGTABLE3_ENABLE_CONAN AND EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
conan_basic_setup(TARGETS)
conan_basic_setup()
string(REPLACE ";" ":" LINK_FLAGS "${CONAN_LIB_DIRS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath-link,${LINK_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath-link,${LINK_FLAGS}")

29
conanfile.py

@ -27,37 +27,28 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
################################################################################
import os
import os.path
from conans import ConanFile, CMake, tools
class ArgTable3(ConanFile):
class Argtable3(ConanFile):
name = 'argtable3'
description = 'A single-file, ANSI C, command-line parsing library that parses GNU-style command-line options.'
url = 'https://github.com/argtable/argtable3'
version = tools.load('version.txt').strip() + '-3'
version = tools.load('version.tag').strip() if os.path.isfile('version.tag') else "v0.0.0"
license = 'BSD 3-Clause'
settings = 'os', 'compiler', 'build_type', 'arch'
options = {
'shared': [True, False],
'build_examples': [True, False],
'build_tests': [True, False]
}
default_options = {
'shared': True,
'build_examples': True,
'build_tests': True
}
options = {'shared': [True, False]}
default_options = {'shared': True}
generators = 'cmake'
scm = {
'type': 'git',
'url': 'auto',
'revision': 'auto'
}
exports = 'version.txt'
exports = 'version.tag'
def build(self):
if self.settings.os:
@ -77,11 +68,7 @@ class ArgTable3(ConanFile):
def configure_cmake(self):
cmake = CMake(self)
cmake.configure(defs={
'BUILD_SHARED_LIBS': 'ON' if self.options.shared else 'OFF',
'argtable3_build_examples': 'ON' if self.options.build_examples else 'OFF',
'argtable3_build_tests': 'ON' if self.options.build_tests else 'OFF'
}, build_folder=self.binary_folder)
cmake.configure(defs={}, build_folder=self.binary_folder)
return cmake
@property

63
test_package/CMakeLists.txt

@ -1,25 +1,56 @@
# (C)2019 Red Lion Controls, Inc. All rights reserved. Red Lion, the Red Lion logo and Sixnet are registered trademarks
# of Red Lion Controls, Inc. All other company and product names are trademarks of their respective owners.
cmake_minimum_required(VERSION 3.3)
project(ArgTable3TestConan C)
################################################################################
# This file is part of the argtable3 library.
#
# Copyright (C) 2016-2019 Tom G. Huang
# <tomghuang@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of STEWART HEITMANN nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL STEWART HEITMANN BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
################################################################################
cmake_minimum_required(VERSION 3.0)
project(test_conanpkg)
include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
conan_basic_setup(TARGETS)
conan_basic_setup()
enable_testing()
if (CONAN_SETTINGS_OS)
find_package(argtable3 REQUIRED)
add_executable(${PROJECT_NAME} testargtable3.c)
target_link_libraries(${PROJECT_NAME} PUBLIC argtable3)
add_test(NAME ${PROJECT_NAME} COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} "$<TARGET_FILE:${PROJECT_NAME}>" --help)
find_package(argtable3 REQUIRED)
add_executable(${PROJECT_NAME} testargtable3.c)
target_link_libraries(${PROJECT_NAME} PUBLIC argtable3)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"$<TARGET_FILE:argtable3>"
"$<TARGET_FILE_DIR:${PROJECT_NAME}>"
)
add_test(NAME ${PROJECT_NAME} COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} "$<TARGET_FILE:${PROJECT_NAME}>" --help)
else ()
add_subdirectory("${CONAN_ARGTABLE3_ROOT}/src" "${CMAKE_CURRENT_BINARY_DIR}/argtable3")
add_subdirectory("${CONAN_ARGTABLE3_ROOT}/src" "${CMAKE_CURRENT_BINARY_DIR}/argtable3")
# Compiled library should exist and be a target in the current CMake project
add_test(NAME lib_exists COMMAND "${CMAKE_COMMAND}" -E md5sum "$<TARGET_FILE:argtable3>")
# Compiled library should exist and be a target in the current CMake project
add_test(NAME lib_exists COMMAND "${CMAKE_COMMAND}" -E md5sum "$<TARGET_FILE:argtable3>")
endif ()

2
test_package/conanfile.py

@ -15,4 +15,4 @@ class NewProjectTestConan(ConanFile):
def test(self):
with tools.environment_append(RunEnvironment(self).vars):
self.run('ctest --output-on-failure')
self.run('ctest -C Debug --output-on-failure')

6
test_package/testargtable3.c

@ -1,4 +1,4 @@
#include "argtable3.h"
#include <argtable3.h>
/* global arg_xxx structs */
struct arg_lit *a, *b, *c, *verb, *help, *version;
@ -18,12 +18,12 @@ int main(int argc, char *argv[])
scal = arg_int0(NULL, "scalar", "<n>", "foo value"),
verb = arg_lit0("v", "verbose", "verbose output"),
o = arg_file0("o", NULL, "myfile", "output file"),
file = arg_filen(NULL, NULL, "<file>", 1, 100, "input files"),
file = arg_filen(NULL, NULL, "<file>", 0, 100, "input files"),
end = arg_end(20),
};
int exitcode = 0;
char progname[] = "testargtable2.exe";
char progname[] = "testargtable3.exe";
int nerrors;
nerrors = arg_parse(argc,argv,argtable);

Loading…
Cancel
Save