Re: [cmake-developers] Obtaining header file dependencies of a source file manually

2015-12-01 Thread Dan Liew
> I fail to see why that should not work. Producing LLVM bitcode from
> C++ with Clang is just adding -emit-llvm flag, right? So, why can't
> the SuperBuild configure the child build to use Clang and this flag?
> And Bob's your uncle...

Hmm, to be honest I hadn't tried. It works better than expected but...

The problem for this particular project is that it doesn't file a very
standard compilation process. It compiles to LLVM IR, then to LLVM
bitcode and then it invokes and external program to generate source
files with the LLVM bitcode embedded in specially named arrays these
generated source files then are compiled along with other sources into
the projects main library. If I made the external project create
OBJECT libraries rather than regular libraries then that might work
but when I add the ``-emit-llvm`` flag to CMAKE_C_FLAGS things start
breaking..., e.g.

```
include(CheckCCompilerFlag)
CHECK_C_COMPILER_FLAG("-g" SUPPORTS_DEBUG)
```

Checking this compiler flag fails if CMAKE_C_FLAGS contains
``-emit-llvm`` due to linking errors.

I also need a way of communicating to the outside world where the
object files are as they are the final output. Using ``add_library(foo
OBJECT ...)`` is just a hack to avoid invoking the linker.

Maybe I should use a tool-chain file? I've never used this feature of
CMake before but perhaps that would solve these problems. That way I
could have CMake use, llvm-link rather than the system linker. Then
things wouldn't break when trying to link.

Dan.
-- 

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] Obtaining header file dependencies of a source file manually

2015-11-30 Thread Michael Wild
On Mon, Nov 30, 2015 at 7:01 PM, Dan Liew  wrote:
> Hi Michael,
>
>> Not going into detail as I'm typing on the phone, but this really sounds
>> like a case where a "SuperBuild"
>> (http://www.kitware.com/media/html/BuildingExternalProjectsWithCMake2.8.html)
>> can help you to simplify things a lot.
>
> Thanks for the suggestion but this certainly is not a case where a
> "SuperBuild" would help. CMake does not know how to configure a
> compiler that can produce LLVM Bitcode so using a "SuperBuild" is not
> going to help.
>
> Dan.


Hi Dan

I fail to see why that should not work. Producing LLVM bitcode from
C++ with Clang is just adding -emit-llvm flag, right? So, why can't
the SuperBuild configure the child build to use Clang and this flag?
And Bob's your uncle...

Michael
-- 

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] Obtaining header file dependencies of a source file manually

2015-11-30 Thread Dan Liew
Hi,

On 30 November 2015 at 18:03, Dan Liew  wrote:
> Hi,
>
> On 30 November 2015 at 08:09, Petr Kmoch  wrote:
>> Hi Dan,
>>
>> you could look into the IMPLICIT_DEPENDS argument of add_custom_command:
>> https://cmake.org/cmake/help/latest/command/add_custom_command.html
>>
>> I don't have direct experience with it, but it looks like it could do what
>> you're looking for.
>
> Oh. That sounds exactly like what I'm looking for!

It works but only for makefile generators... That's an annoying
limitation. I'll file a feature request to get this implemented for
other generators.

Dan.
-- 

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] Obtaining header file dependencies of a source file manually

2015-11-30 Thread Dan Liew
Hi,

On 30 November 2015 at 08:09, Petr Kmoch  wrote:
> Hi Dan,
>
> you could look into the IMPLICIT_DEPENDS argument of add_custom_command:
> https://cmake.org/cmake/help/latest/command/add_custom_command.html
>
> I don't have direct experience with it, but it looks like it could do what
> you're looking for.

Oh. That sounds exactly like what I'm looking for!

Thanks,
Dan.
-- 

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] Obtaining header file dependencies of a source file manually

2015-11-30 Thread Dan Liew
Hi Michael,

> Not going into detail as I'm typing on the phone, but this really sounds
> like a case where a "SuperBuild"
> (http://www.kitware.com/media/html/BuildingExternalProjectsWithCMake2.8.html)
> can help you to simplify things a lot.

Thanks for the suggestion but this certainly is not a case where a
"SuperBuild" would help. CMake does not know how to configure a
compiler that can produce LLVM Bitcode so using a "SuperBuild" is not
going to help.

Dan.
-- 

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] Obtaining header file dependencies of a source file manually

2015-11-30 Thread Petr Kmoch
Hi Dan,

you could look into the IMPLICIT_DEPENDS argument of add_custom_command:
https://cmake.org/cmake/help/latest/command/add_custom_command.html

I don't have direct experience with it, but it looks like it could do what
you're looking for.

Petr

On Sun, Nov 29, 2015 at 10:47 AM, Dan Liew  wrote:

