Skip to content

Commit

Permalink
Merge branch 'xcmake'
Browse files Browse the repository at this point in the history
  • Loading branch information
pfultz2 committed Aug 2, 2016
2 parents 8740204 + 6b7d47b commit cd93ce8
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 5 deletions.
7 changes: 4 additions & 3 deletions cget/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ def init_command(prefix, toolchain, cxx, cxxflags, ldflags, std, define, shared,
@click.option('-f', '--file', default=None, help="Install packages listed in the file")
@click.option('-D', '--define', multiple=True, help="Extra configuration variables to pass to CMake")
@click.option('-G', '--generator', envvar='CGET_GENERATOR', help='Set the generator for CMake to use')
@click.option('-X', '--cmake', help='Set cmake file to use to build project')
@click.argument('pkgs', nargs=-1, type=click.STRING)
def install_command(prefix, pkgs, define, file, test, test_all, update, generator):
def install_command(prefix, pkgs, define, file, test, test_all, update, generator, cmake):
""" Install packages """
pbs = [PackageBuild(pkg) for pkg in pkgs]
pbs = [PackageBuild(pkg, define=define, cmake=cmake) for pkg in pkgs]
for pb in list(prefix.from_file(file))+pbs:
with prefix.try_("Failed to build package {}".format(pb.to_name()), on_fail=lambda: prefix.remove(pb)):
click.echo(prefix.install(pb.merge(define), test=test, test_all=test_all, update=update, generator=generator))
click.echo(prefix.install(pb, test=test, test_all=test_all, update=update, generator=generator))

@cli.command(name='build')
@use_prefix
Expand Down
6 changes: 4 additions & 2 deletions cget/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ def fname_to_pkg(fname):
else: return PackageSource(name=fname.replace('__', '/'), fname=fname)

class PackageBuild:
def __init__(self, pkg_src=None, define=[], parent=None, test=False, hash=None, build=None):
def __init__(self, pkg_src=None, define=None, parent=None, test=False, hash=None, build=None, cmake=None):
self.pkg_src = pkg_src
self.define = define
self.define = define or []
self.parent = parent
self.test = test
self.build = build
self.hash = hash
self.cmake = cmake

def merge(self, define):
result = copy.copy(self)
Expand All @@ -70,6 +71,7 @@ def parse_pkg_build_tokens(args):
parser.add_argument('pkg_src')
parser.add_argument('-D', '--define', nargs='+')
parser.add_argument('-H', '--hash')
parser.add_argument('-X', '--cmake')
parser.add_argument('-t', '--test', action='store_true')
parser.add_argument('-b', '--build', action='store_true')
return parser.parse_args(args=args, namespace=PackageBuild())
Expand Down
6 changes: 6 additions & 0 deletions cget/prefix.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ def parse_pkg_src(self, pkg, start=None):
def parse_pkg_build(self, pkg, start=None):
if isinstance(pkg, PackageBuild):
pkg.pkg_src = self.parse_pkg_src(pkg.pkg_src, start)
if pkg.cmake and not os.path.isabs(pkg.cmake):
pkg.cmake = util.actual_path(pkg.cmake, start)
return pkg
else: return PackageBuild(self.parse_pkg_src(pkg, start))

Expand Down Expand Up @@ -189,6 +191,10 @@ def install(self, pb, test=False, test_all=False, generator=None, update=False,
src_dir = builder.fetch(pb.pkg_src.url, pb.hash)
# Install any dependencies first
self.install_deps(pb, src_dir, test=test, test_all=test_all, generator=generator)
# Setup cmake file
if pb.cmake:
target = os.path.join(src_dir, 'CMakeLists.txt')
shutil.copyfile(pb.cmake, target)
# Confirue and build
builder.configure(src_dir, defines=pb.define, generator=generator, install_prefix=install_dir)
builder.build(config='Release')
Expand Down
21 changes: 21 additions & 0 deletions test/basicappx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cmake_minimum_required (VERSION 2.8)

include(CTest)

add_executable (basicapp main.cpp)
find_package(PkgConfig)
pkg_check_modules(BASICAPP_PKGS REQUIRED simple)
include_directories(${BASICAPP_PKGS_INCLUDE_DIRS})
target_link_libraries(basicapp ${BASICAPP_PKGS_LDFLAGS})
install(TARGETS basicapp DESTINATION bin)

add_executable (basciapptest main.cpp)
target_link_libraries(basciapptest ${BASICAPP_PKGS_LDFLAGS})
if(WIN32)
add_test(NAME basicapptest WORKING_DIRECTORY ${LIBRARY_OUTPUT_PATH} COMMAND basciapptest${CMAKE_EXECUTABLE_SUFFIX})
else()
add_test(NAME basicapptest COMMAND basciapptest)
endif()



7 changes: 7 additions & 0 deletions test/basicappx/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

#include <simple.h>

int main()
{
simple();
}
3 changes: 3 additions & 0 deletions test/basicappx/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Initial comment
simple:../libsimplebare --cmake ../libsimple/CMakeLists.txt # A comment
# Trailing comment
10 changes: 10 additions & 0 deletions test/libsimplebare/include/simple.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

#ifndef GUARD_SIMPLE_H
#define GUARD_SIMPLE_H

inline void simple()
{
}


#endif
6 changes: 6 additions & 0 deletions test/libsimplebare/simple.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Name: simple
Description: A simple library
URL: https://github.com/pfultz2/Fit
Version: 1.0

Cflags: -I@CMAKE_INSTALL_PREFIX@/include
7 changes: 7 additions & 0 deletions test/libsimplebare/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

#include <simple.h>

int main()
{
simple();
}
15 changes: 15 additions & 0 deletions test/test_cget.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@ def test_dir_custom_build_path(d):
def test_prefix(d):
d.cmds(install_cmds(url=get_exists_path('libsimple'), lib='simple', prefix=d.get_path('usr')))

@pytest.mark.xfail
def test_xcmake_fail(d):
d.cmds(install_cmds(url=get_exists_path('libsimplebare'), lib='simple'))

def test_xcmake(d):
url = get_exists_path('libsimplebare') + ' --cmake ' + get_exists_path('libsimple', 'CMakeLists.txt')
d.cmds(install_cmds(url=url, lib='simple', alias=get_exists_path('libsimplebare')))

def test_xcmake_s(d):
url = get_exists_path('libsimplebare') + ' -X ' + get_exists_path('libsimple', 'CMakeLists.txt')
d.cmds(install_cmds(url=url, lib='simple', alias=get_exists_path('libsimplebare')))

def test_rm(d):
d.cmds(install_cmds(url=get_exists_path('libsimple'), lib='simple', remove='rm'))

Expand Down Expand Up @@ -242,6 +254,9 @@ def test_app_include_dir(d):
def test_app_dir(d):
d.cmds(install_cmds(url=get_exists_path('basicapp'), lib='simple', alias='simple', size=2))

def test_xapp_dir(d):
d.cmds(install_cmds(url=get_exists_path('basicappx'), lib='simple', alias='simple', size=2))

def test_build_flag_child(d):
d.cmds([
cget_cmd('install', '--verbose', get_exists_path('basicappbuild')),
Expand Down

0 comments on commit cd93ce8

Please sign in to comment.