[CMake] CMake searching for shared libraries in invalid paths

Mark Thomas markysays at yahoo.com
Wed Jun 1 16:21:54 EDT 2016


Hi cmake users,     Reposting question from stackoverflow (http://stackoverflow.com/questions/37449511/cmake-searching-for-shared-libraries-in-invalid-paths) since I didn't get a good answer there:
I noticed that the cmake generation step in my project was taking a long time and so I ran cmake through strace to figure out the root cause. I found that cmake was trying to find internal shared libraries in the wrong locations repeatedly, which was causing a lot of unnecessary file system lookups. Here is a simple project that illustrates the problem:
    $ ll -R                                                                                                                                                                                                                                                         .:    total 20K    drwxr-xr-x 2 mark mark 4.0K May 25 16:22 alpha    drwxr-xr-x 2 mark mark 4.0K May 25 16:22 beta    drwxr-xr-x 2 mark mark 4.0K May 25 16:42 build    -rw-r--r-- 1 mark mark  185 May 25 16:20 CMakeLists.txt    -rw-r--r-- 1 mark mark    0 May 25 16:16 dummy.cc    drwxr-xr-x 2 mark mark 4.0K May 25 16:22 gamma        ./alpha:    total 4.0K    -rw-r--r-- 1 mark mark  0 May 25 16:16 alpha.cc    -rw-r--r-- 1 mark mark 69 May 25 16:20 CMakeLists.txt        ./beta:    total 4.0K    -rw-r--r-- 1 mark mark  0 May 25 16:16 beta.cc    -rw-r--r-- 1 mark mark 67 May 25 16:18 CMakeLists.txt        ./build:    total 0        ./gamma:    total 4.0K    -rw-r--r-- 1 mark mark 35 May 25 16:19 CMakeLists.txt    -rw-r--r-- 1 mark mark  0 May 25 16:16 gamma.cc 
alpha.cc, beta.cc, gamma.cc and dummy.cc are all empty cc files. Here are the contents of all the CMakLists.txt files:
Top level CMakeLists.txt
    $ cat CMakeLists.txt     cmake_minimum_required(VERSION 2.8)
    add_subdirectory(alpha)    add_subdirectory(beta)    add_subdirectory(gamma)
    add_executable(dummy_exec dummy.cc)    target_link_libraries(dummy_exec alpha)
alpha/CMakeLists.txt 
    $ cat alpha/CMakeLists.txt     add_library(alpha SHARED alpha.cc)    target_link_libraries(alpha beta)
beta/CMakeLists.txt
    $ cat beta/CMakeLists.txt     add_library(beta SHARED beta.cc)    target_link_libraries(beta gamma)
gamma/CMakeLists.txt 
    $ cat gamma/CMakeLists.txt     add_library(gamma SHARED gamma.cc)

I invoke cmake (through strace) as follows:
    $ cd build/    $ strace -f -o /tmp/s.out  cmake  ..                                                                                                                                                                                                              -- The C compiler identification is GNU 4.8.4    -- The CXX compiler identification is GNU 4.8.4    -- Check for working C compiler: /usr/bin/cc    -- Check for working C compiler: /usr/bin/cc -- works    -- Detecting C compiler ABI info    -- Detecting C compiler ABI info - done    -- Check for working CXX compiler: /usr/bin/c++    -- Check for working CXX compiler: /usr/bin/c++ -- works    -- Detecting CXX compiler ABI info    -- Detecting CXX compiler ABI info - done    -- Configuring done    -- Generating done    -- Build files have been written to: /home/mark/Downloads/cmake/build

When I inspect the strace output, I see it trying to access libalpha in invalid locations (such as under the beta/ and gamma/ sub directories):
    31430 access("/home/mark/Downloads/cmake/build/beta/libalpha.so", R_OK) = -1 ENOENT (No such file or directory)    31430 access("/home/mark/Downloads/cmake/build/gamma/libalpha.so", R_OK) = -1 ENOENT (No such file or directory)
Similarly, it is trying to access libbeta and libgamma in invalid locations:
    31430 access("/home/mark/Downloads/cmake/build/alpha/libbeta.so", R_OK) = -1 ENOENT (No such file or directory)    31430 access("/home/mark/Downloads/cmake/build/gamma/libbeta.so", R_OK) = -1 ENOENT (No such file or directory)
    31430 access("/home/mark/Downloads/cmake/build/alpha/libgamma.so", R_OK) = -1 ENOENT (No such file or directory)    31430 access("/home/mark/Downloads/cmake/build/beta/libgamma.so", R_OK) = -1 ENOENT (No such file or directory)
For a large project with many shared libraries and many dependencies, these invalid lookups add up and seem to be causing big delays at the makefile generation step. Any idea on why this is happening and how I could prevent cmake from searching in these invalid paths ? 
thanksmark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160601/a8c3d2e7/attachment-0001.html>


More information about the CMake mailing list