Re: [CMake] (no subject)

2014-01-02 Thread Matt Wilbur
On Thu, Jan 2, 2014 at 10:20 AM, Magnus Therning mag...@therning.orgwrote:

 On Thu, Jan 02, 2014 at 12:14:38AM -0500, Matt Wilbur wrote:
  With a bit of thought and source code reading, I sorted this out.
  Let me know if you'd like me to post my answer to my own question.

 Yes, please do.

 I'm sure you've found yourself in the very irritating situation where
 you're looking for the answer to some question, but all you can find
 is other people asking the same question in various fora.  By
 answering your own question you'll help other people avoid that
 irritating situation when they are looking around for an answer to
 this particular question. :)


Very good point.

So, the flaw in my understanding was that the ONLY_CMAKE_FIND_ROOT_PATH |
NO_CMAKE_FIND_ROOT_PATH | CMAKE_FIND_ROOT_PATH_BOTH had no effect if
NO_DEFAULTS is used.

NO_DEFAULTS only affects the construction of the list of paths to be
searched.  i.e. NO_DEFAULTS means the list of paths to be searched consists
only of the paths specified by the PATHS argument (maybe others - haven't
looked into that one).  Point is, all the find_XXX commands construct a
list of paths to be searched, consisting of what is specified in the
command plus maybe some other paths.

The effect of ONLY_CMAKE_FIND_ROOT_PATH | NO_CMAKE_FIND_ROOT_PATH |
CMAKE_FIND_ROOT_PATH_BOTH (and, similarly CMAKE_FIND_ROOT_PATH_MODE_*) is
to determine how that list of search paths is further processed to create
the final list of paths searched by CMake.

Call the initial list of paths to be searched InitialSearchPaths.  Call
RerootedSearchPaths the result of prepending each element of
CMAKE_FIND_ROOT to each element of InitialSearchPaths.  In Clojure (since
I've been playing with it in my personal time and it succinctly captures
the list processing):

