Specifying compile language for <stdint.h> as C, not C++. Editing a MCU Project (coded using Keil) in VS

I have a working project for a STM32F746 microcontroller (MCU) that was coded using the Keil IDE. The project makes use of many of STMicroelectronics’ HAL libraries. I would like to continue working on the project using Visual Studio (VS). I believe most of the CMake files are in place, so VS knows where to find all the relevant libraries used. I am having trouble correctly compiling the <stdint.h> file.

I would like to be able to compile the project in VS to detect compile time errors. Building the project to flash the MCU will still be done using Keil of course.

The project structure is as follows:

  • MasterProject
    – MyProject:
    Contains my files coded in c++
    – STM32F7_Hal:
    Containing hardware abstraction c code, used in MyProject.
    – CMakeLists.txt

In STM32F7_Hal the header file stm32f746xx.h defines the register address offsets for the MCU I’m using. As an example:

typedef struct
{
__IO uint32_t SR;     /*!< ADC status register,                         Address offset: 0x00 */
__IO uint32_t CR1;    /*!< ADC control register 1,                      Address offset: 0x04 */
// etc.
} ADC_TypeDef;

Visual Studio cannot compile this file. I have the following error in the code above: variable “uint32_t” is not a type name. uint32_t is defined in <stdint.h>, which is included in the stm32f746xx.h file. I believe the reason for this error is because Visual Studio is compiling <stdint.h> in c++ and not c. I am not fully confident that this is the source of the problem though, because #include <stdint.h> is declared after extern "C" { in stm32f746xx.h (meaning that it should be compiled in c).

I have attempted to specify the compile language in the CMakeLists.txt file, without any luck, as seen below:

cmake_minimum_required(VERSION 3.9)
project(MasterProject)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wextra -Wpedantic -Wdouble-        
promotion -Wnull-dereference -Wuninitialized -Wsuggest-override -Wduplicated-cond -Wfloat-equal -Wunsafe-loop-optimizations -Wcast-align -Wwrite-strings -Wconversion -Wzero-as-null-pointer-constant -Wparentheses -Wuseless-cast -Wlogical-op -Waggressive-loop-optimizations ")

set_source_files_properties("C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.27.29110/include/stdint.h" PROPERTIES LANGUAGE C )

add_subdirectory(STM32F7_Hal)
set_source_files_properties(STM32F7_Hal PROPERTIES LANGUAGE C )

add_subdirectory(MyProject)

What am I doing wrong?

Note: I am a CMake novice. Feel free to point out clear gaps in my knowledge.