Re: [cmake-developers] CMake alternative language (was: Using CMake as a library from Python)

2016-01-11 Thread Petr Kmoch
Hi all.

I'd like to voice my opinion as a somewhat advanced CMake user here.

For me, one of the strongest points of CMake is the fact that its project
specification is procedural rather than declarative. In my current job, for
example, we have a significant framework built in CMake which handles a lot
of unique setups we have (which were largely inherited from a previous
inhouse buildsystem). Yes, the end result of our framework is that the
CMakeLists consist mostly of declarative commands from our framework, but
the implementation of these commands is heavily procedural. I am convinced
that if CMake didn't give us the procedural power required to make this
work, we couldn't have adopted it. (I had previously tried emulating bits
of this setup in a more declarative system and failed miserably).

Of course (having written much of this framework I'm talking about above),
I know all too well that a better front-end language would do a world of
good for CMake. I also understand that taking a more declarative approach
could help that, and I'm not opposed to such a change in principle.
However, please take care not to throw the baby out with the bathwater and
nerf the expressiveness of what can be done with CMake (in a procedural
way).

If I understand Brad's suggestion correctly, it would amount to a (possibly
empty) procedural step being used to generate a declarative description of
the buildsystem. This would work well in our scenario, I believe, as long
as that procedural step could be sufficiently modularised on the client
side.

I fully support introducing an alternative input language to CMake and
taking all steps necessary for this to happen, but please do this in a way
which will not restrict what CMake is capable of doing.

Petr

On Fri, Jan 8, 2016 at 5:30 PM, Brad King  wrote:

> Hi Charles,
>
> Thanks for your efforts in exploring this topic.  CMake's current language
> grew incrementally out of something that was not originally intended as a
> programming language.  The cmState refactoring Stephen Kelly has started
> is a huge step toward enabling alternative languages, but there is a long
> way to go.
>
> A few general thoughts:
>
> * One rule we have for CMake is to never expose any public SDK of the C++
>   implementation structures.  We want to be able to rewrite them
> arbitrarily
>   at any time.  Therefore any solution that needs to access the C++
>   structures must be integrated into CMake upstream and expose
> functionality
>   only through other languages or file formats.
>
> * The cmState infrastructure builds on a "snapshot" design with a goal of
>   being able to "fork" configuration/generation temporarily and then revert
>   back, and to be able to re-start configuration from the middle.  These
>   goals may be incompatible with any language whose implementation we do
>   not fully control unless it is allowed to execute only in isolated and
>   independent snippets.  These are not hard goals, but it is a trade-off
>   to keep in mind.  Stephen may be able to elaborate more on the snapshot
>   approach if needed.
>
> * A problem with the current design is that the entire configuration
> process
>   is logically serial making parallel evaluation hard or impossible.  In
>   many cases each add_subdirectory can be processed independently, but this
>   will require semantic changes to allow.
>
> On 01/04/2016 02:41 AM, Charles Huet wrote:
> > I'm trying to be as declarative as possible, because really like how
> readable
> > simple QML programs are, and I think it would be perfect for a
> buildsystem.
>
> Ideally most of the specification (sources, libraries, executables, etc.)
> should be in a pure format that can be evaluated without side effects (e.g.
> declarative or functional).  This rules out both Python and Lua, but the
> specification format does not have to be the main entry point.  There could
> be some imperative configuration step that does system introspection and
> then loads the pure specification and evaluates it as needed for the
> specific
> environment.
>
> If we're going to go through the effort to provide an alternative input
> format,
> I think we should strive for this approach because it will be more
> flexible in
> the long run.  A pure specification format will allow easy loading/saving
> by
> other tools, IDEs, etc., without having to process any imperative logic.
>
> > Actually, I'm directly using the cmMakefile, because I did not want to
> wrap all
> > the commands, and it seemed backwards to me to wrap them.
>
> Yes.  Any alternative format should be processed directly into the
> structures
> used by the generators.  The cmState work has separated the generate-time
> representation quite a bit from the configuration-time
> (cmake-language-specific)
> representation, but I think there is still further work needed to finish
> that.
>
> >> Having said all that, Brad favors Lua I believe, and he favors a
> different
> >> approach 

Re: [cmake-developers] CMake alternative language (was: Using CMake as a library from Python)

2016-01-11 Thread Charles Huet
Hi,

