Re: [CMake] Is there analog of source command from bash ?

2017-05-28 Thread Alan W. Irwin

On 2017-05-29 00:36+0300 Konstantin Tokarev wrote:




28.05.2017, 16:58, "Denis Kotov" :

Hi everyone,

I have tried to find solution to the following problem:
There is the project with environment variable described in setenv.sh file
Old build process looks like:
source setenv.sh
make release

But I want to accomplish this by CMake. But I have realized that CMake does not 
have analog of source command that's why the following command does not work:
execute_process(COMMAND bash -c "source ../setenv")


You can run  source setenv.sh before you run cmake, or in the same shell 
invocation with command that requires environment


That method just makes those environment variables available at cmake
time and it will require more work to propagate that environment to
the environment used at make time.

@Denis (the OP).  I have an entirely different suggestion. You will
have to experiment (since I have never tried this myself), but
fundamentally you want a command to run at make time before you build
the release target.

I am pretty sure the following idea would implement this without issues:

add_custom_target(update_environment
COMMAND bash -c "source "
)
add_custom_target(release ALL
COMMAND command1
COMMAND command2
[...]
)
# Make sure the above command is run every time before the release
# target is built
add_dependencies(release update_environment)

N.B. according to
 this
method will only work on top-level targets that you create yourself
with add_executable, add_library, and add_custom_target; and will NOT
work (for good reasons, see below) on CMake-generated high-level
targets such as "test", "all", and "install".  But for example, if you
implement your add_custom_target for the "release" target with the ALL
attribute as above, it will make that custom target a dependency of
the "all" target which itself is (automatically) a dependency of the
"install" target.  So the target dependency chain resulting from
the above idea
would be

install -> all -> release -> update_environment

And similarly for the "test" high-level target.

Which I think is what you want for the dependency chain between the high-level 
targets
and custom targets.

Good luck, and please let us know the results of your experiments with this
idea.

Alan

__
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state
implementation for stellar interiors (freeeos.sf.net); the Time
Ephemerides project (timeephem.sf.net); PLplot scientific plotting
software package (plplot.sf.net); the libLASi project
(unifont.org/lasi); the Loads of Linux Links project (loll.sf.net);
and the Linux Brochure Project (lbproject.sf.net).
__

Linux-powered Science
__
--

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


Re: [CMake] Is there analog of source command from bash ?

2017-05-28 Thread Konstantin Tokarev


28.05.2017, 16:58, "Denis Kotov" :
> Hi everyone,
>
> I have tried to find solution to the following problem:
> There is the project with environment variable described in setenv.sh file
> Old build process looks like:
> source setenv.sh
> make release
>
> But I want to accomplish this by CMake. But I have realized that CMake does 
> not have analog of source command that's why the following command does not 
> work:
> execute_process(COMMAND bash -c "source ../setenv")

You can run  source setenv.sh before you run cmake, or in the same shell 
invocation with command that requires environment

>
> Because CMake creates a child process.
> How can I import variables that was set in some sh file ?
>
> Thanks,
> Best Regards
> Denis Kotov
> ,--
>
> 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


-- 
Regards,
Konstantin
-- 

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

Re: [CMake] Is there analog of source command from bash ?

2017-05-28 Thread Magnus Therning

Denis Kotov  writes:

> Hi everyone,
>
> I have tried to find solution to the following problem: There is the
> project with environment variable described in *setenv.sh* file
> Old build process looks like:
> source *setenv.sh*
> make release
>
> But I want to accomplish this by *CMake*. But I have realized that
> *CMake* does not have analog of source command that's why the
> following command does not work:
> execute_process(COMMAND bash -c "source ../setenv")
>
> Because *CMake* creates a child process.
> How can I import variables that was set in some sh file ?

What I usually do is rewrite the sh file into a proper CMake package and
then use find_package() to pull it in. Another option is of course to
just include() it.

/M

--
Magnus Therning  OpenPGP: 0x927912051716CE39
email: mag...@therning.org   jabber: mag...@therning.org
twitter: magthe   http://therning.org/magnus

If our ideas of intellectual property are wrong, we must change them,
improve them and return them to their original purpose. When
intellectual property rules diminish the supply of new ideas, they
steal from all of us.
 — Andrew Brown, November 19, 2005, The Guardian


signature.asc
Description: PGP signature
-- 

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

[CMake] Is there analog of source command from bash ?

2017-05-28 Thread Denis Kotov
Hi everyone,

I have tried to find solution to the following problem:
There is the project with environment variable described in *setenv.sh* file
Old build process looks like:
source *setenv.sh*
make release

But I want to accomplish this by *CMake*. But I have realized that *CMake*
does not have analog of source command that's why the following command
does not work:
execute_process(COMMAND bash -c "source ../setenv")

Because *CMake* creates a child process.
How can I import variables that was set in some sh file ?

*Thanks,*

*Best RegardsDenis Kotov*
-- 

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