I want to add this library to my existing C++ project, which I have included by adding it as a submodule in an external folder, where external/CMakeLists.txt is:
set(FMI4C_BUILD_SHARED FALSE)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/fmi4c)
set_target_properties(fmi4c PROPERTIES LINKER_LANGUAGE C)
When I try to build my project with the Visual Studio 17 2022 generator, it compiles fine, but when I use the Ninja generator the build fails. For reference this is my CMakePresets.json:
{
"version": 2,
"configurePresets": [
{
"name": "debug_windows",
"displayName": "Debug Windows",
"binaryDir": "${sourceDir}/build",
"generator": "Visual Studio 17 2022",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"CMAKE_TOOLCHAIN_FILE": {
"value": "${sourceDir}/vcpkg/scripts/buildsystems/vcpkg.cmake",
"type": "FILEPATH"
},
"VCPKG_INSTALLED_DIR": "../../vcpkg_installed",
"NEMO_BUILD_TESTS": "TRUE",
"NEMO_BUILD_PYTHON_EXTENSION": "FALSE",
"NEMO_BUILD_CPPTESTS": "TRUE"
}
},
{
"name": "release_windows",
"displayName": "Release Windows",
"binaryDir": "${sourceDir}/build",
"generator": "Visual Studio 17 2022",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"CMAKE_TOOLCHAIN_FILE": {
"value": "${sourceDir}/vcpkg/scripts/buildsystems/vcpkg.cmake",
"type": "FILEPATH"
},
"VCPKG_INSTALLED_DIR": "../../vcpkg_installed",
"NEMO_BUILD_TESTS": "TRUE",
"NEMO_BUILD_PYTHON_EXTENSION": "FALSE",
"NEMO_BUILD_CPPTESTS": "TRUE"
}
},
{
"name": "debug_linux",
"displayName": "Debug Linux",
"binaryDir": "${sourceDir}/build",
"generator": "Ninja",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"CMAKE_TOOLCHAIN_FILE": {
"value": "${sourceDir}/vcpkg/scripts/buildsystems/vcpkg.cmake",
"type": "FILEPATH"
},
"VCPKG_INSTALLED_DIR": "../../vcpkg_installed",
"NEMO_BUILD_TESTS": "TRUE",
"NEMO_BUILD_PYTHON_EXTENSION": "FALSE",
"NEMO_BUILD_CPPTESTS": "TRUE"
}
},
{
"name": "release_linux",
"displayName": "Release Linux",
"binaryDir": "${sourceDir}/build",
"generator": "Ninja",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"CMAKE_TOOLCHAIN_FILE": {
"value": "${sourceDir}/vcpkg/scripts/buildsystems/vcpkg.cmake",
"type": "FILEPATH"
},
"VCPKG_INSTALLED_DIR": "../../vcpkg_installed",
"NEMO_BUILD_TESTS": "TRUE",
"NEMO_BUILD_PYTHON_EXTENSION": "FALSE",
"NEMO_BUILD_CPPTESTS": "TRUE"
}
}
],
"buildPresets": [
]
}
if I change the generator to Ninja for the windows builds, I get a lot of C1003 and C2440 errors, which I think is because the external library is being compiled using the C++ compiler instead of the C compiler
[build] C:Userstom.mcleansrcNemoexternalfmi4csrcfmi4c.c(4578): error C2440: '=': cannot convert from 'fmi3Status (__cdecl *)(fmi3Instance,const fmi3ValueReference *,size_t,fmi3Int8 *,size_t)' to 'fmi3GetInt8_t'
[build] C:Userstom.mcleansrcNemoexternalfmi4csrcfmi4c.c(4579): error C2440: '=': cannot convert from 'fmi3Status (__cdecl *)(fmi3Instance,const fmi3ValueReference *,size_t,fmi3UInt8 *,size_t)' to 'fmi3GetUInt8_t'
[build] C:Userstom.mcleansrcNemoexternalfmi4csrcfmi4c.c(4580): error C2440: '=': cannot convert from 'fmi3Status (__cdecl *)(fmi3Instance,const fmi3ValueReference *,size_t,fmi3Int16 *,size_t)' to 'fmi3GetInt16_t'
[build] C:Userstom.mcleansrcNemoexternalfmi4csrcfmi4c.c(4580): fatal error C1003: error count exceeds 100; stopping compilation
I am not sure why this is happening, I have tried to set the fmi4c library to be compiled with C by using
set_target_properties(fmi4c PROPERTIES LINKER_LANGUAGE C)
And have checked the CMakeLists.txt of fmi4c and at the top is has:
cmake_minimum_required(VERSION 3.15)
project(fmi4c C)
set(CMAKE_C_STANDARD 99)
How can I add this library to my existing c++ project with CMake?