Archicad C++ API
About Archicad add-on development using the C++ API.

Migration from API 25 to API 26. And CMake...

MudratDetector
Booster

WIN 10 | AC 26 | VS 2019

.

We are making the transition from ArchiCAD 25 to ArchiCAD 27, after skipping verison 26.  And I am just now dipping my toe in the waters of CMake.

 

- - I have installed CMake for Visual Studio 2019 from the VS Installer.

- - I have a successful build and execution for the "Hello CMake" starter project.
- - Not wanting to make the direct jump to 27, my dev path is 25 > 26 > 27.

- - Moving on to ArchiCAD Add-Ons, I downloaded the recommended CMakeLists.txt and CMakeCommon.cmake templates from our fair GS Community.

 

I am having trouble generating the build, in spite of settings I have made.  The error I receive while detecting the ArchiCAD version is:

MudratDetector_0-1696624580717.png


The function used, from CMakeCommon.cmake, is:

 

 

 

 

function (DetectACVersion devKitDir acVersion)

    set (ACAPIncFileLocation ${devKitDir}/Inc/ACAPinc.h)
    if (EXISTS ${ACAPIncFileLocation})
        file (READ ${ACAPIncFileLocation} ACAPIncContent)
        string (REGEX MATCHALL "#define[ \t]+ServerMainVers_([0-9][0-9])" VersionList ${ACAPIncContent})
        set (${acVersion} ${CMAKE_MATCH_1} PARENT_SCOPE)
    else ()
        message (FATAL_ERROR "Failed to detect Archicad version, please check the value of the AC_API_DEVKIT_DIR variable.")
    endif ()

endfunction ()

 

 

 

 


The function call, from CMakeLists.txt, is:

 

 

 

 

DetectACVersion (${AC_API_DEVKIT_DIR} ACVersion)

 

 

 

 


which seem to have an equal number of arguments, contrary to the error message.

So I backed up one step, and made sure I was getting a good value from AC_API_DEVKIT_DIR.  I am testing the value with a message before trying to use it.

 

 

 

 

message( STATUS "... AC_API_DEVKIT_DIR: $ENV{AC_API_DEVKIT_DIR}")
DetectACVersion (${AC_API_DEVKIT_DIR} ACVersion)
message (STATUS "Archicad Version: ${ACVersion}")

 

 

 

 

And, as the screenshot above shows, I have an empty string - no value.

I am attempting to set this value in CMakeSettings.json:

MudratDetector_1-1696625475153.png

and still get the error.

I have resorted to good ole fashioned DOS with:

MudratDetector_2-1696625600903.png

 and still get the error.

What am I missing?  Can someone point me in the right direction please?

 

Continued thanks,

Chris

Chris Gilmer
Intel i9-12950HX CPU @ 2.30GHz, 16 cores
NVIDIA GeForce RTX 3080
48.0 GB RAM
Windows 10 Pro 64-bit
1 ACCEPTED SOLUTION
6 REPLIES 6

Hi Chris,


TLDR: Please try your CMakeSettings.json approach again and use "Project -> Delete Cache and Regenerate".  If that's not helping, I'm trying to give some explanations below why I think certain steps didn't work and some suggestions.

 

Longer explanation

I think there are several different causes for the errors in the different steps you are trying. I'll try my best guesses from the descriptions you were giving.


First of all we have to differentiate the environment variable AC_API_DEVKIT_DIR and the CMake variable with the same name!

Presumably you have something like the following line in your main CMakeLists.txt file:

 

 

set (AC_API_DEVKIT_DIR $ENV{AC_API_DEVKIT_DIR} CACHE PATH "API DevKit directory.")

 

 

This is the line were the CMake variable is set to the same value as the environment variable.
Now when you don't do anything special and generate the CMake configuration from within Visual Studio, the environment variable will be empty and thus the CMake variable as well. This is my best guess to what happened and you've then discovered.

 

 


@MudratDetector wrote:

I am attempting to set this value in CMakeSettings.json:

