License Delivery maintenance is expected to occur on Saturday, November 30, between 8 AM and 11 AM CET. This may cause a short 3-hours outage in which license-related tasks: license key upload, download, update, SSA validation, access to the license pool and Graphisoft ID authentication may not function properly. We apologize for any inconvenience.
Archicad C++ API
About Archicad add-on development using the C++ API.

CMAKE ADDON

poco2013
Mentor
I am trying to create some basic test addons using the cmake utility for a bare starting template:

Using the example "CMAKE Template for Archicad AddOns" as a basis:

The example compiles and works fine by itself but it contains only a rudimentary Dialog example. I would like to include the utility functions such as clickAnpoint, clickAnelem, etc. as contained in the APICommon.c & ,h files but when I include them in the source folder the solution will not compile. I assuming I must add a module or something to the CMAKE file but what? No example for doing this is given.

What do I need to add to "cmakelist.txt" to add and compile the common files as are used in all the examples?? The demo mentions that additional modules can be added at the end (i.e.: AddGSModule (AddOn GSUtils GSUtils) but does not describe what is needed for what.
The c files are included in all the other API examples and are mostly needed for any project to do anything. Would be nice if Graphisoft would revise its Demo to include them but, if not, i need some help to do it my self?
I am using the cmake template for archicad addons code example as listed in the Developer site Blog.

Thanks for any help!
Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27
5 REPLIES 5
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
Hi,

I'm happy to hear that you are using CMake!
It's good news for us because we are planning to give CMakeLists.txt file for each example Add-On in our DevKit.
The attached

contains the Browser_Control example Add-On with a CMakeLists.txt. You have to place the script from

to the Support/Tools folder to use CMake for building.
The attached CMakeLists.txt can be a universal CMake file for Add-Ons, just make sure you placed the surce files (.c, .cpp, .grc, .rc2 etc.) into the right folder structure and it should work.

The problem you faced is that the source files with .c extension are treated as pure C files by CMake, so it won't compile them as Cpp files. You have to tell CMake explicitly to compile them as Cpp:
file (GLOB AllCFiles
	${AddOnSourcesFolder}/*.c
)
set_source_files_properties(${AllCFiles} PROPERTIES LANGUAGE CXX)
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
I would like to ask your opinion on the following topic:
How about each Example in the API DevKit would contain one CMakeLists.txt file?
Do you agree that the Visual Studio (.vcxproj) and Xcode (.xcodeproj) IDE files are not necessary to be included anymore that way?

Note, the Visual Studio and Xcode project files can be generated by CMake. But the generated files are not portable (containing the absolute path and other local links), so we are not able to place them into the DevKit.
poco2013
Mentor
Based on running your solution above, which was successful -- Thank you: I would have to say Yes with some qualifications.

The new API package should not install the package in the programs folder anymore as default This would eliminate the necessity of running VS in admin mode. it would be of an advantage to also include a cmd exe file in each folder which would automatically execute the cmake without using the power shell manually -- at least, on windows. -- But not a serious problem

Also would like to see more blogs on how to alter cmakelist.txt to include other things from the examples. Cmake is very complicated and tries to be all things to all. One can easily get "lost" in the documentation. Color coding or commenting lines that can be changed and why, would be very helpful.
The DEVKIT examples are great but the C++ APi is very complicated and examples within the documentation are very sparse.I find myself often using cut and paste which mostly works but only mostly. Graphisoft should make that process easier keeping in mind the above problems. Perhaps just a section of some CPP utility files that could be included as above? But, on the whole, I think this will be very helpful to encourage more participation.

On another note, but related: I have some very serious concerns regarding the Python APi. I would be interested in your comments in the Beta?
Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
poco2013 wrote:
The new API package should not install the package in the programs folder anymore as default. This would eliminate the necessity of running VS in admin mode.
Thank you for your idea! What would be your preferred choice for default installation location?

poco2013 wrote:
It would be of an advantage to also include a cmd exe file in each folder which would automatically execute the cmake
This would work only if the DevKit would contain the cmake or the user installs manually the cmake and includes its location in the environment variable.

poco2013 wrote:
Also would like to see more blogs on how to alter cmakelist.txt to include other things from the examples. Cmake is very complicated and tries to be all things to all. One can easily get "lost" in the documentation. Color coding or commenting lines that can be changed and why, would be very helpful.
I agree, it's not so easy to write CMake configuration files. I hope we will have time to make a blog post to explain our CMakeLists.txt file line by line. However I think an average user won't look inside the CMakeLists.txt, he/she will just execute CMake, because our CMakeLists.txt will be universally usable for any Add-On projects.

poco2013 wrote:
On another note, but related: I have some very serious concerns regarding the Python APi. I would be interested in your comments in the Beta?
If you are an Archicad25 Beta user, then you can post bugs or your issues into our system. If you've already done that, then we will work on it soon. I'm sure I will bump into it if it's related to Python API
If you have general (not Beta version) related API issue, then feel free to post it at our API Support System.

@Tibor Lorantfy wrote:
How about each Example in the API DevKit would contain one CMakeLists.txt file?
Do you agree that the Visual Studio (.vcxproj) and Xcode (.xcodeproj) IDE files are not necessary to be included anymore that way?

I think that's a good idea, shipping CMakeLists.txt files with each Example. That should also make the dev kits for Windows & MacOS platforms a bit more alike, (and probably make it easier to set up source files for building the addon on one platform using the file-set for the other platform)

Another advantage: It would help in building the examples by using other IDEs (like vscode) instead of Visual Studio.