Using CLion IDE and CMake to compile my project with c++ and a couple objective-c++ classes.
My problem arose because I need to include CoreFoundation in my project for my class in a .mm file to inherit from NSObject
After much digging, I think I found the modern CMake way of linking MacOS frameworks (CoreBluetooth, CoreFoundation, etc) with cmake.
Code below is the modern way of finding and linking MacOS frameworks in my Cmakelists.txt file:
target_link_libraries(project_name PUBLIC stdc++ "-framework CoreBluetooth"
"-framework Foundation"
"-framework CoreFoundation"
objc)
Loading cmake does not throw any errors, but when I try to import
the files (in either my .cpp or .mm files) the IDE is saying that it cannot find the CoreBluetooth and Foundation libraries.
Not sure if I am missing anything really obvious. Any help would be appreciated!
Okay after going on several wild goose hunts and layers and layers of digging, I finally found a solution. I printed out the location of CoreFoundation to make sure it was being found correctly and the directory is good:
find_library(FoundationLib CoreFoundation)
message("LIB: ${FoundationLib}")
-> /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Foundation.framework
Okay so I am almost certain is being loaded correctly. Now I dug deeper and broke my code and discovered that CLion accepts other extensions such as .h++ and .hm
.hm looks really similar to .h, and I know that the .m extension denotes an objective c file so that must mean I should probably use .hm to represent an objective-c header. So I renamed my header with the .hm extension and it works now. I think this is CLion specific and has not been documented anywhere.
recap: on CLion rename your objective c header from .h -> .hm
and if your header is an objective c++ header, change from .h -> .hmm
FINAL RECAP: I changed the header files back from .hm and .hmm -> .h, and they still work. So final answer for my issue is on CLion you have to set objective c++ headers to .hmm and .hm temporarily then you set them back to .h