MudratDetector_1-1696625475153.png

and still get the error.


Now your first try was to set it in CMakeSettings.json. This is actually a good way in my opinion.
There might be a few reasons why it still failed. I think most likely is, that the empty string value was still cached for the CMake variable AC_API_DEVKIT_DIR.

Be sure to use "Project -> Delete Cache and Regenerate". If that's not resolving the issue, i would recommend manually deleting the build folder and trying again.

 


@MudratDetector wrote:

I have resorted to good ole fashioned DOS with:

MudratDetector_2-1696625600903.png

 and still get the error.


Just setting the environment variable with the set command in the command prompt doesn't have any effect outside of that specific command prompt process.

So you would have to use setx(and probably run the command prompt as administrator) but I wouldn't recommend it since it's a bit of a hassle to always change it globally when you want to build against a different DEV_KIT version for a different Archicad version.

Instead I would recommend that you run the Developer Command Prompt for VS 2019 or Developer PowerShell for VS 2019, navigate to your project directory, set the environment variable there locally like you did and run a command like this:

 

cmake -B Build -G "Visual Studio 16 2019" -A x64 -T v142 .

 

 

Or don't set the environment variable at all and specify the devkit dir as a cmake option like so:

 

 

 

cmake -B Build -G "Visual Studio 16 2019" -A x64 -T v142 -DAC_API_DEVKIT_DIR=<DevKitSupportDir> .​

 


Hope that helps!
Bernd

Bernd Schwarzenbacher - Archicad Add-On Developer - Get Add-Ons & Archicad Tips on my Website: bschwb.com
MudratDetector
Booster

Bernd,

 

Thanks for the thorough and detailed explanation.  I will put these ideas to the test and [fingers crossed] report back with good news.  Your previous replies have always gotten me pointed in the right direction.

 

- Chris

 

EDIT:  The good news is I am successfully setting and reading the value of 

AC_API_DEVKIT_DIR

Thanks.

Chris Gilmer
Intel i9-12950HX CPU @ 2.30GHz, 16 cores
NVIDIA GeForce RTX 3080
48.0 GB RAM
Windows 10 Pro 64-bit
MudratDetector
Booster

After resolving a couple other issues, I am currently stuck at:

1> [CMake] -- >>> AC_API_DEVKIT_DIR: C:\Program Files\GRAPHISOFT\API Development Kit 26.3000\Support
1> [CMake] -- Archicad Version: 26
1> [CMake] -- Configuring done
1> [CMake] CMake Error: CMake can not determine linker language for target: JHP_Help
1> [CMake] -- Generating done
1> [CMake] CMake Generate step failed.  Build files cannot be regenerated correctly.

 

In the CMakeLists.txt file, I have tried using [without success] variations of the CMake commands:
set()
add-executable()
set_target_properties()

 

all of which seem to be the goto solution for this issue and are seen commented below.

Below is my CMakeLists.txt file:

cmake_minimum_required (VERSION 3.16)

include (Tools/CMakeCommon.cmake)

set (API_DEVKIT_DIR $ENV{AC_API_DEVKIT_DIR} CACHE PATH "API DevKit directory.")

if (GITHUB_BUILD)
    include(${CMAKE_BINARY_DIR}/conan_paths.cmake)
    set (API_DEVKIT_DIR ${CONAN_ARCHICAD-APIDEVKIT_ROOT}/bin)
endif ()

set_property (GLOBAL PROPERTY USE_FOLDERS ON)

set (CMAKE_CONFIGURATION_TYPES Debug;Release;RelWithDebInfo)
set (AC_API_DEVKIT_DIR ${API_DEVKIT_DIR} CACHE PATH "API DevKit directory.")
set (AC_ADDON_NAME "JHP_Help" CACHE STRING "AddOn Name")
set (AC_ADDON_LANGUAGE "INT" CACHE STRING "Add-On language code.")

project (${AC_ADDON_NAME} CXX)

