Skip to content

Include configuration variables in package - #176

Merged
kkaefer merged 14 commits into
masterfrom
176-ini-files
Aug 5, 2016
Merged

kkaefer merged 14 commits into
masterfrom
176-ini-files

Conversation

@kkaefer

@kkaefer kkaefer commented Jul 26, 2016 •

Copy link
Copy Markdown
Member

When generating a package, we should generate the configuration required to link a package and put it into a configuration file that we ship with the package, for example INI-style like this:

package=libuv
version=1.7.6
platform=osx-x86_64
cc=-isystem {prefix}/include
cxx=-isystem {prefix}/include
link={prefix}/lib/libuv.a -lpthread -ldl

The reason for using INI over a more complicated format is that it's way easier to parse with CMake. It also means that we don't have to invoke pkg-config or other build-systems to obtain the flags.

/cc @springmeyer

@springmeyer

Copy link
Copy Markdown
Contributor

👍

@kkaefer
kkaefer force-pushed the 176-ini-files branch 5 times, most recently from 22043ba to f2aa30b Compare July 28, 2016 12:45
@kkaefer

kkaefer commented Jul 28, 2016

Copy link
Copy Markdown
Member Author

This PR changes a few things:

  • Add a config command that can be used like this: mason config <package> <version>. It prints an .ini-style file to the console that looks like this:

    name=glfw
    version=3.1.2
    platform=osx
    platform_version=x86_64
    include_dirs={prefix}/include
    ldflags=-framework Cocoa -framework OpenGL
    static_libs={prefix}/lib/libglfw3.a

    There are also options and definitions, but they are omitted when empty. Header only packages have header_only=true and omit the platform_* keys. The string {prefix} is replaced with the installation location of the package after reading the ini file. You can use ini-style comments (starting with ;). Sections are allowed as well, but are currently ignored.

    When building a package, that file is saved as mason.ini into the package so that the build system can retrieve the configuration from it without having to invoke Mason.

  • Adds a CMake file that downloads, and unpacks packages, and obtains options via the mason.ini file. If a legacy package doesn't have a mason.ini file, the CMake file generates one (this requires Mason to be present); we can remove that part of the code once all of our packages have mason.ini files. Use in your package could look like this:

    cmake_minimum_required(VERSION 3.2)
    
    include(.mason/mason.cmake)
    
    mason_use(earcut VERSION 0.11 HEADER_ONLY)
    mason_use(libpng VERSION 1.6.20)
    
    add_executable(main main.cpp)
    
    target_add_mason_package(main PRIVATE earcut)
    target_add_mason_package(main PRIVATE libpng)
  • Instead of file(DOWNLOAD ...), we are using curl as a subprocess because some versions of CMake out there don't include SSL/TLS support.

  • The CMake script auto-detects the platform. When you want a different one (e.g. for iOS), you should set MASON_PLATFORM=ios.

Comment thread mason.cmake
# Determine platform
if(NOT MASON_PLATFORM)
if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
set(MASON_PLATFORM "macos")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's currently osx not macos right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. We are setting macos because we expect that upstream providers/users also use macos, but we change it to osx a little further down.

@springmeyer

Copy link
Copy Markdown
Contributor

@kkaefer Saw that error handling could be improved for the case where a package is not installed yet:

~/.mason[176-ini-files]$ ./mason config libpng 1.6.20
/Users/dane/.mason/scripts/libpng/1.6.20/script.sh: line 47: /Users/dane/.mason/mason_packages/osx-x86_64/libpng/1.6.20/bin/libpng-config: No such file or directory
/Users/dane/.mason/scripts/libpng/1.6.20/script.sh: line 48: /Users/dane/.mason/mason_packages/osx-x86_64/libpng/1.6.20/bin/libpng-config: No such file or directory
/Users/dane/.mason/scripts/libpng/1.6.20/script.sh: line 40: /Users/dane/.mason/mason_packages/osx-x86_64/libpng/1.6.20/bin/libpng-config: No such file or directory
/Users/dane/.mason/scripts/libpng/1.6.20/script.sh: line 41: /Users/dane/.mason/mason_packages/osx-x86_64/libpng/1.6.20/bin/libpng-config: No such file or directory
No static library file '/Users/dane/.mason/mason_packages/osx-x86_64/libpng/1.6.20/lib/libpng.a'
name=libpng
version=1.6.20
platform=osx
platform_version=x86_64
~/.mason[176-ini-files]$ echo $?
0

I think ./mason config should exit as soon as one of the sub commands fails.

@kkaefer

kkaefer commented Jul 29, 2016

Copy link
Copy Markdown
Member Author

@springmeyer Looks like local FOO=$(...) eats exit codes, so the set -e didn't exit the script.

@kkaefer
kkaefer force-pushed the 176-ini-files branch 2 times, most recently from 7f75185 to f4ee8ed Compare August 4, 2016 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants