Hello
When I use target_precompile_headers in my project the compilation of my mm-files fail with the following error:
error: Objective-C 1 was disabled in PCH file but is currently enabled.
However, when I generate an Xcode - project, compilation in Xcode works fine.
I saw that target_precompile_headers creates the parameter -include-pch in the call of the compiler on command line. Xcode does that not! When I call the compiler myself without that -include-pch parameter on the mm-file, like Xcode does, everything works fine.
When I use “add_compile_options(-Xclang -include -Xclang ${PROJECT_SOURCE_DIR}/stdafx.h)” instead of “target_precompile_headers”, it also works fine.
My CMakeLists.txt is this:
cmake_minimum_required(VERSION 3.10)
project(testlib)
add_executable(testlib lib.h lib.cpp lib.mm)
#Does not work
target_precompile_headers(testlib PRIVATE stdafx.h)
#Works for my, -Xclang depends on the compiler, Cmake is using
add_compile_options(-Xclang -include -Xclang ${PROJECT_SOURCE_DIR}/stdafx.h)
My stdafx.h file looks like that:
#pragma once
#include <iostream>
#ifdef __objc__
#import <Foundation/Foundation.h>
#endif
Is this a bug in CMake?
Best regards,
Micha