# set(JHP_HelpCPP JHP_Help.cpp)
# add_executable(JHP_Help ${JHP_HelpCPP})
# set_target_properties(JHP_HelpCPP PROPERTIES LINKER_LANGUAGE CXX)

message( STATUS ">>> AC_API_DEVKIT_DIR: $ENV{AC_API_DEVKIT_DIR}")
DetectACVersion (${AC_API_DEVKIT_DIR} ACVersion)
message (STATUS "Archicad Version: ${ACVersion}")

set (AddOnFolder .)
SetGlobalCompilerDefinitions ()
GenerateAddOnProject (${ACVersion} ${AC_API_DEVKIT_DIR} ${AC_ADDON_NAME} ${AddOnFolder} ${AC_ADDON_LANGUAGE})

 

And, once again, I am not sure if this is a coding syntax issue, a Visual Studio configuration issue, or where best to look to solve.

 

Thanks, as always - chris

Chris Gilmer
Intel i9-12950HX CPU @ 2.30GHz, 16 cores
NVIDIA GeForce RTX 3080
48.0 GB RAM
Windows 10 Pro 64-bit
Solution

Hm... never encountered the linker language issue. I think one issue with your tries with set_target_properties is, that you redefine the target! Hidden in the function GenerateAddOnProject, there's already a target with your add-ons name (JHP_Help) created. So instead I would try the following line AFTER GenerateAddOnProject (so basically at the end of the file):

 

set_target_properties(${AC_ADDON_NAME} PROPERTIES LINKER_LANGUAGE CXX)

 

Bernd Schwarzenbacher - Archicad Add-On Developer - Get Add-Ons & Archicad Tips on my Website: bschwb.com
MudratDetector
Booster

 

 

 

 

GenerateAddOnProject (${ACVersion} ${AC_API_DEVKIT_DIR} ${AC_ADDON_NAME} ${AddOnFolder} ${AC_ADDON_LANGUAGE})
set_target_properties(${AC_ADDON_NAME} PROPERTIES LINKER_LANGUAGE CXX)

 

 

 

 

was the trick to getting over that hurdle.  After a few other edits, I now have an error free build.

 

But I am not getting an .apx file.  I suspect I need to rearrange my file/folder structure, most notably putting the .cpp file in the .\Src folder.

MudratDetector_0-1697039515955.png

 

I'm still digging around with this.  Thanks for sharing the knowledge so far...

- chris

 

EDIT:  Hurray!

MudratDetector_0-1697046747927.png

 

But firing up AC26 gets me this:

MudratDetector_1-1697046900533.png

And selecting the .apx file to manually add it gets me this:

MudratDetector_2-1697047156804.png

So close.

Will it ever end... !!!

Chris Gilmer
Intel i9-12950HX CPU @ 2.30GHz, 16 cores
NVIDIA GeForce RTX 3080
48.0 GB RAM
Windows 10 Pro 64-bit
MudratDetector
Booster

That did not take too long.

MudratDetector_0-1697056185739.png

And, it even works!

MudratDetector_1-1697056262121.png

Turns out the catch was an ERROR in defining CMAKE_CONFIGURATION_TYPES twice.  Not exactly which one of these fixed it but:

# set (CMAKE_CONFIGURATION_TYPES Debug;Release;RelWithDebInfo)
set (CMAKE_CONFIGURATION_TYPES Debug)

looks like once and not three times.

 

And manually removing:

{
   "name": "CMAKE_CONFIGURATION_TYPES",
   "value": "x64-Debug",
   "type": "STRING"
}

from the .json file and leaving

set (CMAKE_CONFIGURATION_TYPES Debug)

in the CMakeLists.txt file did the trick.

Although I suspect this 'set' writes to the .json file...

 

Thanks again for the guidance!
And I hope this play-by-play helps someone else who has yet to transition out of API 25.

 

- chris

Chris Gilmer
Intel i9-12950HX CPU @ 2.30GHz, 16 cores
NVIDIA GeForce RTX 3080
48.0 GB RAM
Windows 10 Pro 64-bit

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!