[Cmake] How to use more than one compiler and architecture in a project?

Ramon E. Creager rcreager at nrao.edu
Mon Feb 10 15:02:46 EST 2003


Hello,

I have a project that builds a distributed system, some components (.exe and
.dll) are Win32, and some components are for an embedded x86 system running
MS-DOS.  I am using the Borland Makefiles option with CMake on the command
line (no CMakeSetup).  For the Win32 components, I'm using the command line
tools that came with CBuilder5; for the DOS components, I'm forced to revert
to Borland C++ 5.2, which I think is the last version that supported DOS.
What I've done is in each source directory that produces a target, I've
created a subdirectory named Win32 if there is a Win32 target and one called
DOS if there is an MS-DOS target (some library directories have both).  In
each, I have a CMakeLists.txt file.  The Win32 ones are fairly
straightforward; I can go with the options CMake wants to use.  The DOS one
is another story altogether.  Here is what I've attempted:

SET(DOSPRG_SRC    ../main.cpp ../file1.cpp ../file2.cpp ../filen.cpp)
ADD_EXECUTABLE(ZY ${DOSPRG})
INCLUDE_DIRECTORIES(...) # my include directories
INCLUDE(${PROJECT_ROOT}/DOSCompilerFlags.txt)
LINK_DIRECTORIES(...} # my library directories
TARGET_LINK_LIBRARIES(DOSPRG mylib fp87 mathl cl)

Note the line "INCLUDE(${PROJECT_ROOT}/DOSCompilerFlags.txt)".  In the
project's root directory, I have a file DOSCompilerFlags.txt, and its
contents are:

SET(BC5_BIN E:/bin/Borland/BC5/bin)
SET(BC5_LIB E:\\bin\\Borland\\BC5\\lib) #for the linker
SET(CMAKE_CXX_COMPILER ${BC5_BIN}//bcc)
SET(CMAKE_C_COMPILER ${BC5_BIN}//bcc)
SET(CMAKE_CXX_FLAGS "-1 -AT -b -C -f87 -H- -ml -RT- -x- -xd- -w -Etasm32")
SET(CMAKE_CXX_FLAGS_DEBUG "-Od -N -k -v -DDEBUG")
SET(CMAKE_C_FLAGS "-1 -AT -b -C -f87 -H- -ml -RT- -x- -xd- -w -Etasm32")
SET(CMAKE_C_FLAGS_DEBUG "-Od -N -k -v -DDEBUG")
SET(CMAKE_LINKER_FLAGS
"-lc -L${LIBDISK}\\pctcpsdk\\netbcc3.0;${BC5_LIB} -ln -tDe")
SET(CMAKE_LINKER_FLAGS_DEBUG "-lm -ls -lv")

All my code compiles fine with the proper compiler and its flags, and I can
make DOS .libs, but executables will not link.  CMake insists on giving my
linker the -tWC flag (seems to be assuming I want a Win32 Console program),
and BCC balks at this.

I've got 2 questions:

  1)How can I make this work?
and
  2)Is anyone out there doing something similar (for example, we also have
projects that simultaneously build executables for Linux, Solaris and
VxWorks), and if so, how would they recommend using CMake with such a
project?

Incidentally, there was a recent request by Lars Prieske on how to make a
library with both .cpp and .asm files.  I've done this in my project, by
telling BCC what assembler to use on a .asm file (note the -Etasm32 in
CMAKE_CXX_FLAGS above), and then placed that file in the target's source
list along with all the .cpp files.  This works because the compiler can
compile to assembly, and thus must know what to do with a .asm file.
Perhaps CL has a similar option?


Ramon





More information about the CMake mailing list