> Hi,
>
> # TL;DR
>
> I need a way of determining the header file dependencies of a source
> file and inform CMake about them. CMake doesn't do this automatically
> because I'm using custom commands for the compilation step so CMake
> doesn't do it's usual magic of automatically inferring source file
> header dependencies. This is because this part of the compilation step
> requires a separate C++ compiler (completely independent from the one
> that CMake detects at configure time).
>
> Is there a way of doing this that will also regenerate the
> dependencies if the source file changes?
>
> # Long version
>
> A C++ project that I work on [1] is (amongst other things) a compiler.
> In order to compile applications it needs to link in a supporting
> runtime that is compiled to LLVM bitcode which is linked into the
> applications it compiles.
>
> The supporting runtime is written in C++ and compiled with Clang. The
> compilation of the runtime is currently achieved using
> ``add_custom_command()`` and so I am not using CMake's in built
> support for detecting header file dependencies. The reason for doing
> it this way is because the LLVM bitcode compiler (i.e. Clang) **is
> not** the same compiler as the host C++ compiler for the project. For
> example the host code might be built with MSVC but the supporting
> runtime is **always** built with Clang.
>
> To see this concretely take a look at [2].
>
> The build works correctly if you build from a clean build directory.
> It does not work correctly if you perform a rebuild and change one of
> the header files that the supporting runtime depends on. This is
> because CMake doesn't know that the runtime source files depend on the
> header files and so doesn't rebuild the relevant source files.
>
> I can obviously tell CMake about these manually (adding more entries
> under ``DEPENDS`` in the ``add_custom_command()`` invocation) but this
> is very cumbersome.
>
> What I really need is a way to
>
> * Automatically infer the dependencies of a source file and tell CMake
> about them
> * Have the dependencies automatically regenerated if the source file
> changes (someone could add or remove a header file include).
>
> In a simple Makefile build system this typically achieved by doing
> something like this:
>
> ```
> all:: $(SRCS:.cpp:.o)
>
> SRCS := foo.cpp bar.cpp
>
> # Include SRC file dependencies generated by the compiler if they exist
> -include $(SRCs:.cpp=.d)
>
> %.o : %.cpp
>   $(CXX) -c $< -o $@ -MP -MMD -MF $*.d
> ```
>
> Note the ``-M*`` flags get the compiler when it runs to generate
> additional makefile rules that will get included next time a build
> happens.
>
> I don't really know how to do the same thing with CMake. One idea is
> at configure time invoke Clang with the ``-MP -MMD -MF`` flags on each
> runtime source file, extract the dependencies then pass them to
> ``DEPENDS`` in ``add_custom_command()``. If I wanted the dependencies
> regenerated if the runtime source file changes then I would need to
> somehow get CMake to reconfigure every time this happens.
>
> I don't like this idea very much due to
>
> * Having to invoke Clang manually to determine the dependencies. CMake
> already knows how to determine source file dependencies, but this
> functionality (AFAIK) isn't exposed to me.
>
> * Reconfiguring every time one of the runtime source file changes is
> annoying (configuring can be slow sometimes).
>
> Does anyone have any other ideas? CMake obviously knows how to do all
> this stuff already for source files being compiled for the detected
> host C++ compiler, I just don't know how to get at this logic for
> source files that need to be built with a second independent C++
> compiler.
>
> [1] https://github.com/halide/Halide
> [2] https://github.com/halide/Halide/blob/master/src/CMakeLists.txt#L140
>
> Thanks,
> Dan.
> --
>
> 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
>
-- 

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 C

Re: [cmake-developers] Obtaining header file dependencies of a source file manually

2015-11-29 Thread Michael Wild
On Sun, Nov 29, 2015, 10:47 Dan Liew  wrote:

Hi,

# TL;DR

I need a way of determining the header file dependencies of a source
file and inform CMake about them. CMake doesn't do this automatically
because I'm using custom commands for the compilation step so CMake
doesn't do it's usual magic of automatically inferring source file
header dependencies. This is because this part of the compilation step
requires a separate C++ compiler (completely independent from the one
that CMake detects at configure time).

Is there a way of doing this that will also regenerate the
dependencies if the source file changes?

# Long version

A C++ project that I work on [1] is (amongst other things) a compiler.
In order to compile applications it needs to link in a supporting
runtime that is compiled to LLVM bitcode which is linked into the
applications it compiles.

The supporting runtime is written in C++ and compiled with Clang. The
compilation of the runtime is currently achieved using
``add_custom_command()`` and so I am not using CMake's in built
support for detecting header file dependencies. The reason for doing
it this way is because the LLVM bitcode compiler (i.e. Clang) **is
not** the same compiler as the host C++ compiler for the project. For
example the host code might be built with MSVC but the supporting
runtime is **always** built with Clang.

To see this concretely take a look at [2].

The build works correctly if you build from a clean build directory.
It does not work correctly if you perform a rebuild and change one of
the header files that the supporting runtime depends on. This is
because CMake doesn't know that the runtime source files depend on the
header files and so doesn't rebuild the relevant source files.

I can obviously tell CMake about these manually (adding more entries
under ``DEPENDS`` in the ``add_custom_command()`` invocation) but this
is very cumbersome.

What I really need is a way to

* Automatically infer the dependencies of a source file and tell CMake
about them
* Have the dependencies automatically regenerated if the source file
changes (someone could add or remove a header file include).

