[CMake] include directories not found for object library

2018-05-08 Thread Miklos Espak
Hi,

I have an abstract class that I want to compile into many applications.
Something like this:

baseapp.h
baseapp.cpp
app1.h
app1.cpp
app2.h
app2.cpp
...

I thought of making an object library from baseapp because I want to
compile it only once and it is used only internally.

However, baseapp depends on other libraries, e.g. dcmjpeg, mylib1 and
mylib2, and the include directories of these of these libraries are not
found. For regular libraries and executables, the include directories are
picked up from the target property of the linked libraries, but for object
libraries you cannot specify target link libraries.

I came up with this:

add_library(baseapp OBJECT baseapp.h baseapp.cpp)
target_include_directories(baseapp PUBLIC
  $
  $
  $)

This works, but it does not look too pretty to me.

I am wondering if there is a more elegant way.

E.g. would it be a good idea to propagate the include dirs with the
add_dependencies command? E.g. instead of the above, one could write:

add_dependencies(baseapp dcmjpeg mylib1 mylib2)

Cheers,
Miklos
-- 

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] Memory usage and configuration time for large project

2018-05-08 Thread Malfettone, Kris
I manage a very large project using CMake that I have done significant 
restructuring to lower the CMake configure times.  I will say the one thing 
that surprised me the most is that for one piece of it where we have repeated 
work done say “for each folder in this subdir build 11 executables with a ton 
of code generation.”  If I structure the build as such:

One top level CMakeLists.txt and one single line CMakeLists.txt in each subdir 
containing do_work(${SUBDIR}):
foreach( SUBDIR ${LIST_OF_SUBDIRS} )
   add_subdirectory(${SUBDIR})
endforeach()

Versus:

One top level CMakeLists.txt:
foreach( SUBDIR ${LIST_OF_SUBDIRS} )
   do_work(${SUBDIR})
endforeach()

In short, the decision to do all the work in the same CMakeLists.txt file or do 
I enter and leave a CMakeLists.txt for each directory causes a dramatic 
performance and memory difference.

The add_subdirectory method saves many Gigs of RAM and reduces our configure 
time from 30 minutes to 5 minutes.  Please note I am writing this from memory 
so my numbers may be a bit off but scale is accurate.

I don’t know if this is applicable to your case but it was the biggest saving 
in my project and took a long time to figure out.

-Kris

From: CMake [mailto:cmake-boun...@cmake.org] On Behalf Of Isaiah Norton
Sent: Friday, May 04, 2018 7:51 PM
To: Patrick E Gartung 
Cc: cmake@cmake.org
Subject: Re: [CMake] Memory usage and configuration time for large project

As one ballpark datapoint: a "superbuild" of 3D Slicer 
(slicer.org) has a similar object and library count:

macbook-pro:s5nj inorton$ find ./ -name *.o | wc -l
   14127
macbook-pro:s5nj inorton$ find ./ -name *.dylib -or -name *.so | wc -l
2158

Based on a few quick tests, the aggregate cmake time is probably about 6-8 
minutes for the ninja generator, over the multi-hour build (each dependency is 
configured and built as a separate sub-project via CMake's ExternalProject 
mechanism) -- with the caveat that each of those cmake runs is doing lengthy 
checks that should only be done once if your project strictly uses 
`add_subdirectory`.

As a more concrete point of comparison, building VTK generates 5747 object 
files, and a clean configure on my 2-core macbook takes about 90s.

Isaiah



On Fri, May 4, 2018 at 2:16 PM, Patrick E Gartung 
mailto:gart...@fnal.gov>> wrote:
Just to be clear, the memory and time used are just to configure and generate 
the makefiles or Ninja file. The build itself can take several hours.

On 4/30/18, 4:55 PM, "R0b0t1" mailto:r03...@gmail.com>> 
wrote:

On Mon, Apr 30, 2018 at 4:44 PM, Patrick E Gartung 
mailto:gart...@fnal.gov>> wrote:
>  Hi,
>
> We have a large c/c++/fortran project, CMSSW, that is built with a custom 
tool, scram.
>
> https://github.com/cms-sw/cmssw
>
> The project might move to a cmake based build in the future. The scripts 
to convert to CmakeLists.tx has been written
>
> https://github.com/cms-sw/cmssw2cmake
>
> Tests show that with the cmake files generated with this script, 
configuring the project uses up to 1.5GB of ram and takes 11 minutes when using 
-GMakefiles. Using -GNinja and using the latest cmake, this time can be reduced 
to 8 minutes.
>
> The project builds 14k object files, 2.2k libraries, ~600 binaries, 500 
generated source files with links to ~100 external libraries.
>
> Is this amount of memory usage and time typical for a project of this 
size?
>

I'm inclined to say "yes" as many builds such as Firefox, its
supporting libraries, and Chrome all take lots of time and memory.
Chrome uses Ninja, I might add. But the issue is not CMake itself.
CMake tends to produce better builds.

As I am not intimately familiar with your project, I can't make good
concrete suggestions. You may enjoy reading
https://news.ycombinator.com/item?id=14733829 and searching for build
optimization strategies.

Keep in mind a lot of the blame falls on C++ and Windows, should you
be using Windows. If you aren't using Windows, then the advice in the
comments above should still be relevant, and give you something to go
on.

