chalet icon indicating copy to clipboard operation
chalet copied to clipboard

Using different compilers to an entire build

Open dimitre opened this issue 3 years ago • 3 comments

Finally with your help I've completed compiling openFrameworks on macOs! But I still have to comment out objective-c, compile everything using LLVM then uncomment objective c and compile the rest using apple-llvm

if I use llvm for all I get this error

ERROR: chalet.json: Objective-C / Objective-C++ is currently only supported on MacOS using Apple clang.

and if I use apple-llvm I got errors in files that mixes cpp with obj-c

with the settings (-x objective-c++) I used to build correctly on llvm :

			"compileOptions": [
				"-fpascal-strings",
				"-x objective-c++",
				"-fobjc-arc"
			],

I get

clang: error: language not recognized: ' objective-c++'

and without it I get errors like this:

In file included from libs/openFrameworks/app/ofAppGLFWWindow.cpp:25:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/System/Library/Frameworks/Cocoa.framework/Headers/Cocoa.h:12:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:8:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:523:1: error: expected unqualified-id
@class NSString, Protocol;

in this file for example: https://github.com/openframeworks/openFrameworks/blob/master/libs/openFrameworks/app/ofAppGLFWWindow.cpp

dimitre avatar Oct 11 '22 12:10 dimitre

Could you share the whole chalet.json? And what platform are you building it with LLVM? You should only need apple-llvm to build it on mac.

rewrking avatar Oct 11 '22 12:10 rewrking

sure! I'm using this two configurations to be able to build everything: chalet configure -t apple-llvm -a auto chalet configure -t llvm -a auto

here the chalet.json

