[CMake] find_library finds same library over and again

John R. Cary cary at txcorp.com
Thu Nov 3 07:26:57 EDT 2011


Feels like I am doing something wrong.

Looking for multiple libraries:

$ cat CMakeLists.txt
set(mylibdir /contrib/netcdf-4.1.2-ser/lib)
foreach (name netcdf_c++ netcdff netcdf)
   message("Looking for ${name} in ${mylibdir}.")
   find_library(mylib NAMES ${name} PATHS ${mylibdir} NO_DEFAULT_PATH)
   if (mylib)
     message("Found: ${mylib}.")
     list(APPEND mylibs ${mylib})
   else ()
     message("Not found.")
   endif ()
endforeach ()

But continues to find the first each time:

$ cmake .
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Checking whether C compiler has -isysroot
-- Checking whether C compiler has -isysroot - yes
-- Checking whether C compiler supports OSX deployment target flag
-- Checking whether C compiler supports OSX deployment target flag - yes
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Checking whether CXX compiler has -isysroot
-- Checking whether CXX compiler has -isysroot - yes
-- Checking whether CXX compiler supports OSX deployment target flag
-- Checking whether CXX compiler supports OSX deployment target flag - yes
-- 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
Looking for netcdf_c++ in /contrib/netcdf-4.1.2-ser/lib.
Found: /contrib/netcdf-4.1.2-ser/lib/libnetcdf_c++.dylib.
Looking for netcdff in /contrib/netcdf-4.1.2-ser/lib.
Found: /contrib/netcdf-4.1.2-ser/lib/libnetcdf_c++.dylib.
Looking for netcdf in /contrib/netcdf-4.1.2-ser/lib.
Found: /contrib/netcdf-4.1.2-ser/lib/libnetcdf_c++.dylib.
CMake Warning (dev) in CMakeLists.txt:
   No cmake_minimum_required command is present.  A line of code such as

     cmake_minimum_required(VERSION 2.8)

   should be added at the top of the file.  The version specified may be 
lower
   if you wish to support older CMake versions for this project.  For more
   information run "cmake --help-policy CMP0000".
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Configuring done
-- Generating done
-- Build files have been written to: /Users/cary

even though all libraries are present:

$ ls /contrib/netcdf-4.1.2-ser/lib
libnetcdf.7.dylib    libnetcdf_c++.a        libnetcdff.dylib
libnetcdf.a        libnetcdf_c++.dylib    libnetcdff.la
libnetcdf.dylib        libnetcdf_c++.la    pkgconfig
libnetcdf.la        libnetcdff.5.dylib
libnetcdf_c++.4.dylib    libnetcdff.a

$ cmake --version
cmake version 2.8.5

$ uname -a
Darwin numbersix.local 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun  7 
16:33:36 PDT 2011; root:xnu-1504.15.3~1/RELEASE_I386 i386

?????

John Cary



More information about the CMake mailing list