[CMake] Crosscompilation woes

portolan michele.portolan at imag.fr
Mon Oct 10 07:13:34 EDT 2016


It is pretty much standard. I wrote the toolchain file adapting 
different examples.

the Cmakelist is for the subdirectory of my parser (called SIT_parser). 
The trick si that I use a custom command for Lex/Yacc, so even when 
cross-compiling it is still correctly called.


Michele



Le 10/10/2016 à 12:48, Robert Bielik a écrit :
>
> Ok, I cannot get this to work. The source files to be generated with 
> add_custom_command have property GENERATED set to ON, but cmake does 
> not adhere, and tries to use the tool binaries of the target system.
>
> Michele, would you be ok with sharing your cmake code for this 
> particular bit ?
>
> Regards
>
> /R
>
> *From:*portolan [mailto:michele.portolan at imag.fr]
> *Sent:* den 10 oktober 2016 11:33
> *To:* Robert Bielik <Robert.Bielik at dirac.com>; Craig Scott 
> <craig.scott at crascit.com>
> *Cc:* Cmake at cmake.org
> *Subject:* Re: [CMake] Crosscompilation woes
>
> I cannot answer your question: I am a newcomer to Cmake (I have been 
> using it for less than 6 months) and on my build system I have 3.6, so 
> I never really looked at the previous versions.
>
> Sorry,
>
> Michele
>
> Le 10/10/2016 à 11:30, Robert Bielik a écrit :
>
>     Thank you Michele,
>
>     This is exactly what I’m after. You specify cmake v3.6 docs ? Is
>     it only working from 3.6.x ? I have 3.5.2 on my build system.
>
>     Regards
>
>     /Robert
>
>     *From:*portolan [mailto:michele.portolan at imag.fr]
>     *Sent:* den 10 oktober 2016 11:27
>     *To:* Robert Bielik <Robert.Bielik at dirac.com>
>     <mailto:Robert.Bielik at dirac.com>; Craig Scott
>     <craig.scott at crascit.com> <mailto:craig.scott at crascit.com>
>     *Cc:* Cmake at cmake.org <mailto:Cmake at cmake.org>
>     *Subject:* Re: [CMake] Crosscompilation woes
>
>     In my project I build on Linux i686 and I use a Toolchain file to
>     specify the ARM cross-compiler
>
>     https://cmake.org/cmake/help/v3.6/manual/cmake-toolchains.7.html
>
>     The nice thing is that if you mark some files as "generated" CMAKE
>     will automatically use the build rather than the target
>     toolchains. For instance, I have a Flex/Byson compiler that is
>     generated locally on i686 , but then compiled for ARM.
>
>     Regards,
>
>     Michele
>
>     Le 10/10/2016 à 11:10, Robert Bielik a écrit :
>
>         Thanks Craig,
>
>         Your solution will work for me I think.
>
>         Regards
>
>         /R
>
>         *From:*Craig Scott [mailto:craig.scott at crascit.com]
>         *Sent:* den 10 oktober 2016 10:47
>         *To:* Robert Bielik <Robert.Bielik at dirac.com>
>         <mailto:Robert.Bielik at dirac.com>
>         *Cc:* Cmake at cmake.org <mailto:Cmake at cmake.org>
>         *Subject:* Re: [CMake] Crosscompilation woes
>
>         Here's one possible solution (not perfect, but has been
>         working in production for us for a while now for a similar
>         scenario to what you describe):
>
>         http://stackoverflow.com/q/36084785/1938798
>
>         An alternative is a superbuild arrangement which would require
>         a top level project to drive two sub-builds brought in via
>         ExternalProject
>         <https://cmake.org/cmake/help/latest/module/ExternalProject.html>,
>         one for the host and the other for arm. This is both better
>         and worse, depending on your point of view, so you may need to
>         do some research/experimenting to see which is a better fit
>         for your situation.
>
>         On Mon, Oct 10, 2016 at 7:29 PM, Robert Bielik
>         <Robert.Bielik at dirac.com <mailto:Robert.Bielik at dirac.com>> wrote:
>
>             Hi all,
>
>             I am crosscompiling a project for arm (on linux i686), and
>             use codegeneration tools within the project (together with
>             add_custom_command). Of course, this will fail, since the
>             tools are compiled for arm also and thus won't execute on
>             my host system. So the tools need to be compiled for i686
>             whilst the rest for arm. I'm sure this can be handled by
>             CMake although haven't done it before so would appreciate
>             pointers :)
>
>             Regards
>             /Robert
>
>             --
>
>             Powered by www.kitware.com <http://www.kitware.com>
>
>             Please keep messages on-topic and check the CMake FAQ at:
>             http://www.cmake.org/Wiki/CMake_FAQ
>             <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
>             <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://public.kitware.com/mailman/listinfo/cmake
>
>
>
>         -- 
>
>         Craig Scott
>
>         Melbourne, Australia
>
>         https://crascit.com
>
>
>
>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20161010/f5ef7a62/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Toolchain-arm.cmake
Type: text/x-cmake
Size: 1022 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake/attachments/20161010/f5ef7a62/attachment-0001.bin>
-------------- next part --------------
cmake_minimum_required(VERSION 3.5)
project(SIT_parser)