{
	"name": "OF",
	"version": "0.11.3",
	// "externalDependencies": {
	// 	"glfw": {
	// 	   "repository": "https://github.com/glfw/glfw"
	// 	},
	// 	"assimp": {
	// 		"repository": "https://github.com/assimp/assimp",
	// 		"tag" : "v5.2.5"
	// 	 }
	//  },	

	"abstracts:*": {
		"language": "C++",
		"settings:Cxx": {
			"cppStandard": "c++17",
			"runtimeTypeInformation": true,
			"compileOptions": [
				"-fpascal-strings",
				"-x objective-c++",
				"-fobjc-arc"
			],
			"includeDirs": [
				"libs/glew/include",
				"libs/tess2/include",
				"libs/glm/include",
				"libs/utf8/include",
				"libs/glfw/include",
				"libs/pugixml/include",
				"libs/uriparser/include",
				"libs/fmod/include",
				"libs/cairo/include/cairo",
				"libs/Freeimage/include",
				"libs/curl/include",
				"libs/freetype/include/freetype2",
				"libs/json/include",
				"libs/rtAudio/include",

				"libs/openFrameworks",
				"libs/openFrameworks/3d",
				"libs/openFrameworks/app",
				"libs/openFrameworks/communication",
				"libs/openFrameworks/events",
				"libs/openFrameworks/gl",
				"libs/openFrameworks/graphics",
				"libs/openFrameworks/math",
				"libs/openFrameworks/sound",
				"libs/openFrameworks/types",
				"libs/openFrameworks/utils",
				"libs/openFrameworks/video"
			],

			"macosFrameworks": [
				"Accelerate",
				"AGL",
				"ApplicationServices",
				"AVFoundation",
				"Cocoa",
				"CoreAudio",
				"CoreFoundation",
				"CoreMedia",
				"CoreServices",
				"CoreVideo",
				"IOKit",
				"OpenGL",
				"QuartzCore",
				"Security"
			]
		}
		// ,
		// "files": "libs/openFrameworks/**.{cpp,mm}"


	},

	"targets": {
		"objcOF": {
			"language": "Objective-C++",
			"kind": "staticLibrary",
			"files": "libs/openFrameworks/**.mm",
			"condition": "[:macos]"
		},

		"coreOF": {
			"kind": "staticLibrary",
			"language": "C++",
			"condition": "[:macos]",

			"settings:Cxx": {
				"cppStandard": "c++17",
				"runtimeTypeInformation": true,
				"warningsPreset": "minimal",
				"compileOptions[:macos]": [
					"-mmacos-version-min=10.15",
					"-fpascal-strings",
					"-x objective-c++",
					// "-lobjc"
					// "-lc++"
					"-fobjc-arc"
				],

				"threads": true,
				"exceptions": true,

				"libDirs": [
					"libs/glm/include",
					"libs/glfw/include",
					"libs/glew/include",
					// "libs/glew/include/GL",
					"libs/tess2/include",
					"libs/utf8/include",
					"libs/Freeimage/include",
					"libs/cairo/include/cairo",
					"libs/curl/include",
					"libs/fmod/include",
					"libs/freetype/include/freetype2",
					"libs/json/include",
					"libs/pugixml/include",
					"libs/rtAudio/include",
					"libs/uriparser/include"
				],

				"macosFrameworks": [
					"Accelerate",
					"AGL",
					"ApplicationServices",
					"AVFoundation",
					"Cocoa",
					"CoreAudio",
					"CoreFoundation",
					"CoreMedia",
					"CoreServices",
					"CoreVideo",
					"IOKit",
					"OpenGL",
					"QuartzCore",
					"Security"
				]
			},

			"files": {
				"include": [ 
					"libs/openFrameworks/**.{cpp}" 
				],
				"exclude": [
					"libs/openFrameworks/video/{ofGstVideoPlayer,ofGstVideoGrabber,ofGstUtils,ofDirectShowGrabber,ofDirectShowPlayer}.*",
					"libs/openFrameworks/*/{ofAppEGLWindow,ofAppGlutWindow}.*"
				]
			}
		},

		"appOF" : {
			"kind": "executable",
			"language": "C++",
			"settings:Cxx": {
				"cppStandard": "c++17",
				"runtimeTypeInformation": true,
				"staticLinks": [
					"objcOF",
					"coreOF"
				],
								// ,
				// "links[:macos]": "my-static-lib"


				"linkerOptions" : [
					// "libs/**/*.{a,dylib}",
					"libs/FreeImage/lib/osx/freeimage.a",
					"libs/boost/lib/osx/boost_system.a",
					"libs/boost/lib/osx/boost_filesystem.a",
					"libs/cairo/lib/osx/cairo-script-interpreter.a",
					"libs/cairo/lib/osx/cairo.a",
					"libs/cairo/lib/osx/png.a",
					"libs/cairo/lib/osx/pixman-1.a",
					"libs/curl/lib/osx/curl.a",
					"libs/freetype/lib/osx/freetype.a",
					"libs/glew/lib/osx/glew.a",
					"libs/glfw/lib/osx/glfw3.a",
					"libs/pugixml/lib/osx/pugixml.a",
					"libs/rtAudio/lib/osx/rtaudio.a",
					"libs/tess2/lib/osx/tess2.a",
					"libs/uriparser/lib/osx/uriparser.a",
					"libs/fmod/lib/osx/libfmod.dylib"

					// "libs/FreeImage/lib/osx/freeimage.a libs/boost/lib/osx/boost_system.a libs/boost/lib/osx/boost_filesystem.a libs/cairo/lib/osx/cairo-script-interpreter.a libs/cairo/lib/osx/cairo.a libs/cairo/lib/osx/png.a libs/cairo/lib/osx/pixman-1.a libs/curl/lib/osx/curl.a libs/freetype/lib/osx/freetype.a libs/glew/lib/osx/glew.a libs/glfw/lib/osx/glfw3.a libs/pugixml/lib/osx/pugixml.a libs/rtAudio/lib/osx/rtaudio.a libs/tess2/lib/osx/tess2.a libs/uriparser/lib/osx/uriparser.a libs/fmod/lib/osx/libfmod.dylib -lobjc -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/14.0.0/lib/darwin/libclang_rt.osx.a"
				],
				

				"libDirs": [
					// "libs/glm/lib",
					"libs/glfw/lib",
					"libs/glew/lib",
					"libs/tess2/lib",
					// "libs/utf8/lib",
					"libs/Freeimage/lib",
					"libs/cairo/lib",
					"libs/curl/lib",
					"libs/fmod/lib",
					"libs/freetype/lib",
					// "libs/json/lib",
					"libs/pugixml/lib",
					"libs/rtAudio/lib",
					"libs/uriparser/lib"
				],
				"warningsPreset": "minimal"
			},

			"files": "examples/3d/3DPrimitivesExample/src/**.cpp"
		}
	},

	"distribution": {
		"all": {
			"kind": "bundle",
			"buildTargets": "appOF",
			"macosBundle": {
				"type": "app",
				"infoPropertyList": "examples/3d/3DPrimitivesExample/openFrameworks-Info.plist",
				"icon": "/Users/z/Desktop/DESK2/of/_icon/of_ow2.png.icns"
			}
		}
	}
}

