0

I have a Jamfile and one of the C++ sources MUST be compiled as Objective-C++ on darwin only. How I can make this example Jamfile compile file2 as Objective-C++ on darwin only? Please note that using a MM file extension is not a solution here.

import modules ;
import os ;

ECHO "OS =" [ os.name ] ;

SOURCES =
file1
file2 # How do I compile this file as objective-c++ on darwin only?
file3
;

local usage-requirements = 
<include>./include
;

project someproject ;

lib someproject

: # sources
src/$(SOURCES).cpp

: # requirements
<threading>multi
$(usage-requirements)

: # usage requirements
$(usage-requirements)
;
junglecat
  • 643
  • 1
  • 10
  • 19
  • I don't know Jam, but for GCC (or clang), you basically just need to add the flag `-x objective-c++` to the compiler command line. That should reduce your problem to figuring out how to add flags to the compiler command line on a per-platform basis in your Jam script. – pmdj Jun 12 '12 at 13:07

1 Answers1

1

I don't have a full answer, but the conventional way is to make a new rule to compile .cpp files to objective-c object files. You'll want to look at the Extender Manual part of the documentation to figure out how to do that, but it's not simple, especially since the method will depend on the toolkit.

The simpler hack is to just add the compilation flag when making the object file. (Untested code below...)

import modules ;
import os ;

ECHO "OS =" [ os.name ] ;

local usage-requirements = 
  <include>./include
  ;

# By putting the (usage) requirements in the project,
# they automatically apply to all targets
project someproject
  : <threading>multi
    $(usage-requirements)
  :
  : $(usage-requirements)
  ;

lib someproject
  : # sources
    src/file1.cpp
    src/file3.cpp
    file2.o
  ;

obj file2.o
  : src/file2.cpp
  : <toolset>gcc:<cxxflags>"-x objective-c++"
  ;

(Assuming pmjordan's suggested flags are correct.) Change the toolset and flags as appropriate (or add appropriate lines).

The hacky part is that the above jamfile will only work correctly with gcc. With other compilers, it will compile in cpp mode. If you remove the <toolset>gcc: part, using other compilers will fail, unless they also recognize the same flags as gcc.

Community
  • 1
  • 1
AFoglia
  • 7,968
  • 3
  • 35
  • 51