(flatten (for [r CMAKE_FIND_ROOT] (map #(str r %) InitialSearchPaths)))

The actual list of search paths, SearchPaths would be one of

IntitalSearchPaths
RerootedSearchPaths
(concat RerootedSearchPaths  IntitalSearchPaths)
--

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

[CMake] (no subject)

2014-01-01 Thread Matt Wilbur
Hello CMakers,

I’m seeing behavior with find_path that seems to be inconsistent with the
cmake documentation.  According to the documentation (as I understand it),
when NO_DEFAULT_PATH is set, the CMAKE_FIND_ROOT_PATH should have no impact
on where find_path looks.  However it seems to be having a big impact when
the CMAKE_TOOLCHAIN_FILE is used.

You’ll see between Experiment 2 and Experiment 3 below, where the only
difference is setting

set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

and this means the difference between success and failure of find_path,
even though CMAKE_FIND_ROOT_PATH should have no impact if NO_DEFAULT_PATH
is used.

Furthermore CMAKE_FIND_ROOT_PATH_MODE_INCLUDE seems to have this impact
only when cross-compiling, not when

Thoughts?  Is this behavior seem odd to anyone else?

Matt


Experiment 1:

CMakeLists.txt:

cmake_minimum_required(VERSION 2.8)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
find_path(ZLIB_INCLUDE_DIR NAMES zlib.h PATHS
/home/vagrant/Projects/cmake-test/zlib-1.2.8 NO_DEFAULT_PATH)
message(Found: ${ZLIB_INCLUDE_DIR}”)

Output from cmake:

cmake ..

-- The C compiler identification is GNU 4.6.3
-- The CXX compiler identification is GNU 4.6.3
-- 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
Found: /home/vagrant/Projects/cmake-test/zlib-1.2.8
-- Configuring done
-- Generating done
-- Build files have been written to:
/home/vagrant/Projects/another-cmake-test/build

Experiment 2:

CMakeLists.txt:  same as above

Toolchain file:

# this one is important
SET(CMAKE_SYSTEM_NAME Linux)

# specify the cross compiler
set(CMAKE_C_COMPILER /opt/freescale-2010.09/bin/powerpc-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER /opt/freescale-2010.09/bin/powerpc-linux-gnu-g++)

# where is the target environment
set(CMAKE_FIND_ROOT_PATH /opt/freescale-2010.09)

# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

Output from cmake:

-- The C compiler identification is GNU 4.5.1
-- The CXX compiler identification is GNU 4.5.1
-- Check for working C compiler:
/opt/freescale-2010.09/bin/powerpc-linux-gnu-gcc
-- Check for working C compiler:
/opt/freescale-2010.09/bin/powerpc-linux-gnu-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler:
/opt/freescale-2010.09/bin/powerpc-linux-gnu-g++
-- Check for working CXX compiler:
/opt/freescale-2010.09/bin/powerpc-linux-gnu-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
Found: ZLIB_INCLUDE_DIR-NOTFOUND
-- Configuring done
-- Generating done
-- Build files have been written to:
/home/vagrant/Projects/another-cmake-test/build

Experiment 3:

CMakeLists.txt:

cmake_minimum_required(VERSION 2.8)

find_path(ZLIB_INCLUDE_DIR NAMES zlib.h PATHS
/home/vagrant/Projects/cmake-test/zlib-1.2.8 NO_DEFAULT_PATH)
message(Found: ${ZLIB_INCLUDE_DIR}”)

Toolchain file:

 this one is important
SET(CMAKE_SYSTEM_NAME Linux)

# specify the cross compiler
set(CMAKE_C_COMPILER /opt/freescale-2010.09/bin/powerpc-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER /opt/freescale-2010.09/bin/powerpc-linux-gnu-g++)

# where is the target environment
set(CMAKE_FIND_ROOT_PATH /opt/freescale-2010.09)

# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)

Output from cmake:

cmake -DCMAKE_TOOLCHAIN_FILE=../TC-powerpc-e500v2.cmake ..

-- The C compiler identification is GNU 4.5.1
-- The CXX compiler identification is GNU 4.5.1
-- Check for working C compiler:
/opt/freescale-2010.09/bin/powerpc-linux-gnu-gcc
-- Check for working C compiler:
/opt/freescale-2010.09/bin/powerpc-linux-gnu-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler:
/opt/freescale-2010.09/bin/powerpc-linux-gnu-g++
-- Check for working CXX compiler:
/opt/freescale-2010.09/bin/powerpc-linux-gnu-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
Found: /home/vagrant/Projects/cmake-test/zlib-1.2.8
-- Configuring done
-- Generating done
-- Build files have been written to:
/home/vagrant/Projects/another-cmake-test/build
--

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: 

Re: [CMake] How to locate clang-format

2014-01-01 Thread Matt Wilbur


On Wednesday, January 1, 2014 at 4:27 PM, Michi Henning wrote:

 I would like to add a target to format my code with clang-format. However, 
 clang-format isn't installed as clang-format (at least not on Ubuntu). 
 Instead, it installs itself as clang-format-3.4, clang-format-3.5, etc.
 
 Is there a reasonable way to locate the binary with the largest version 
 number = than some minimum version? For example, I'd like to find 
 clang-format-3.5 or later (even if the next version happens to be 
 clang-format-4.0), and then create a symlink in the build tree for other 
 scripts to use.
I am a CMake newbie (like, just this week), and this is only a partial solution 
(I think I could probably flesh it out if we knew what the version string would 
look like in all situations), but maybe something like this:

CMakeLists.txt:

set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR})
find_package(ClangFormat)

if(CLANG_FORMAT_FOUND)
message(clang-format executable: ${CLANG_FORMAT_EXECUTABLE})
message(clang-format version: ${CLANG_FORMAT_VERSION})
else()
message(clang-format executable not found)
endif()


FindClangFormat.cmake (in the CMAKE_SOURCE_DIR):

string(REPLACE : ; _PATH $ENV{PATH})
foreach(p ${_PATH})
file(GLOB cand ${p}/clang-format*)
if(cand)
set(CLANG_FORMAT_EXECUTABLE ${cand})
set(CLANG_FORMAT_FOUND ON)
execute_process(COMMAND ${CLANG_FORMAT_EXECUTABLE} -version 
OUTPUT_VARIABLE clang_out )
string(REGEX MATCH .*\(version[^\n]*\)\n version ${clang_out})
set(CLANG_FORMAT_VERSION ${CMAKE_MATCH_1})
break()
else()
set(CLANG_FORMAT_FOUND OFF)
endif()

endforeach()

Matt

--

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

Re: [CMake] (no subject)

2014-01-01 Thread Matt Wilbur
With a bit of thought and source code reading, I sorted this out.  Let me know 
if you'd like me to post my answer to my own question.

Matt

 On Jan 1, 2014, at 11:13 AM, Matt Wilbur wilb...@gmail.com wrote:
 
 Hello CMakers,
 
 I’m seeing behavior with find_path that seems to be inconsistent with the 
 cmake documentation.  According to the documentation (as I understand it), 
 when NO_DEFAULT_PATH is set, the CMAKE_FIND_ROOT_PATH should have no impact 
 on where find_path looks.  However it seems to be having a big impact when 
 the CMAKE_TOOLCHAIN_FILE is used.  
 
 You’ll see between Experiment 2 and Experiment 3 below, where the only 
 difference is setting 
 
 set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
 
 and this means the difference between success and failure of find_path, even 
 though CMAKE_FIND_ROOT_PATH should have no impact if NO_DEFAULT_PATH is used.
 
 Furthermore CMAKE_FIND_ROOT_PATH_MODE_INCLUDE seems to have this impact only 
 when cross-compiling, not when 
 
 Thoughts?  Is this behavior seem odd to anyone else?
 
 Matt
 
 
 Experiment 1:
 
 CMakeLists.txt:
 
 cmake_minimum_required(VERSION 2.8)
 set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
 find_path(ZLIB_INCLUDE_DIR NAMES zlib.h PATHS 
 /home/vagrant/Projects/cmake-test/zlib-1.2.8 NO_DEFAULT_PATH)
 message(Found: ${ZLIB_INCLUDE_DIR}”)
 
 Output from cmake:
 
 cmake ..
 
 -- The C compiler identification is GNU 4.6.3
 -- The CXX compiler identification is GNU 4.6.3
 -- 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
 Found: /home/vagrant/Projects/cmake-test/zlib-1.2.8
 -- Configuring done
 -- Generating done
 -- Build files have been written to: 
 /home/vagrant/Projects/another-cmake-test/build
 
 Experiment 2:
 
 CMakeLists.txt:  same as above
 
 Toolchain file: 
 
 # this one is important
 SET(CMAKE_SYSTEM_NAME Linux)
 
 # specify the cross compiler
 set(CMAKE_C_COMPILER /opt/freescale-2010.09/bin/powerpc-linux-gnu-gcc)
 set(CMAKE_CXX_COMPILER /opt/freescale-2010.09/bin/powerpc-linux-gnu-g++)
 
 # where is the target environment
 set(CMAKE_FIND_ROOT_PATH /opt/freescale-2010.09)
 
 # search for programs in the build host directories
 SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
 # for libraries and headers in the target directories
 SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
 SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
 
 Output from cmake:
 
 -- The C compiler identification is GNU 4.5.1
 -- The CXX compiler identification is GNU 4.5.1
 -- Check for working C compiler: 
 /opt/freescale-2010.09/bin/powerpc-linux-gnu-gcc
 -- Check for working C compiler: 
 /opt/freescale-2010.09/bin/powerpc-linux-gnu-gcc -- works
 -- Detecting C compiler ABI info
 -- Detecting C compiler ABI info - done
 -- Check for working CXX compiler: 
 /opt/freescale-2010.09/bin/powerpc-linux-gnu-g++
 -- Check for working CXX compiler: 
 /opt/freescale-2010.09/bin/powerpc-linux-gnu-g++ -- works
 -- Detecting CXX compiler ABI info
 -- Detecting CXX compiler ABI info - done
 Found: ZLIB_INCLUDE_DIR-NOTFOUND
 -- Configuring done
 -- Generating done
 -- Build files have been written to: 
 /home/vagrant/Projects/another-cmake-test/build
 
 Experiment 3:
 
 CMakeLists.txt:
 
 cmake_minimum_required(VERSION 2.8)
 
 find_path(ZLIB_INCLUDE_DIR NAMES zlib.h PATHS 
 /home/vagrant/Projects/cmake-test/zlib-1.2.8 NO_DEFAULT_PATH)
 message(Found: ${ZLIB_INCLUDE_DIR}”)
 
 Toolchain file:
 
  this one is important
 SET(CMAKE_SYSTEM_NAME Linux)
 
 # specify the cross compiler
 set(CMAKE_C_COMPILER /opt/freescale-2010.09/bin/powerpc-linux-gnu-gcc)
 set(CMAKE_CXX_COMPILER /opt/freescale-2010.09/bin/powerpc-linux-gnu-g++)
 
 # where is the target environment
 set(CMAKE_FIND_ROOT_PATH /opt/freescale-2010.09)
 
 # search for programs in the build host directories
 SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
 # for libraries and headers in the target directories
 SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
 
 Output from cmake:
 
 cmake -DCMAKE_TOOLCHAIN_FILE=../TC-powerpc-e500v2.cmake ..
 
 -- The C compiler identification is GNU 4.5.1
 -- The CXX compiler identification is GNU 4.5.1
 -- Check for working C compiler: 
 /opt/freescale-2010.09/bin/powerpc-linux-gnu-gcc
 -- Check for working C compiler: 
 /opt/freescale-2010.09/bin/powerpc-linux-gnu-gcc -- works
 -- Detecting C compiler ABI info
 -- Detecting C compiler ABI info - done
 -- Check for working CXX compiler: 
 /opt/freescale-2010.09/bin/powerpc-linux-gnu-g++
 -- Check for working CXX compiler: 
 /opt/freescale-2010.09/bin/powerpc-linux-gnu-g++ -- works
 -- Detecting CXX compiler ABI info
 -- Detecting CXX compiler ABI info - done
 Found: /home/vagrant/Projects/cmake-test/zlib-1.2.8
 -- Configuring done
 -- Generating