dimitre avatar Oct 11 '22 12:10 dimitre

I'll get back to you on this over the weekend btw. I'll need to build open frameworks myself and figure out if chalet is missing anything it should be doing for Objective-C++.

rewrking avatar Oct 12 '22 13:10 rewrking

Update: I got open frameworks and one of the examples to build (it's 1 staticLibrary and 1 executable target).

I'll get the new chalet version it requires out by tomorrow -- looking into #203 as well. The main change is that if the target is Objective-C/C++, non-mm/m files will be compiled with -x objective-c++ (or -x objective-c). ~~The only restriction right now is that you can't use a precompiled header in that target if you mix - setting a pch will simply not add the -x flags to the cpp files. If I can figure out how to get it to work correctly with it, I will do that instead, but for now this is fine because open frameworks doesn't use a pch.~~ Edit: fixed - mixing works w/ pch now too

Another thing I added was exact paths to libraries in links and staticLinks since OF uses links w/o thelib prefix for some reason. This way you don't have to pass them into linkerOptions.

Also made a couple bugfixes in the macos bundler. They would have come up if you had a distribution target that included multiple executable targets.

I'll share the chalet.json file along with some other notes when the new version is out. Bottom line is, you do not need 2 compilers. Just Apple Clang :)

rewrking avatar Oct 23 '22 02:10 rewrking

Here's the release: v0.5.7

Here's the chalet.json I came up with to both build the framework as a static library, and compile the box example. I also added a distribution example to create an app bundle and dmg.

Open Frameworks example chalet.json
{
"name": "open-frameworks",
"version": "1.0.0",
"abstracts:*": {
  "language": "C++",
  "language[toolchain:apple-llvm]": "Objective-C++",
  "settings:Cxx": {
    "cppStandard": "c++17",
    "warningsPreset": "minimal",
    "runtimeTypeInformation": true,
    "threads": true,
    "exceptions": true,
    "defines[:debug]": [
      "DEBUG"
    ],
    "compileOptions[toolchain:apple-llvm]": [
      "-fpascal-strings",
      "-fobjc-arc"
    ],
    "includeDirs": [
      "libs/openFrameworks/*",
      "libs/openFrameworks"
    ],
    "includeDirs[:macos]": [
      "libs/glew/include",
      "libs/tess2/include",
      "libs/glm/include",
      "libs/utf8/include",
      "libs/glfw/include",
      "libs/pugixml/include",
      "libs/uriparser/include",
      "libs/fmod/include",
      "libs/cairo/include/cairo",
      "libs/FreeImage/include",
      "libs/curl/include",
      "libs/freetype/include/freetype2",
      "libs/json/include",
      "libs/rtAudio/include"
    ],
    "libDirs[:macos]": "libs/fmod/lib/osx",
    "links[:macos]": "fmod",
    "staticLinks[:macos]": [
      "libs/boost/lib/osx/boost_system.a",
      "libs/boost/lib/osx/boost_filesystem.a",
      "libs/cairo/lib/osx/png.a",
      "libs/cairo/lib/osx/pixman-1.a",
      "libs/cairo/lib/osx/cairo.a",
      "libs/cairo/lib/osx/cairo-script-interpreter.a",
      "libs/curl/lib/osx/curl.a",
      "libs/FreeImage/lib/osx/freeimage.a",
      "libs/freetype/lib/osx/freetype.a",
      "libs/glew/lib/osx/glew.a",
      "libs/glfw/lib/osx/glfw3.a",
      "libs/pugixml/lib/osx/pugixml.a",
      "libs/rtAudio/lib/osx/rtaudio.a",
      "libs/tess2/lib/osx/tess2.a",
      "libs/uriparser/lib/osx/uriparser.a"
    ],
    "macosFrameworks": [
      "Accelerate",
      "AGL",
      "ApplicationServices",
      "AVFoundation",
      "Cocoa",
      "CoreAudio",
      "CoreFoundation",
      "CoreMedia",
      "CoreServices",
      "CoreVideo",
      "IOKit",
      "OpenGL",
      "QuartzCore",
      "Security"
    ]
  }
},
"targets": {
  "open-frameworks": {
    "kind": "staticLibrary",
    "files": {
      "include": [
        "libs/openFrameworks/{3d,communication,events,gl,graphics,math,sound,types,utils,video}/*.cpp",
        "libs/openFrameworks/app/ofBaseApp.cpp",
        "libs/openFrameworks/app/ofMainLoop.cpp",
        "libs/openFrameworks/app/ofAppRunner.cpp",
        "libs/openFrameworks/app/ofAppGLFWWindow.cpp"
      ],
      "include[toolchain:apple-llvm]": "libs/openFrameworks/**.{mm,m}",
      "exclude[:macos]": [
        "libs/openFrameworks/video/ofDirectShowPlayer.cpp",
        "libs/openFrameworks/video/ofGstVideoGrabber.cpp",
        "libs/openFrameworks/video/ofGstVideoPlayer.cpp",
        "libs/openFrameworks/video/ofGstUtils.cpp"
      ]
    }
  },
  "ofBoxExample": {
    "kind": "executable",
    "settings:Cxx": {
      "includeDirs": "examples/3d/ofBoxExample/src",
      "staticLinks": "open-frameworks"
    },
    "files": "examples/3d/ofBoxExample/src/*.cpp",
    "copyFilesOnRun[:macos]": "examples/3d/ofBoxExample/bin/data"
  },
  "download-libs": {
    "kind": "script",
    "condition": "[:runTarget]",
    "file[:macos]": "scripts/osx/download_libs.sh"
  }
},
"distribution": {
  "ofBoxExample": {
    "kind": "bundle",
    "buildTargets": "*",
    "exclude": [
      "data/.gitkeep"
    ],
    "macosBundle": {
      "type": "app",
      "icon": "libs/openFrameworksCompiled/project/osx/of.icns",
      "infoPropertyList": {
        "CFBundleDevelopmentRegion": "en-US",
        "CFBundleDisplayName": "${name}",
        "CFBundleExecutable": "${mainExecutable}",
        "CFBundleIconFile": "${icon}",
        "CFBundleIdentifier": "com.developer.application",
        "CFBundleInfoDictionaryVersion": "6.0",
        "CFBundleName": "${bundleName}",
        "CFBundlePackageType": "APPL",
        "CFBundleShortVersionString": "1.0.0",
        "CFBundleVersion": "1.0.0",
        "CFBundleSignature": "????",
        "LSMinimumSystemVersion": "10.8",
        "NSHighResolutionCapable": true
      }
    }
  },
  "ofBoxExample.dmg": {
    "kind": "macosDiskImage",
    "pathbarVisible": false,
    "textSize": 12,
    "iconSize": 80,
    "size": {
      "width": 512,
      "height": 342
    },
    "positions": {
      "ofBoxExample": {
        "x": 120,
        "y": 188
      },
      "Applications": {
        "x": 392,
        "y": 188
      }
    }
  }
}
}

rewrking avatar Oct 23 '22 22:10 rewrking

Crazy fast. it is GREAT @rewrking Thank you! I'm really surprised you could figure out lots of details from building OF in a few days, ACE totally building package here. chalet buildrun doesn't complete with this alert

ERROR: chalet.json: Run target of 'app' is either: not a valid project name, or is excluded based on a property condition.

dimitre avatar Oct 24 '22 01:10 dimitre

is app the old project name? It just means "app" is expected because it's set under options.runTarget in .chaletrc.

You could either call chalet buildrun (new project name) to explicitly set the new run target or chalet unset options.runTarget && chalet buildrun to infer the new one

rewrking avatar Oct 24 '22 02:10 rewrking