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

Alexander Neundorf a.neundorf-work at gmx.net
Wed Oct 1 18:43:02 EDT 2008


On Wednesday 17 September 2008, Simon Barner wrote:
> 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?

No (at least if I understand correctly).

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

I'm not too familiar with the differences of the makefile generators for 
Windows. Can you try if you also get slashes if you use the nmake makefile 
generator together with nmake ? 

> =============== Toolchain-C18.cmake ===============
> INCLUDE(CMakeForceCompiler)
>
> SET(CMAKE_SYSTEM_NAME Generic)
> CMAKE_FORCE_C_COMPILER(mcc18.exe MicrochipC18)

Why do you need the CMAKE_FORCE_C_COMPILER() ? 
It should only be necessary in very rare conditions.

Alex


More information about the CMake mailing list