0

I have a project which builds for PPC, the Toolchain is working correctly, i can build when the sysroot is installed under /opt/poky/1.5. Now i tried to move that Installation to the Project Directory (it is not a part of the Repository there, it is just installed there so it is not reliant on that fix path, so that everyone can check out the project and build it wothout setting up the sysroot under that fixed folder).

To achieve this I set CMAKE_SYSROOT to "${PROJECT_SOURCE_DIR}/poky" where the poky will be installed upon execution of a custom build script (the project also needs to build a secure image, so it is way simpler to use a build script instead of anything else, also this is convenient for jenkins).

Since the CMAKE_SYSROOT is build from the PROJECT_SOURCE_DIR which is different for the CMakeTestCCompiler Project, the cmake call fails teloling me that the CCompiler is broken of course. So I want to know, how I am supposed to get the CMakeTestCCompiler Project to compile with the same CMAKE_SYSROOT variable, without altering the CMakeTestCCompiler Project itself (of course).

Somehow I cannot find an answer anywhere, it seems that noone ever had this issue (which frankly i cannot understand, this should be a common setup in my opinion). (Or maybe i am just too much of a noob when it comes to CMAKE, which i will gladly admit)

I am not interested in solutions like: "JUST INSTALL IT IN A FIX PATH" or such... please, I need the setup like this, I have reasons for that.

THX for reading/trying/answering/helping Have a nice day

EDIT1:

In CMakeLists.txt (top level CMakeFile so it should be used by any build):

`SET(CMAKE_SYSROOT "${PROJECT_SOURCE_DIR}/poky/sysroots")`

In ToolchainCMake (the one given to the cmake as CMAKE_TOOLCHAIN_FILE):

`SET(CMAKE_SYSTEM_NAME Linux)`
`SET(CMAKE_SYSTEM_VERSION 1)`
`SET(CMAKE_SYSROOT "${PROJECT_SOURCE_DIR}/poky/sysroots")`
`SET(COMPILER_ROOT ${PROJECT_SOURCE_DIR}/poky/sysroots/i686-pokysdk-linux/usr/bin/powerpc-poky-linux-gnuspe)`
`SET(CMAKE_C_COMPILER ${COMPILER_ROOT}/powerpc-poky-linux-gnuspe-gcc)`
`SET(CMAKE_CXX_COMPILER ${COMPILER_ROOT}/powerpc-poky-linux-gnuspe-g++)`
`MESSAGE("CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}")`
`MESSAGE("CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")`
`MESSAGE("COMPILER_ROOT: ${COMPILER_ROOT}")`
`SET(CMAKE_FIND_ROOT_PATH ${SYS_ROOT}/ppce500v2-poky-linux-gnuspe)`
`SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)`
`SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)`
`SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)`

EDIT2:

I used the

`set(CMAKE_C_COMPILER_WORKS 1 CACHE INTERNAL "")`
`set(CMAKE_CXX_COMPILER_WORKS 1 CACHE INTERNAL "")`

settings to simulate the CMakeTestCCompiler build succeeding and realized that I am facing some additional problems: It seem that the packages are looked up on the system instead of the CMAKE_SYSROOT folder. Even tried the

`SET(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT})`

to try to force the search in there, but without luck. In the CMakeError.log I can see, that the compiler itself was configured with the prefix option that points to /opt/poky/1.5, the path that i want to "overwrite", now I am not sure if the compiler could even deal with an alternate path.

I felt the need to add these information, they not really add to the problem at hand.

ERRORS:

I also found some errors in the above cmake:

`SET(CMAKE_SYSROOT "${PROJECT_SOURCE_DIR}/poky/sysroots")`

must be

`SET(CMAKE_SYSROOT "${PROJECT_SOURCE_DIR}/poky/sysroots/ppce500v2-poky-linux-gnuspe")`

instead and therefor the

`SET(CMAKE_FIND_ROOT_PATH ${SYS_ROOT}/ppce500v2-poky-linux-gnuspe)`

changes to

`SET(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT})`
MDeero
  • 370
  • 1
  • 4
  • 11
  • Could you please add your toolchain file? For possible solutions see [here](http://stackoverflow.com/questions/37356957/cmake-command-line-definitions-not-perpetuating-to-toolchain-file) and [here](http://stackoverflow.com/questions/38359796/cmake-amrcc-custom-linker). – Florian Sep 07 '16 at 08:26
  • What is PROJECT_SOURCE_PATH? What I know is that you cannot initiate a project before parsing the toolchain file. https://public.kitware.com/Bug/view.php?id=15999 – Antonio Sep 07 '16 at 08:43
  • PROJECT_SOURCE_DIR... point taken – MDeero Sep 07 '16 at 09:02
  • Toolchain file added, the links are not helpful though. – MDeero Sep 07 '16 at 09:02
  • Have you used CMake toolchain file before moving cross compiler from `/opt/poky/1.5` to `${PROJECT_SOURCE_DIR}/poky`? Which version of cmake are you using? – smbear Sep 08 '16 at 06:36

1 Answers1

1

EDIT: Whole answer changed.

My first suspicion was that the problem is that value of ${PROJECT_SOURCE_DIR} is not known in CMAKE_TOOLCHAIN_FILE as it is processed before CMakeLists.txt. But this isn't true.

I had similar problem (CMake 2.8.12.2), everything worked OK, when I passed cross compiler by CC environment variable with --sysroot option, i.e. CMake was invoked as follows:

CC="arm-linux-gnueabi-gcc --sysroot=/path/to/sysroot" cmake /path/to/sources

When I switched to using toolchain file, CMake started to report that C compiler doesn't work.

To workaround this problem, I use CMakeForceCompiler package. Parts toolchain file (along with comments) I think are relevant:

include(CMakeForceCompiler)

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_VERSION 1)

# Force compiler - only option that actually works
cmake_force_c_compiler  (${TOOLCHAIN_PATH}/bin/arm-linux-gnueabi-gcc GNU)
cmake_force_cxx_compiler(${TOOLCHAIN_PATH}/bin/arm-linux-gnueabi-g++ GNU)

# NOTE: CMAKE_SYSROOT doesn't work as expected
add_definitions("--sysroot=${TOOLCHAIN_SYSROOT}")

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --sysroot=${TOOLCHAIN_SYSROOT}" CACHE INTERNAL "" FORCE)

Note, that TOOLCHAIN_PATH and TOOLCHAIN_SYSROOT are my local variables set before.

smbear
  • 1,007
  • 9
  • 17
  • PROJECT_SOURCE_DIR is available, the verbose messages of the cmake and compiler commands show the full paths. – MDeero Sep 07 '16 at 12:06
  • [Here](http://stackoverflow.com/a/39917685/3364871) I present another solution either. In my project for your approach it is needed to add `set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --sysroot=${MYSYSROOT}" CACHE INTERNAL "" FORCE)` as well. – Maxim Suslov Oct 07 '16 at 12:52