In a simple Makefile build system this typically achieved by doing
something like this:

```
all:: $(SRCS:.cpp:.o)

SRCS := foo.cpp bar.cpp

# Include SRC file dependencies generated by the compiler if they exist
-include $(SRCs:.cpp=.d)

%.o : %.cpp
  $(CXX) -c $< -o $@ -MP -MMD -MF $*.d
```

Note the ``-M*`` flags get the compiler when it runs to generate
additional makefile rules that will get included next time a build
happens.

I don't really know how to do the same thing with CMake. One idea is
at configure time invoke Clang with the ``-MP -MMD -MF`` flags on each
runtime source file, extract the dependencies then pass them to
``DEPENDS`` in ``add_custom_command()``. If I wanted the dependencies
regenerated if the runtime source file changes then I would need to
somehow get CMake to reconfigure every time this happens.

I don't like this idea very much due to

* Having to invoke Clang manually to determine the dependencies. CMake
already knows how to determine source file dependencies, but this
functionality (AFAIK) isn't exposed to me.

* Reconfiguring every time one of the runtime source file changes is
annoying (configuring can be slow sometimes).

Does anyone have any other ideas? CMake obviously knows how to do all
this stuff already for source files being compiled for the detected
host C++ compiler, I just don't know how to get at this logic for
source files that need to be built with a second independent C++
compiler.

[1] https://github.com/halide/Halide
[2] https://github.com/halide/Halide/blob/master/src/CMakeLists.txt#L140

Thanks,
Dan.



Hi Dan,

Not going into detail as I'm typing on the phone, but this really sounds
like a case where a "SuperBuild" (
http://www.kitware.com/media/html/BuildingExternalProjectsWithCMake2.8.html)
can help you to simplify things a lot.

Michael
-- 

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

[cmake-developers] Obtaining header file dependencies of a source file manually

2015-11-29 Thread Dan Liew
Hi,

# TL;DR

I need a way of determining the header file dependencies of a source
file and inform CMake about them. CMake doesn't do this automatically
because I'm using custom commands for the compilation step so CMake
doesn't do it's usual magic of automatically inferring source file
header dependencies. This is because this part of the compilation step
requires a separate C++ compiler (completely independent from the one
that CMake detects at configure time).

Is there a way of doing this that will also regenerate the
dependencies if the source file changes?

# Long version

A C++ project that I work on [1] is (amongst other things) a compiler.
In order to compile applications it needs to link in a supporting
runtime that is compiled to LLVM bitcode which is linked into the
applications it compiles.

The supporting runtime is written in C++ and compiled with Clang. The
compilation of the runtime is currently achieved using
``add_custom_command()`` and so I am not using CMake's in built
support for detecting header file dependencies. The reason for doing
it this way is because the LLVM bitcode compiler (i.e. Clang) **is
not** the same compiler as the host C++ compiler for the project. For
example the host code might be built with MSVC but the supporting
runtime is **always** built with Clang.

To see this concretely take a look at [2].

The build works correctly if you build from a clean build directory.
It does not work correctly if you perform a rebuild and change one of
the header files that the supporting runtime depends on. This is
because CMake doesn't know that the runtime source files depend on the
header files and so doesn't rebuild the relevant source files.

I can obviously tell CMake about these manually (adding more entries
under ``DEPENDS`` in the ``add_custom_command()`` invocation) but this
is very cumbersome.

What I really need is a way to

* Automatically infer the dependencies of a source file and tell CMake
about them
* Have the dependencies automatically regenerated if the source file
changes (someone could add or remove a header file include).

In a simple Makefile build system this typically achieved by doing
something like this:

```
all:: $(SRCS:.cpp:.o)

SRCS := foo.cpp bar.cpp

# Include SRC file dependencies generated by the compiler if they exist
-include $(SRCs:.cpp=.d)

%.o : %.cpp
  $(CXX) -c $< -o $@ -MP -MMD -MF $*.d
```

Note the ``-M*`` flags get the compiler when it runs to generate
additional makefile rules that will get included next time a build
happens.

I don't really know how to do the same thing with CMake. One idea is
at configure time invoke Clang with the ``-MP -MMD -MF`` flags on each
runtime source file, extract the dependencies then pass them to
``DEPENDS`` in ``add_custom_command()``. If I wanted the dependencies
regenerated if the runtime source file changes then I would need to
somehow get CMake to reconfigure every time this happens.

I don't like this idea very much due to

* Having to invoke Clang manually to determine the dependencies. CMake
already knows how to determine source file dependencies, but this
functionality (AFAIK) isn't exposed to me.

* Reconfiguring every time one of the runtime source file changes is
annoying (configuring can be slow sometimes).

Does anyone have any other ideas? CMake obviously knows how to do all
this stuff already for source files being compiled for the detected
host C++ compiler, I just don't know how to get at this logic for
source files that need to be built with a second independent C++
compiler.

[1] https://github.com/halide/Halide
[2] https://github.com/halide/Halide/blob/master/src/CMakeLists.txt#L140

Thanks,
Dan.
-- 

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