Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#14 CMakeFiles: cross-compilation & integration in CMake project

open
nobody
Compilation (4)
5
2012-05-16
2012-05-16
daminetreg
No

The provided scons buildfile doesn't easily allow a clean cross compilation for embedded development, indeed the Sconscruct community is still working on some system to perform like the autoreconf --host switch.

Another motivation is than most of the C++ projects which are going on takes CMake as a build system, it allows cross compilation in a really easy and supported manner thanks to ToolChain files. It is often also proposed along to other build system, that's why I think these files could cohabit with the existing scons scripts.

This is why patch provides CMake build for this great json library, it eases integration in CMake projects (i.e. a FindJsonCpp.cmake is provided to help check avaibility of the library before building) and allow cross compilation for any platform by just providing the right toolchain file or to compile it for any platform by executing cmake on the targeted platform.

Example of Toolchain file which can be used with cmake -DCMAKE_TOOLCHAIN_FILE:

ToolchainPPC.cmake ---
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_C_COMPILER /opt/sdks/eldk/usr/bin/ppc-linux-gcc)
SET(CMAKE_CXX_COMPILER /opt/sdks/eldk/usr/bin/ppc-linux-g++)
SET(CMAKE_FIND_ROOT_PATH /opt/sdks/eldk/ppc_6xx/)
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
SET(CMAKE_INSTALL_PREFIX /opt/sdks/eldk/ppc_6xx/usr/)

ToolchainARM.cmake ---
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_C_COMPILER /opt/sdks/OSELAS.Toolchain-1.99.3/arm-cortexa8-linux-gnueabi/gcc-4.3.2-glibc-2.8-binutils-2.18-kernel-2.6.27-sanitized/bin/arm-cortexa8-linux-gnueabi-gcc)
SET(CMAKE_CXX_COMPILER /opt/sdks/OSELAS.Toolchain-1.99.3/arm-cortexa8-linux-gnueabi/gcc-4.3.2-glibc-2.8-binutils-2.18-kernel-2.6.27-sanitized/bin/arm-cortexa8-linux-gnueabi-g++)
SET(CMAKE_FIND_ROOT_PATH /opt/sdks/OSELAS.Toolchain-1.99.3/arm-cortexa8-linux-gnueabi/gcc-4.3.2-glibc-2.8-binutils-2.18-kernel-2.6.27-sanitized/sysroot-arm-cortexa8-linux-gnueabi/)
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
SET(CMAKE_INSTALL_PREFIX /opt/sdks/OSELAS.Toolchain-1.99.3/arm-cortexa8-linux-gnueabi/gcc-4.3.2-glibc-2.8-binutils-2.18-kernel-2.6.27-sanitized/sysroot-arm-cortexa8-linux-gnueabi)

I had first modified the scons file to make cross compilation, but it isn't of any value because it's not standard, it's a little bit an hack (by overriding the different build variable and is not integrable in any cross platform build system like ptxdist, yocto...

I hope that the attached patch will please you and help you integrate this library with CMake, I'm also interested in helping more on it to have it becoming mainline. :)

Cheers,
--
daminetreg
alias Damien Buhl

Discussion

  • daminetreg
    daminetreg
    2012-05-18

    CMake support with a FindJonCpp.cmake rule to help library user to find json_cpp dependency.

     
    Attachments
  • daminetreg
    daminetreg
    2012-05-18

    Update : Just fixed a name hint in the FindJsonCpp for the shared library.