title: CMake cross compilation with Poky
body: <p>I try to set up my cross-platform development environment with CMake.</p>
  
  <p>I encounter the following error only when I try to compile with poky toolchain:</p>
  
  <p>make[2]: <em>*</em> No rule to make '/opt/poky/1.3/sysroots/armv5te-poky-linux-gnueabi/usr/lib/libboost_thread.so', needed by 'test'. Stop</p>
  
  <p>I tried to set up the CMake toolchain in two different methods and the result is the same.</p>
  
  <p>Method1 (simple):</p>
  
  <pre><code>###################################################################################
  # Cross compile using Poky prebuilt toolchains, you need to source the
  # environment first:
  #
  # $ rm -fr build; mkdir build; cd build
  # $ source /opt/poky/1.3/environment-setup-armv5te-poky-linux-gnueabi
  # $ cmake -DCMAKE_TOOLCHAIN_FILE=Toolchains/arm-poky-linux-gnueabi-simple.cmake
  # $ make
  ###################################################################################
  
  SET(CMAKE_SYSTEM_NAME Linux)
  SET(CMAKE_SYSTEM_VERSION 1)
  
  SET(CMAKE_FIND_ROOT_PATH $ENV{OECORE_TARGET_SYSROOT})
  SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
  SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
  SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
  </code></pre>
  
  <p>Method2:</p>
  
  <pre><code># this one is important
  SET( CMAKE_SYSTEM_NAME Linux )
  
  # this one not so much
  SET( CMAKE_SYSTEM_VERSION 1 )
  
  # specify the cross compiler
  SET( CROSS_COMPILER_PATH /opt/poky/1.3/sysroots/x86_64-pokysdk-linux/usr/bin/armv5te-poky-linux-gnueabi )
  SET( C_CROSS_COMPILER arm-poky-linux-gnueabi- )
  
  FIND_PROGRAM( CCACHE ccache )
  IF( CCACHE )
      SET( CMAKE_C_COMPILER "${CCACHE}" "${CROSS_COMPILER_PATH}/${C_CROSS_COMPILER}gcc" )
      SET( CMAKE_CXX_COMPILER "${CCACHE}" "${CROSS_COMPILER_PATH}/${C_CROSS_COMPILER}g++" )
  ELSE( CCACHE )
      SET( CMAKE_C_COMPILER "${CROSS_COMPILER_PATH}/${C_CROSS_COMPILER}gcc" "" )
      SET( CMAKE_CXX_COMPILER "${CROSS_COMPILER_PATH}/${C_CROSS_COMPILER}g++" "" )
  ENDIF(CCACHE)
  
  SET( CMAKE_RANLIB "${CROSS_COMPILER_PATH}/${C_CROSS_COMPILER}ranlib" )
  SET( CMAKE_AR "${CROSS_COMPILER_PATH}/${C_CROSS_COMPILER}ar" )
  
  SET( CMAKE_COMPILER_IS_GNUCC 1 )
  SET( CMAKE_COMPILER_IS_GNUCXX 1 )
  
  INCLUDE_DIRECTORIES( BEFORE SYSTEM /opt/poky/1.3/sysroots/armv5te-poky-linux-gnueabi/usr/include )
  LINK_DIRECTORIES( /opt/poky/1.3/sysroots/armv5te-poky-linux-gnueabi/usr/lib )
  
  # where is the target environment 
  SET( CMAKE_FIND_ROOT_PATH /opt/poky/1.3/sysroots/armv5te-poky-linux-gnueabi/ )
  
  #search for libraries and header files only in the target environment
  SET( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
  SET( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
  
  # search for programs in the build host directories
  SET( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
  </code></pre>
  
  <p>My CMake project is:</p>
  
  <pre><code>cmake_minimum_required( VERSION 2.8.9 )
  
  project ( TEST ) 
  
  set( BOOST_COMPONENTS thread )
  
  find_package( Boost COMPONENTS ${BOOST_COMPONENTS} )
  
  add_executable( test test.cpp ) 
  target_link_libraries( test ${Boost_THREAD_LIBRARY} )
  </code></pre>
  
  <p>My cpp code used for tests:</p>
  
  <pre><code>#include &lt;boost/thread/thread.hpp&gt;
  #include &lt;iostream&gt;
  
  void hello()
  {
      std::cout &lt;&lt; "Hello!" &lt;&lt; std::endl;
  }
  
  int main()
  {
      boost::thread thrd( &amp;hello );
      thrd.join();
      return 0;
  }
  </code></pre>
  
  <p>Thank you by advance for your help</p>