> * The cmState infrastructure builds on a "snapshot" design with a goal of
  being able to "fork" configuration/generation temporarily and then revert
  back, and to be able to re-start configuration from the middle.  These
  goals may be incompatible with any language whose implementation we do
  not fully control unless it is allowed to execute only in isolated and
  independent snippets.  These are not hard goals, but it is a trade-off
  to keep in mind.  Stephen may be able to elaborate more on the snapshot
  approach if needed.

I think these goals aim towards a faster configure, and the ability to only
partly reconfigure, right ?

> * A problem with the current design is that the entire configuration
process
  is logically serial making parallel evaluation hard or impossible.  In
  many cases each add_subdirectory can be processed independently, but this
  will require semantic changes to allow.

I know I am largely biased by the project I work on, but I do not see how
parallel evaluation woud be a huge benefit. We basically have a "core"
library, and lots of libs that link against it (and other libs, such as
third parties).
How would a target B that depends on lib A be processed in this case ?
Wouldn't the evaluation of the link_libraries of B be waiting for the
evaluation of A to finish ?
If this is the case, then parallel evaluation would be only a slight
benefit (again, heavily biased by the project I work on).
And how would that work with CMakeLists that affect their parent scope ?

> Ideally most of the specification (sources, libraries, executables, etc.)
should be in a pure format that can be evaluated without side effects (e.g.
declarative or functional).

I'm not sure I understand how this could be done without losing a lot of
what CMake offers, such as copying or generating files.
I'm leaning towards a declarative approach as it is quite easy to learn
(since you declare objects, and every C++ programmer I know is familiar
with those), and functional, while powerfull and very elegant for some
things, is quite foreign to C+ programmers as a whole (I know C++11 adds
this, but it will be years until this can be used in production for lots of
C++ users, because of old compilers that are still supported for business
reasons).
Moreover, object-oriented is easy to introspect, offering an abstract
representation for IDEs and tools.

It seems you are leaning towards pure functional, but I do not see how this
would work with the current way CMake handles variables and scope, could
you elaborate ?


> I do not think we should have the build specification depend on processing
code like this.  It is not compatible with cmake-gui where the configuration
and generation steps are triggered by the user.

My POC is far from complete, and what I had in mind to keep the CMake-gui
approach was to make generating optional in CLI through a parameter. Thus
executing the script would only configure, which would populate the
CMakeCache, allowing the user to modify variables and such, then configure.
To clarify, only the following lines should be considered when looking at
the POC.
> myProject=cmake.Project("MyTestProject")
> myProject.targets=[cmake.SharedLibrary("testLibrary",["lib.cxx"])]


> In summary, I think work in this direction should first focus on designing
a declarative (or functional) specification format where most of the project
information can be specified.  Then a cmake-language command can be written
to load and evaluate a specification file (as a transition).  Finally we
could look at replacing the entry-point language with something else.  At
that point we could have closures passed as parameters to the evaluation of
the pure spec in order to get custom generate-time logic.

It seems you have in mind to write a new CMake language. I'd rather see an
existing language used, such as OCaml or lisp if you want a pure functional
language. Those are supported by SWIG so prototyping would be easy.
Javascript is even an option that is not *completely* crazy, as it has a
C-Style syntax  so it would be an easy language to write in for C++
programmers.

I think using an existing language has quite a few benefits:
* no need to design or implement a language
* lots of existing resources on how to do things
* lots of existing libraries (data structures, file system operations, etc)
* tooling (auto-complete, debugging, profiling, linting, etc)

Maybe I should take my POC further, in order to see the failings of this
approach, and maybe the same should be done for a more functional approach.
CMake's own buildsystem seems like a good testing ground for this, but it
is a little too big for a first go, do you know of a small CMake-based
project that would be better suited ?

I don't have a clear view of what a pure functional CMake would look like,
but if you give me some mock code, I could give a try at bringing some pure
functional language up to the level of my POC and we could use it as a more

Re: [cmake-developers] CMake alternative language (was: Using CMake as a library from Python)

2016-01-11 Thread Pau Garcia i Quiles
On Fri, Jan 8, 2016 at 5:30 PM, Brad King  wrote:


> See above.  Lua has come up several times in the past in particular because
> its implementation is meant to be small and embeddable.  I've thought a few
> times about how to make Lua scripting available from within the CMake
> language
> in a clean way, but that will not be as valuable as the above pure-spec
> approach.
>
>
Please, do not do that.

The moment you make CMake scriptable in more than one language, you are
forcing every CMake user to learn that additional language because sooner
or later he will step into a third-party that is using that additional
language.

