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

Simon Barner barner at in.tum.de
Wed Sep 17 12:40:58 EDT 2008


Dear CMake users list,

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)
=================================================================

Please let me know, if you need further details.

Thanks,
 Simon

[1]
<http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en010014>

-- 
            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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 258 bytes
Desc: OpenPGP digital signature
URL: <http://www.cmake.org/pipermail/cmake/attachments/20080917/4d019d67/attachment.pgp>


More information about the CMake mailing list