CMake 3.11.3: set properties on the command line?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

CMake 3.11.3: set properties on the command line?

Paul Smith
Hi all.

I'm using cmake with a cross-compiler environment, but building third
party packages that are configured with CMake.  So when I invoke cmake
for those packages I add this options to the command line:

  -DCMAKE_FIND_ROOT_PATH=/my/sysroot

However, this is not working because it's finding 32bit libraries.  For
example if the package's CMakeLists.txt file contains this:

  find_package(ZLIB REQUIRED)

then my link line ends up containing:

  /my/sysroot/usr/lib/libz.so

which is the 32bit version and the link fails.  The 64bit version DOES
exist exactly as it should:

  $ ls -1 /my/sysroot/usr/lib*/libz.so*
  /my/sysroot/tools/usr/lib/libz.so
  /my/sysroot/tools/usr/lib64/libz.so

and the link works if I do it by hand with the right path.  I don't
know why it's not automatically looking for lib64; I checked and CMake
knows I want a 64bit build.  For example I see this after running:

  CMakeFiles/3.11.3/CMakeCXXCompiler.cmake:set(CMAKE_CXX_SIZEOF_DATA_PTR "8")

Actually I wish cmake would just add "-lz" to the command line and let
the linker figure it all out rather than trying to second-guess things.
Then it would "just work".

In any event, if I edit the CMakeLists.txt in the package to set the
global property FIND_LIBRARY_USE_LIB64_PATHS to ON, then it all works
fine:

  set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS ON)

But I can't see any way to set that property from the command line,
without editing the package's CMakeLists.txt file which I obviously
don't want to do.

Help for either (a) figuring out why cmake incorrectly chooses 32bit
libraries or (b) setting the property without editing third-party
CMakeLists.txt files would be much appreciated!!

--

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
Reply | Threaded
Open this post in threaded view
|

Re: CMake 3.11.3: set properties on the command line?

Craig Scott-3


On Tue, Dec 18, 2018 at 7:42 AM Paul Smith <[hidden email]> wrote:
Hi all.

I'm using cmake with a cross-compiler environment, but building third
party packages that are configured with CMake.  So when I invoke cmake
for those packages I add this options to the command line:

  -DCMAKE_FIND_ROOT_PATH=/my/sysroot

However, this is not working because it's finding 32bit libraries.  For
example if the package's CMakeLists.txt file contains this:

  find_package(ZLIB REQUIRED)

then my link line ends up containing:

  /my/sysroot/usr/lib/libz.so

which is the 32bit version and the link fails.  The 64bit version DOES
exist exactly as it should:

  $ ls -1 /my/sysroot/usr/lib*/libz.so*
  /my/sysroot/tools/usr/lib/libz.so
  /my/sysroot/tools/usr/lib64/libz.so

and the link works if I do it by hand with the right path.  I don't
know why it's not automatically looking for lib64; I checked and CMake
knows I want a 64bit build.  For example I see this after running:

  CMakeFiles/3.11.3/CMakeCXXCompiler.cmake:set(CMAKE_CXX_SIZEOF_DATA_PTR "8")

Actually I wish cmake would just add "-lz" to the command line and let
the linker figure it all out rather than trying to second-guess things.
Then it would "just work".

In any event, if I edit the CMakeLists.txt in the package to set the
global property FIND_LIBRARY_USE_LIB64_PATHS to ON, then it all works
fine:

  set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS ON)

But I can't see any way to set that property from the command line,
without editing the package's CMakeLists.txt file which I obviously
don't want to do.

Help for either (a) figuring out why cmake incorrectly chooses 32bit
libraries or (b) setting the property without editing third-party
CMakeLists.txt files would be much appreciated!!


If you are setting your own sysroot, are you using a toolchain file? You could put your set_property() command in your toolchain file if you're using one.

If you're not using a toolchain file and don't want to go that route, you could potentially inject the commands you want using the CMAKE_PROJECT_<projectName>_INCLUDE feature. It allows you to effectively include a file immediately after a project() command without having to actually edit the CMakeLists.txt that contains that project() command.

Those techniques aside, it's interesting that you need to add this manual workaround at all. I suspect this code might be why it is being turned off for you, but without more detail about your build setup, it's hard to say. If you use a toolchain file and set CMAKE_SYSTEM_NAME to anything (even the same as the CMAKE_HOST_SYSTEM_NAME), CMAKE_CROSSCOMPILING will be TRUE, which I suspect would prevent the problem you're seeing.

--
Craig Scott
Melbourne, Australia


--

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
Reply | Threaded
Open this post in threaded view
|

Re: CMake 3.11.3: set properties on the command line?

Paul Smith
On Tue, 2018-12-18 at 08:22 +1100, Craig Scott wrote:
If you are setting your own sysroot, are you using a toolchain file? You could put your set_property() command in your toolchain file if you're using one.

Those techniques aside, it's interesting that you need to add this manual workaround at all. I suspect this code might be why it is being turned off for you, but without more detail about your build setup, it's hard to say. If you use a toolchain file and set CMAKE_SYSTEM_NAME to anything (even the same as the CMAKE_HOST_SYSTEM_NAME), CMAKE_CROSSCOMPILING will be TRUE, which I suspect would prevent the problem you're seeing.

I was not using a toolchain file, but switching to use one (that set CMAKE_SYSTEM_NAME) solved the problem.

Thanks!

--

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