Skip to content

How to compile C and CPP files together?

Hello,I am a fresh man of Cmake,I want use Cmake instead of Makefile to compile a project which includes c and cpp files. The Makefile in the project as following:

...

App/Enclave_u.o: App/Enclave_u.c                        ###use `GCC Compiler` to compile C file and generate .o file
	@$(CC) $(App_C_Flags) -c $< -o $
	@echo "CC   <=  $<"

App/%.o: App/%.cpp                                      ###use `G++ Compiler` to compile CPP files and generate .o file
	@$(CXX) $(App_Cpp_Flags) -c $< -o $@
	@echo "CXX  <=  $<"

$(App_Name): App/Enclave_u.o $(App_Cpp_Objects)         ###link
	@$(CXX) $^ -o $@ $(App_Link_Flags)
	@echo "LINK =>  $
...

the code above first use GCC Compiler to compile C file and generate .o file,then it use G++ Compiler to compile CPP files,finally it links with .o files which generate above.

so How to use Cmake to achieve the above operations? thank you very much!

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information