Convert a Visual Studio project to CMake

If you already have Visual Studio projects (.vcxproj) and solutions (.sln) for your Azure Sphere applications, you'll need to convert them to use CMake. You can still open your Azure Sphere projects in Visual Studio to inspect project properties and other settings, but starting with the 20.01 release, they will not build successfully.

The easiest way to change a high-level app project to build with CMake is to start with the HelloWorld_HighLevelApp sample. You'll need to perform the following steps:

  1. Update main.c from your application.

  2. Copy any other C files that your application requires into the project folder.

  3. Open the CMakeLists.txt file and add any files that require compilation to the add_executable line. For example:

    add_executable (${PROJECT_NAME} main.c file1.c file2.c)

  4. Add any required libraries to the target_link_libraries line. For example:

    target_link_libraries (${PROJECT_NAME} applibs pthread gcc_s c mycustomlibrary)

    You can see which libraries your existing Visual Studio project uses by looking at the Linker inputs in the Project Properties. The exact menu items or keyboard shortcuts to view the linker inputs depends on which version of Visual Studio or Visual Studio Code you're using.

  5. Make sure you are calling the correct Azure Sphere CMake functions. In particular:

    • azsphere_target_add_image_package to set up the rules to create the image package file and to specify any resources files to include when building. For example:

      azsphere_target_add_image_package(${PROJECT_NAME} RESOURCE_FILES "file1.dat" "file2.dat")