IMHO, if you want Lua, then Lua it is. But then please get rid of CMake
scripting.

BTW, I am sure you are aware of CMakeScript, CMake scripting in JavaScript:

http://sourceforge.net/projects/cmakescript/

Also, declarative? Why? There are already a few declarative build systems
(e. g. qbs, one of the reasons for its existence was CMake was not
declarative). By moving CMake from the current procedural scripting to a
declarative approach, you may alienate your current user base and be good
for none anymore.

-- 
Pau Garcia i Quiles
http://www.elpauer.org
(Due to my workload, I may need 10 days to answer)
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers

Re: [cmake-developers] CMake alternative language (was: Using CMake as a library from Python)

2016-01-08 Thread Brad King
Hi Charles,

Thanks for your efforts in exploring this topic.  CMake's current language
grew incrementally out of something that was not originally intended as a
programming language.  The cmState refactoring Stephen Kelly has started
is a huge step toward enabling alternative languages, but there is a long
way to go.

A few general thoughts:

* One rule we have for CMake is to never expose any public SDK of the C++
  implementation structures.  We want to be able to rewrite them arbitrarily
  at any time.  Therefore any solution that needs to access the C++
  structures must be integrated into CMake upstream and expose functionality
  only through other languages or file formats.

* The cmState infrastructure builds on a "snapshot" design with a goal of
  being able to "fork" configuration/generation temporarily and then revert
  back, and to be able to re-start configuration from the middle.  These
  goals may be incompatible with any language whose implementation we do
  not fully control unless it is allowed to execute only in isolated and
  independent snippets.  These are not hard goals, but it is a trade-off
  to keep in mind.  Stephen may be able to elaborate more on the snapshot
  approach if needed.

* A problem with the current design is that the entire configuration process
  is logically serial making parallel evaluation hard or impossible.  In
  many cases each add_subdirectory can be processed independently, but this
  will require semantic changes to allow.

On 01/04/2016 02:41 AM, Charles Huet wrote:
> I'm trying to be as declarative as possible, because really like how readable
> simple QML programs are, and I think it would be perfect for a buildsystem.

Ideally most of the specification (sources, libraries, executables, etc.)
should be in a pure format that can be evaluated without side effects (e.g.
declarative or functional).  This rules out both Python and Lua, but the
specification format does not have to be the main entry point.  There could
be some imperative configuration step that does system introspection and
then loads the pure specification and evaluates it as needed for the specific
environment.

If we're going to go through the effort to provide an alternative input format,
I think we should strive for this approach because it will be more flexible in
the long run.  A pure specification format will allow easy loading/saving by
other tools, IDEs, etc., without having to process any imperative logic.

> Actually, I'm directly using the cmMakefile, because I did not want to wrap 
> all
> the commands, and it seemed backwards to me to wrap them.

Yes.  Any alternative format should be processed directly into the structures
used by the generators.  The cmState work has separated the generate-time
representation quite a bit from the configuration-time (cmake-language-specific)
representation, but I think there is still further work needed to finish that.

>> Having said all that, Brad favors Lua I believe, and he favors a different
>> approach (which no one is working on as far as I know) to adding a new
>> language. So wait to hear from him to know whether it is something that
>> would be upstreamable.
> 
> Have any details on the approach in question?

See above.  Lua has come up several times in the past in particular because
its implementation is meant to be small and embeddable.  I've thought a few
times about how to make Lua scripting available from within the CMake language
in a clean way, but that will not be as valuable as the above pure-spec 
approach.

> Here is what my test POC looked like for generating a simple shared library:
> 
> #!/usr/bin/env python
> # -*- coding: utf-8 -*-
> importcmake
> 
> cmake.init("Ninja","/media/dev/src/cmaketest","/media/dev/build/cmaketest")
> myProject=cmake.Project("MyTestProject")
> myProject.targets=[cmake.SharedLibrary("testLibrary",["lib.cxx"])]
> cmake.generate()

I do not think we should have the build specification depend on processing
code like this.  It is not compatible with cmake-gui where the configuration
and generation steps are triggered by the user.  However, this does serve
as a good POC that we can populate the generator structures with another
language.

In summary, I think work in this direction should first focus on designing
a declarative (or functional) specification format where most of the project
information can be specified.  Then a cmake-language command can be written
to load and evaluate a specification file (as a transition).  Finally we
could look at replacing the entry-point language with something else.  At
that point we could have closures passed as parameters to the evaluation of
the pure spec in order to get custom generate-time logic.

Thanks,
-Brad

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on