Skip to main content
Inspiring
May 12, 2023
Answered

How to build an Illustrator C++-Plugin with CMake?

  • May 12, 2023
  • 1 reply
  • 4554 views

Hi
I'm currently developing a plugin for Illustrator. Because our ecosystem demands it (and for portability reasons) I have to do this on CMake.
I was successful to build a plugin for Mac with CMake, but now I'm struggeling with Windows.
For using an easy plugin, I took the MenuPlay-example from the samples delivered together with the SDK and build it in Visual Studio -> This Plugin was detected by the Illustrator
I then tried to port it to CMake. The build was successful, but Illustrator does not detect the plugin. What am I missing?
This is the CMake-Script:

 

cmake_minimum_required(VERSION 3.14)

project(MenuPlay)

add_compile_definitions(WIN_ENV=1)

set(CMAKE_AUTOMOC ON)

add_library(${PROJECT_NAME})
add_library(${PROJECT_NAME}::${PROJECT_NAME}  ALIAS ${PROJECT_NAME})

set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".aip")

target_sources(${PROJECT_NAME} PRIVATE
	"Source/MenuPlayID.h"
	"Source/MenuPlayPlugin.h"	
        "Source/MenuPlayPlugin.cpp"
        "Source/MenuPlaySuites.h"
        "Source/MenuPlaySuites.cpp"
	"../common/source/Main.cpp"
	"../common/source/Plugin.cpp"
	"../common/source/SDKAboutPluginsHelper.cpp"
	"../common/source/Suites.cpp"	
	"Resources/Win/MenuPlay.rc"
    	
)

target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>)
target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/Source>)

target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/../common/includes>)
target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/../common/win>)
target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/../../illustratorapi/pica_sp>)
target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/../../illustratorapi/illustrator>)
target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/../../illustratorapi/ate>)


foreach(LANG  C CXX RC)
    set(CMAKE_${LANG}_STANDARD_INCLUDE_DIRECTORIES ${CUSTOM_INCLUDE_DIRECTORIES})
endforeach()

 

There is no step for building the plugin.pipl-file, I use the one which was generated via the VS-project.

I put this small sample under github:
https://github.com/Voronwe-the-guide/IllustratorPluginCmake
(The illustratorapi itself is not the, because I was unsure whether it is allowed by Adobe to publish it there. If it is ok, I can also upload it

Correct answer Thorsten_dev

Heureka!
I was able to build and run my example aip.
This line was missing in CMake:

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

This will provide a .lib for the .dll, which seems that this is neede for Windows.
Source how to do:

https://stackoverflow.com/questions/7614286/how-do-i-get-cmake-to-create-a-dll-and-its-matching-lib-file

Now next step would be to work with libraries. But at least one first step is made.
I will keep you updated


😄😄😄

I was finally able to get my plugin running on Windows with cmake.
I found out the following:

 

The following has to be set in CMake:

 

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

 

Also, it has to be explicitly set as a Shared library, because when setting nothing, my CMake build it as a Static Library: 

 

add_library(${PROJECT_NAME} SHARED)

 

 I will keep the github open, so if somebody fall in the same problem, there is an example how to do it (If I have time, I will maybe also include the handling for Mac):
https://github.com/Voronwe-the-guide/IllustratorPluginCmake

On other thing I found out this morning:

I had the main.cpp, which includes the function 

extern "C" ASAPI ASErr PluginMain(char* caller, char* selector, void* message)

in a static library (I made a static library as a wrapper of all the Adobe-API). This works well on Mac, but not on Windows. Here, the main.cpp must be a part of the .aip-Build.

One good thing I found out: Illustrator checks for dlls which are in the same folder as the Plugin

 That means, it is not needed to mess up c:\Program Files\Adobe\Adobe Illustrator 2023\Support Files\Contents\Windows\. with dlls. 

Just put the aip and it's dlls somewhere, and make a symbolic Link to that folder in c:\Program Files\Adobe\Adobe Illustrator 2023\Plug-ins\


Thanks a lot for all the help, it put me at least on the right track

1 reply

Inspiring
May 12, 2023

Addition (Because I do not see an edit-button):
the plugin.pipl was build with the following call:

c:\Python27\python2.exe ..\..\tools\pipl\create_pipl.py -input "[{\"name\":\"MenuPlay\"}]"  
A. Patterson
Inspiring
May 12, 2023

This usually happens because it's missing the PIPL. You can check if it's in there by opening the AIP file in Visual Studio in the Resource editor. File > Open as usual. Make sure you pick the AIP but don't click Open yet. Now you can click on the Open's arrow button and pick "Open with...". Choose 'Resource Editor' (last entry). You should see something like this:

 

 

If you don't, your PIPL isn't being included, and Illustrator will ignore your AIP.

 

P.S. You don't need:

set(CMAKE_AUTOMOC ON)

 That's for Qt (unless you are going to add Qt later, we do!)

Inspiring
May 17, 2023

I just found out that someone has done a rewrite of that tool, which you can find here. I just tried it out and it's about 1000x faster and seems to work more or less the same. So if you find the other tool too slow, give it a try. Their version of that dialog I mentioned is "Options" > "Customize Search Folders"

 

Minor note: your run DependenciesGui.exe not Dependencies.exe in the unzipped folder. I'll hang on to this and I suspect I'll be advocating for it in the future instead.


Heureka!
I was able to build and run my example aip.
This line was missing in CMake:

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

This will provide a .lib for the .dll, which seems that this is neede for Windows.
Source how to do:

https://stackoverflow.com/questions/7614286/how-do-i-get-cmake-to-create-a-dll-and-its-matching-lib-file

Now next step would be to work with libraries. But at least one first step is made.
I will keep you updated