[CMake] Cross compiling toolchain: Substitution in <OBJECTS> variable

Simon Barner barner at in.tum.de
Tue Sep 23 02:59:14 EDT 2008


Hi,

does anybody have a clue on this? Or should I re-state
my question?

Thanks,
  Simon

> I am currently development a CMake cross build platform
> definition to support Microchips C18 C compiler[1].
> 
> I encountered the problem that C18's linker does not like '/' as
> path delimiter which is why I need some substitution for the
> filenames contained in the "magic" <OBJECTS> variable (to '\').
> 
> The only solution I found is to create a temporary batch file and
> to use cmd's text replacement facilities.
> 
> Here is the platform file in question:
> CMake version: 2.6.1
> CMake generator: Unix Makefiles
> Build platform:  win32 (Vista)
> 
> ============================
> # Suffixes of static libraries and object files created by us
> SET(CMAKE_STATIC_LIBRARY_SUFFIX ".lib")
> SET(CMAKE_C_OUTPUT_EXTENSION ".o")
> 
> SET(CMAKE_C_LINK_EXECUTABLE mplink.exe)
> SET(CMAKE_AR mplib.exe)
> 
> # Linking against static variables: /l path/to/lib libTheLibrary.lib
> SET(CMAKE_LIBRARY_PATH_FLAG "/l")
> SET(CMAKE_LINK_LIBRARY_FLAG "lib")
> SET(CMAKE_LINK_LIBRARY_SUFFIX ".lib")
> 
> # Compile a C file into an object file
> SET(CMAKE_C_COMPILE_OBJECT  "<CMAKE_C_COMPILER> <FLAGS> -O
> -fo=\\\"<OBJECT>\\\" <SOURCE>")
> 
> # Link object files to an executable
> SET(CMAKE_C_LINK_EXECUTABLE "<CMAKE_LINKER> <OBJECTS> <CMAKE_C_LINK_FLAGS>
> <LINK_FLAGS> <LINK_LIBRARIES> /o <TARGET> /w")
> 
> # Create static library
> # Problem 1: APPEND does not work (not invoked?)
> # --> do all work in CREATE
> # Problem 2: Need to use \ as path delimiter in <OBJECTS>.
> # Is text replacement possible?
> #SET (CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> /c <TARGET>; <CMAKE_AR> /r <TARGET>
> <OBJECTS>")
> #SET (CMAKE_C_ARCHIVE_APPEND "echo append")
> 
> # Create static library
> #
> # Caution: Object paths to be passed to mplib must use
> #         '\' as path delimiter!
> # TODO: Using temporary batch file to perform text replacement / --> \
> SET(CMAKE_C_CREATE_STATIC_LIBRARY
> 	"\"${CMAKE_COMMAND}\" -E remove <TARGET>"
> 	"\"${CMAKE_COMMAND}\" -E remove c18_build_archive.bat"
> 	"<CMAKE_AR> /c <TARGET>"
> 	"echo set objs=<OBJECTS> > c18_build_archive.bat"
> 	"echo <CMAKE_AR> /r <TARGET> %%objs:/=\\%% >> c18_build_archive.bat"
> 	"c18_build_archive.bat"
> 	"\"${CMAKE_COMMAND}\" -E remove c18_build_archive.bat"
> )
> ===============
> 
> As you can see, there is also a minor problem with
> CMAKE_C_ARCHIVE_APPEND not being invoked. I tried to work around the
> latter issue by using cmd's ; operator in CMAKE_C_ARCHIVE_CREATE.
> 
> Could you please give my some piece of advice, especially for the text
> substitution problem? As soon as I have a clean solution, I would
> certainly like to submit the platform definition file to the CMake
> distribution.
> 
> Here is how I invoke CMake:
> 
> cmake -G "Unix Makefiles"
>    -D "CMAKE_TOOLCHAIN_FILE:FILEPATH=Toolchain-C18.cmake" <src dir>
> 
> =============== Toolchain-C18.cmake ===============
> INCLUDE(CMakeForceCompiler)
> 
> SET(CMAKE_SYSTEM_NAME Generic)
> CMAKE_FORCE_C_COMPILER(mcc18.exe MicrochipC18)
> =================================================================
>

-- 
             Lehrstuhl für                         Dipl.-Inf. Simon Barner
     Robotik und eingebettete Systeme     Technische Universitaet Muenchen
                                                 Fakultaet fuer Informatik
Lehrstuhl I/6  Boltzmannstrasse 3  85748 Garching   http://www6.in.tum.de
Tel.: ++49 (0)89 289-18111   Fax: -18107          Email: barner at in.tum.de


More information about the CMake mailing list