Cheers,
 R0b0t1

> Patrick Gartung
> Fermilab
>

--

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




IMPORTANT: The information contained in this email and/or its attach

Re: [CMake] Help Accommodating Ninja when including CMAKE_CURRENT_BINARY_DIR

2018-05-08 Thread Robert Maynard
Here is how I would do this (
https://github.com/robertmaynard/Sandbox/tree/master/CMakeCustomCommandAfterTarget).
In my example the executable is the target I want to have a custom
PRE_BUILD step for.
On Sat, Apr 28, 2018 at 5:02 AM Stephen McDowell  wrote:


> After much deliberation, I was never successful in getting a synthetic
target to work as expected.  The dilemma is that `add_custom_command`
cannot specify both `TARGET` and `OUTPUT`, the work flow was something like

> add_custom_target(resource-dependency)
> add_custom_command(TARGET resource-dependency ... PRE_BUILD)
> add_custom_command(OUTPUT  DEPENDS
resource-dependency)
> ...
> add_library(actual-obj-library OBJECt  ...
others ...)
> add_dependencies(actual-obj-library resource-dependency)

> I'm sure that's a flawed approach, but in the end I realized I can
actually generate these files at *configure* time <3  The
add_custom_command was just a call to ${CMAKE_COMMAND} ...
resources/bin2c.cmake.  So in the end, it's actually a lot cleaner for us
to just include(resources/bin2c.cmake).

> I doubt this solution will be widely applicable to many projects, but if
you ever find yourself in a situation where you are doing
add_custom_command, where the custom command is calling ${CMAKE_COMMAND},
don't rely on PRE_BUILD because it's not a guarantee.  If you can, just
execute the script at configure time via an include(...) call.
-- 

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


[CMake] Skipping Tests if FIXTURES_SETUP is skipped

2018-05-08 Thread Jörg Kreuzberger
Hi!

I'm working with the FIXTURES feature of the ctest's and find it very usefull.

I want to skip certain tests if the setup test is skipped

so i added a tests with SKIP_RETURN_CODE feature and set it as FIXTURES_SETUP 
"tty" (just calling command tty -s on unix)
my assumption is that now all tests with FIXTURES_REQUIRED "tty" are also 
skipped.
but it does not seem so. The setup test is skipped, but all tests are executed 
(and fail)

The documentation only says the if the SETUP tests FAILS, the tests requiring 
the FIXTURES_SETUP are not executed,
but then the setup test itself goes into FAIL count, i want it to be skipped

It this a bug or are there better solutions than my hack? I now generate files 
in setup test and add them as REQUIRED_FILES in the dependent tests.


Any help appreciated,
Joerg

-- 

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] cmake finds libxml2 but still says its missing

2018-05-08 Thread Rolf Eike Beer

Am 2018-05-08 14:51, schrieb Florian Lindner:

Hello,

I try to compile my software like

cmake -DCMAKE_TOOLCHAIN_FILE=../../toolchain.cmake 
-DBUILD_SHARED_LIBS=off ../..



cat ../../toolchain.cmake

SET(CMAKE_SYSTEM_NAME Hazelhen)
SET(CMAKE_C_COMPILER   cc)
SET(CMAKE_CXX_COMPILER CC)
SET(CMAKE_Fortran_COMPILER ftn)

which gives me the error:

CMake Error at
/usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:148
(message):
  Could NOT find LibXml2 (missing: LIBXML2_LIBRARIES) (found version 
"2.9.4")

Call Stack (most recent call first):
  /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:388
(_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake/Modules/FindLibXml2.cmake:69
(FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  CMakeLists.txt:73 (find_package)


It can determine the version, e.g. because it can ask pkg-config or 
finds the header, but it does not find the library to link to.



I am a bit puzzled, because it says it found libxml 2.9.4, but then
again does not set the $LIBXML2_LIBRARIES.

Usage is

find_package(LibXml2 REQlesUIRED)


sure?

Eike
--

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


[CMake] cmake finds libxml2 but still says its missing

2018-05-08 Thread Florian Lindner
Hello,

I try to compile my software like

cmake -DCMAKE_TOOLCHAIN_FILE=../../toolchain.cmake -DBUILD_SHARED_LIBS=off ../..

> cat ../../toolchain.cmake
SET(CMAKE_SYSTEM_NAME Hazelhen)
SET(CMAKE_C_COMPILER   cc)
SET(CMAKE_CXX_COMPILER CC)
SET(CMAKE_Fortran_COMPILER ftn)

which gives me the error:

CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:148 
(message):
  Could NOT find LibXml2 (missing: LIBXML2_LIBRARIES) (found version "2.9.4")
Call Stack (most recent call first):
  /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:388 
(_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake/Modules/FindLibXml2.cmake:69 
(FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  CMakeLists.txt:73 (find_package)


I am a bit puzzled, because it says it found libxml 2.9.4, but then again does 
not set the $LIBXML2_LIBRARIES.

Usage is

find_package(LibXml2 REQlesUIRED)
include_directories(${LIBXML2_INCLUDE_DIR})

and later

target_link_libraries(foobar PUBLIC ${LIBXML2_LIBRARIES})

cmake version 3.5.2

Thanks!
Florian
-- 

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