find_package(FLEX)
find_package(BISON)
if ( NOT FLEX_FOUND)
 message( FATAL_ERROR "Flex not found")
endif()

if (NOT BISON_FOUND)
 message( FATAL_ERROR "Bison not found")
endif()

add_definitions(${P_WARNINGS})
set (P_WARNINGS "-Wall -Wno-sign-compare -Wnon-virtual-dtor -Wredundant-decls -Wundef -Wmissing-declarations -Wmissing-include-dirs")
add_definitions(${P_CFLAGS})
set (P_CFLAGS "${P_WARNINGS} -std=c++14")

add_definitions(${Flex_Switches})
if (WIN32)
#+  set (P_CFLAGS ${P_CFLAGS} -DBUILD_DLL)
  set (P_CFLAGS ${P_CFLAGS})
	set (Flex_Switches -v -L)
else()
  set (P_CFLAGS "${P_CFLAGS} -fPIC")
	set (Flex_Switches -v -L)
endif()


set (LEX_YACC_SRC_DIR  "${CMAKE_CURRENT_SOURCE_DIR}/")

# Create custom command for flex/lex (note the outputs)
ADD_CUSTOM_TARGET(SIT_Lexer_class echo "Creating SIT_lexer")
add_custom_command(
  OUTPUT ${LEX_YACC_SRC_DIR}SIT_lexer.yy.cc
  COMMAND flex ${Flex_Switches}  -o${LEX_YACC_SRC_DIR}SIT_lexer.yy.cc ${LEX_YACC_SRC_DIR}SIT_lexer.l
  DEPENDS SIT_lexer.l
)

# Create target for the parser
ADD_CUSTOM_TARGET(SIT_Parser_class echo "Creating SIT_parser")
add_custom_command(
  OUTPUT ${LEX_YACC_SRC_DIR}SIT_parser.tab.cc ${LEX_YACC_SRC_DIR}SIT_parser.tab.hh
  COMMAND bison -d -v -l ${LEX_YACC_SRC_DIR}SIT_parser.yy -o ${LEX_YACC_SRC_DIR}SIT_parser.tab.cc
  DEPENDS SIT_parser.yy
)

# Add parser.c to the list of sources
#+SET(SIT_parser_SRCS ${SIT_parser_SRC} ${LEX_YACC_SRC_DIR}SIT_parser.tab.cc ${LEX_YACC_SRC_DIR}SIT_lexer.yy.cc)

# Since parser.c does not exists yet when cmake is run, mark it as generated
SET_SOURCE_FILES_PROPERTIES(${LEX_YACC_SRC_DIR}SIT_parser.tab.cc GENERATED)
SET_SOURCE_FILES_PROPERTIES(${LEX_YACC_SRC_DIR}SIT_lexer.yy.cc 	 GENERATED)

# Include binary directory to include lexer.c in parser.c
#+include_directories(${CMAKE_BINARY_DIR}/SIT_parser/)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/)

add_executable 	(SIT_reader_demo 	${LEX_YACC_SRC_DIR}main.cpp)

set_target_properties(SIT_reader_demo PROPERTIES COMPILE_FLAGS "${P_CFLAGS}" )


More information about the CMake mailing list