[CMake] Moving static library to separate project

2018-09-25 Thread Christopher E Robison
I've got a situation I've searched for answers on, and though I've found
similar questions, I've found no generally-applicable answers, or at least
ones I can use. Apologies in advance for a beginner-level question.

I have a group of applications that all use some common functionality I've
located in a static library (for logging in this case). we'll call it
libmylog here. Libmylog is pretty simple, but at some point I wanted to
solve some thread safety situations, so I included some synchronization
features that now require me to link with pthreads. Easy enough,
"target_link_libraries(mylog pthread)" takes care of it.

I've recently begun developing a separate application which doesn't belong
in the same tree, and so I've put it in its own new project. I've decided
I'd like this new application to use libmylog as well, and so now I've
moved mylog into its own separate project too. I've added install
directives and the library (libmylog.a) and its header file end up in the
correct spots in /usr/local when I do a "make install". Looks good so far.

The problem is when I compile any of my executables, the link fails with
undefined reference errors since after removing libmylog from the same
build tree every application I've written that uses it must now link with
libpthread as well. This is an odd thing to have to specify for small
utilities that don't have threads and shouldn't need to care about them. I
look at libmylog.a with nm and all the references to pthreads symbols are
undefined.

More critically, it seems that since the build process for libmylog doesn't
generate an executable, the "target_link_libraries(mylog pthread) line is
now _silently ignored_.

What is the Right Way of dealing with this in CMake? I'd like a way to tell
the linker to force the inclusion of the relevant code in the static
library, but if there's a more canonical approach I'd appreciate the
advice. (For example, do I need to [learn how to] create a CMake "package"
for my libmylog installation -- would this help propagate the -lpthread
requirement to the build for the executables?)


Thanks!
Chris
-- 

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:
https://cmake.org/mailman/listinfo/cmake


Re: [CMake] How to have build steps operate on files in a copied directory?

2017-07-10 Thread Christopher E Robison
It appears to be so -- the install directives execute in incident order, at
least from within a single CMakeLists.txt file.

The solution ended up being INSTALL(CODE "execute_process(COMMAND ...)").
Feels like a bit of a hack, but the install works on two different
platforms -- I'm satisfied for now.

Thanks again for the help!

CR




On Mon, Jul 10, 2017 at 6:25 PM, Michael Ellery <mellery...@gmail.com>
wrote:

>
> > On Jul 10, 2017, at 11:19 AM, Christopher E Robison <
> cerobi...@utexas.edu> wrote:
>


> > Can I specify somehow that this install command must be executed after
> the INSTALL(DIRECTORY ...) command has completed?
>
> I *believe* the install directives are executed in the order they are
> encountered in the processing of CMakeLists files, so putting the custom
> step as the last item in your top level CMake file might do the trick.
>
>
>
-- 

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] How to have build steps operate on files in a copied directory?

2017-07-10 Thread Christopher E Robison
The INSTALL(SCRIPT ...) syntax might be just the answer I need, thanks!.

As I mentioned, the index creating script in the custom step needs to
operate on the copied directory tree in its final location, so if it's not
all there yet it will fail.  So, if CMake has some distinction between
"build" and "install"  (I'm familiar with Makefiles, where the syntax
enforces no such separation -- just targets, dependencies, and commands),
then this would mean the step has to be executed at the end of the
"install" phase.

Can I specify somehow that this install command must be executed after the
INSTALL(DIRECTORY ...) command has completed?


Thanks,
CR


On Mon, Jul 10, 2017 at 6:04 PM, Michael Ellery <mellery...@gmail.com>
wrote:

>
> > On Jul 10, 2017, at 10:46 AM, Christopher E Robison <
> cerobi...@utexas.edu> wrote:
> >
> > I've recently begun using CMake on an existing project I've taken over,
> and I feel like I'm mostly getting used to it, though there is still a vast
> amount to learn.  I've got nearly the entire project building successfully,
> with the exception of a directory of external scripts that need to be
> configured at the end of the install process to create some index files.
> >
> > So, in a nutshell, there's a script that takes care of this post-install
> configuration, that needs to be executed once the target tree of
> directories and script files are in place, copied from the source tree. And
> I'm finding that when the script is called during the build, the
> INSTALL(DIRECTORY ...) command from the CMakeLists.txt directory hasn't
> been run yet, so the tree of script files hasn't been put in place yet and
> the script (and the build) fails.
> >
> > FWIW, if I leave out the add_custom_command and add_custom_target that
> execute the script, the directory tree does copy correctly.
> >
> > I have not found any guidance on how to specify that the directory tree
> gets copied first. How is this normally done?
> >
> >
> > Thanks,
> > CR
> >
> >
> >
>
> I think you might be getting confused by two distinct phases: BUILD and
> INSTALL.
>
> BUILD is what happens when building your sources and all the results of
> this step are in your build directory (or source directory if you do
> in-source building). Both add_custom_command and add_custom_target are
> evaluated (and potentially executed) at BUILD time.  The BUILD phase is
> what is processed when you just do “make” in Makefile terms.
>
> INSTALL is what happens when you request your project to be installed. The
> various install() directives in your CMake files will be processed during
> INSTALL. In Makefile terms, this what happens when you do “make install”
> (BUILD is also done in that case since INSTALL always depends on BUILD)
>
> So the first question is: does this custom step need to be done at BUILD
> time or INSTALL time? Running custom code is easier at BUILD time since you
> have the add_custom_command and the like. If you need to run custom code at
> INSTALL time, maybe consider this:
>
> https://stackoverflow.com/questions/41254902/cmake-run-
> script-for-install-target
>
> …although I have not done something like this myself. I suspect it is
> difficult to get just right, depending on the various platforms you support.
>
> Does that make sense?
>
> -Mike
>
>
>
>
-- 

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] How to have build steps operate on files in a copied directory?

2017-07-10 Thread Christopher E Robison
I've recently begun using CMake on an existing project I've taken over, and
I feel like I'm mostly getting used to it, though there is still a vast
amount to learn.  I've got nearly the entire project building successfully,
with the exception of a directory of external scripts that need to be
configured at the end of the install process to create some index files.

So, in a nutshell, there's a script that takes care of this post-install
configuration, that needs to be executed once the target tree of
directories and script files are in place, copied from the source tree. And
I'm finding that when the script is called during the build, the
INSTALL(DIRECTORY ...) command from the CMakeLists.txt directory hasn't
been run yet, so the tree of script files hasn't been put in place yet and
the script (and the build) fails.

FWIW, if I leave out the add_custom_command and add_custom_target that
execute the script, the directory tree does copy correctly.

I have not found any guidance on how to specify that the directory tree
gets copied first. How is this normally done?


Thanks,
CR
-- 

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