Hi,
as I put the info about Using MinGW and Cygwin with Visual C++ here I was curious myself about how this works, so I tried this. It works pretty much great if you setup things correct and I will share the setup here.
Visual Studio will then compile with the MinGW compiler and you have the full blown IntelliSense support as well.
To get this to work you need:
- install Visual Studio community (current is 2019)
- have the MSYS2 development environment setup for Rack
- get the latest Rack SDK
- create a CMakeSettings.json for Visual Studio
- create a CMakeLists.txt for your plugin
Create CMakeLists.txt for your plugin and put it in your plugin source directory
This is a generic CMakeLists.txt to compile a Rack plugin under Windows:
cmake_minimum_required(VERSION 3.5)
if ("${RACK_SDK}" STREQUAL "")
message(FATAL_ERROR "Path to Rack SDK missing! Add -DRACK_SDK=<path to Rack SDK> to the cmake call.")
endif ()
message(STATUS "Use Rack SDK: ${RACK_SDK}")
# set this to the plugin slug!
set(PLUGIN_NAME myFancyPluginName)
project(VCVRack${PLUGIN_NAME}Plugin)
set(CMAKE_CXX_STANDARD 14)
# Do not change the LIB_NAME!
set(LIB_NAME plugin)
include_directories("${RACK_SDK}/include" "${RACK_SDK}/dep/include")
link_directories(${RACK_SDK})
file(GLOB_RECURSE SOURCES *.cpp)
file(GLOB_RECURSE SRC_SOURCES src/*.cpp)
add_library(${LIB_NAME} MODULE ${SOURCES} ${SRC_SOURCES})
add_definitions(-DARCH_WIN)
target_include_directories(${LIB_NAME} PRIVATE include)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
target_link_libraries(${LIB_NAME} "Rack")
set_target_properties(${LIB_NAME} PROPERTIES PREFIX "")
file(GLOB LICENSE LICENSE*)
file(INSTALL plugin.json res ${LICENSE} DESTINATION dist/${PLUGIN_NAME})
install(DIRECTORY ${PROJECT_BINARY_DIR}/lib/ DESTINATION ${PROJECT_BINARY_DIR}/dist/${PLUGIN_NAME} OPTIONAL)
install(DIRECTORY ${PROJECT_BINARY_DIR}/dist/${PLUGIN_NAME}/ DESTINATION ${PLUGIN_NAME})
Adapt the PLUGIN_NAME
variable, so it matches your plugin name.
Double check if all your source files will be collected by the file(GLOB_RECURSE ...
statements, if not adapt it to your needs.
Create CMakeSettings.json for your Environment and put it in your plugin source directory
{
"configurations": [
{
"name": "Mingw64-Release",
"generator": "Ninja",
"configurationType": "Release",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": "",
"inheritEnvironments": [ "mingw_64" ],
"environments": [
{
"MINGW64_ROOT": "C:\\msys64\\mingw64",
"BIN_ROOT": "${env.MINGW64_ROOT}\\bin",
"FLAVOR": "x86_64-w64-mingw32",
"TOOLSET_VERSION": "8.1.0",
"PATH": "${env.MINGW64_ROOT}\\bin;${env.MINGW64_ROOT}\\..\\usr\\local\\bin;${env.MINGW64_ROOT}\\..\\usr\\bin;${env.MINGW64_ROOT}\\..\\bin;${env.PATH}",
"INCLUDE": "${env.INCLUDE};${env.MINGW64_ROOT}\\include\\c++\\${env.TOOLSET_VERSION};${env.MINGW64_ROOT}\\include\\c++\\${env.TOOLSET_VERSION}\\tr1;${env.MINGW64_ROOT}\\include\\c++\\${env.TOOLSET_VERSION}\\${env.FLAVOR}",
"environment": "mingw_64"
}
],
"variables": [
{
"name": "CMAKE_C_COMPILER",
"value": "${env.BIN_ROOT}\\gcc.exe",
"type": "STRING"
},
{
"name": "CMAKE_CXX_COMPILER",
"value": "${env.BIN_ROOT}\\g++.exe",
"type": "STRING"
},
{
"name": "RACK_SDK",
"value": "ADD HERE THE PATH TO YOUR UNPACKED RACK SDK FOLDER!",
"type": "STRING"
}
],
"intelliSenseMode": "linux-gcc-x64"
}
]
}
Adapt in the environments
section the variables so it matches with your MSYS2 installation:
MINGW64_ROOT
FLAVOR
TOOLSET_VERSION
Adapt in the variables
section the value for RACK_SDK so it points to the directory containing the libRack.a
and include
.
Now start Visual Studio IDE and open project by Open Folder and navigate to your plugin sources (https://docs.microsoft.com/en-us/visualstudio/ide/develop-code-in-visual-studio-without-projects-or-solutions?view=vs-2019).
Thats it.
If you need another build configuration, e.g. for Debug, just copy the part under configuration and append it after the
existing configuration and change the adapt the configurationType
to Debug
.
I hope this helps someone, let me know.