How to cross compile with cmake + arm-none-eabi on windows? - windows

I like to automate the cross compiling for several projects on a Windows build server. I have some problems with the arm cross compiler. Setting it up seems a bit difficult. The cmake compiler check fails with a linking error(see below).
My experimental project looks like:
main.cpp - a test programm
CMakeLists.txt - the cmake build script
cmake/STM32F2xx.cmake - the special settings for the ARM STM32F2xx-series
I am using 3 Packages:
cmake-3.8.0-win64-x64.msi -cmake for windows
mingw-w64-install.exe - mingw 64 for windows
gcc-arm-none-eabi-6-2017-q1-update-win32.exe - arm x compiler
The main.cpp contains:
int main(void) {
return 0;
}
The CMakeLists.txt contains:
cmake_minimum_required (VERSION 3.0)
# module name
set(PrjName testPrj)
project (${PrjName})
# module version
set(PCK_MAJOR 1)
set(PCK_MINOR 0)
set(PCK_REVISION 0)
#####################
# Features switches
#####################
#####################
# architecture
#####################
# possible values:
# NATIVE
# STM32F2xx
SET(Arch NATIVE CACHE STRING "Architecture")
#############################
# software stack search path
############################
SET(SWstackPath NONE CACHE STRING "software stack search path")
#############################
# software stack handling
############################
if (${SWstackPath} STREQUAL NONE)
else ()
include_directories(${SWstackPath})
endif()
#############################
# package creation
#############################
SET(PackageFormat "DEFAULT" CACHE STRING "the format of the installation package")
########################
# define module content
########################
# MetaData header
set(testApp "testApp")
set(${testApp}_VERSION_MAJOR 1)
set(${testApp}_VERSION_MINOR 2)
set(${testApp}_VERSION_REVISION 3)
set(${testApp}_SOVERSION 4)
########################
# architecture handling
########################
if(${Arch} STREQUAL NATIVE)
MESSAGE("Architecture is set to NATIVE")
else()
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/${Arch}.cmake)
endif()
if (${PackageFormat} STREQUAL "DEFAULT")
if (UNIX)
include(GNUInstallDirs)
set(CPACK_GENERATOR "DEB")
else ()
set(CPACK_GENERATOR "ZIP")
set(CMAKE_INSTALL_FULL_BINDIR "bin")
set(CMAKE_INSTALL_FULL_LIBDIR "lib")
set(CMAKE_INSTALL_FULL_LIBDIRSTATIC "lib")
set(CMAKE_INSTALL_FULL_INCLUDEDIR "include")
set(CMAKE_INSTALL_FULL_MANDIR "doc")
endif()
elseif(${PackageFormat} STREQUAL "ZIP")
set(CPACK_GENERATOR "ZIP")
set(CMAKE_INSTALL_FULL_BINDIR "bin")
set(CMAKE_INSTALL_FULL_LIBDIR "lib")
set(CMAKE_INSTALL_FULL_LIBDIRSTATIC "lib")
set(CMAKE_INSTALL_FULL_INCLUDEDIR "include")
set(CMAKE_INSTALL_FULL_MANDIR "doc")
else()
message( FATAL_ERROR "The PackageFormat is unknown")
endif()
################################
# compile of the module content
################################
list(APPEND testApp_sources
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
)
add_executable(${testApp}
${testApp_sources}
)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set_target_properties(${testApp} PROPERTIES
LINKER_LANGUAGE CXX
)
################################
# installation
################################
if(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
# install app
install(
TARGETS ${testApp}
RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/static
)
set(CPACK_PACKAGE_DESCRIPTION "test")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "test")
set(CPACK_PACKAGE_VENDOR "xxx")
set(CPACK_PACKAGE_CONTACT "xxx")
set(CPACK_PACKAGE_VERSION_MAJOR "${PCK_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${PCK_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${PCK_REVISION}")
set(CPACK_PACKAGE_FILE_NAME "${PrjName}_${PCK_MAJOR}.${PCK_MINOR}.${PCK_REVISION}")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${PrjName}_${PCK_MAJOR}.${PCK_MINOR}.${PCK_REVISION}")
include(CPack)
endif()
The cmake/STM32F2xx.cmake contains:
set(CMAKE_C_FLAGS_INIT "--cpu Cortex-M3")
set(CMAKE_CXX_FLAGS_INIT "--cpu Cortex-M3")
set(CMAKE_C_LINK_FLAGS_INIT "--zt")
I created an toolchain file for the arm compiler:
# generated cmake toolchain file for
include (CMakeForceCompiler)
# We are cross compiling so we don't want compiler tests to run, as they will fail
set(CMAKE_SYSTEM_NAME Generic)
# Set processor type
set(CMAKE_SYSTEM_PROCESSOR arm)
SET(CMAKE_CROSSCOMPILING 1)
set(CMAKE_ASM_COMPILER "arm-none-eabi-as.exe")
set(CMAKE_C_COMPILER "arm-none-eabi-gcc.exe")
set(CMAKE_CXX_COMPILER "arm-none-eabi-g++.exe")
set(CMAKE_LINKER "arm-none-eabi-gcc.exe")
set(CMAKE_MAKE_PROGRAM "mingw32-make.exe")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --specs=nosys.specs")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --specs=nosys.specs")
When compiling on cmd with:
cd D:\git\myTestBuild\build
PATH=C:\Program Files\CMake\bin;C:\Program Files (x86)\GNU Tools ARM Embedded\6 2017-q1-update\bin;C:\Program Files\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev2\mingw64\bin;%PATH%
"C:\Program Files\CMake\bin\cmake.exe" -DArch="STM32F2xx" -G"MinGW Makefiles" -DPackageFormat=ZIP -DSWstackPath="D:\git\myTestBuild\SWstack" -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE="D:\git\myTestBuild\dump\toolchain.cmake" ..
CMake Error at C:/Program Files/CMake/share/cmake-3.8/Modules/CMakeTestCCompiler.cmake:51 (message):
The C compiler "C:/Program Files (x86)/GNU Tools ARM Embedded/6
2017-q1-update/bin/arm-none-eabi-gcc.exe" is not able to compile a simple
test program.
It fails with the following output:
Change Dir: D:/git/myTestBuild/build/CMakeFiles/CMakeTmp
Run Build Command:"C:/Program
Files/mingw-w64/x86_64-6.3.0-posix-seh-rt_v5-rev2/mingw64/bin/mingw32-make.exe"
"cmTC_8c052/fast"
C:/Program
Files/mingw-w64/x86_64-6.3.0-posix-seh-rt_v5-rev2/mingw64/bin/mingw32-make.exe
-f CMakeFiles\cmTC_8c052.dir\build.make CMakeFiles/cmTC_8c052.dir/build
mingw32-make.exe[1]: Entering directory
'D:/git/myTestBuild/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_8c052.dir/testCCompiler.c.obj
"C:\Program Files (x86)\GNU Tools ARM Embedded\6
2017-q1-update\bin\arm-none-eabi-gcc.exe" -o
CMakeFiles\cmTC_8c052.dir\testCCompiler.c.obj -c
D:\git\myTestBuild\build\CMakeFiles\CMakeTmp\testCCompiler.c
Linking C executable cmTC_8c052
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_link_script
CMakeFiles\cmTC_8c052.dir\link.txt --verbose=1
"C:\Program Files (x86)\GNU Tools ARM Embedded\6
2017-q1-update\bin\arm-none-eabi-gcc.exe"
CMakeFiles/cmTC_8c052.dir/testCCompiler.c.obj -o cmTC_8c052
c:/program files (x86)/gnu tools arm embedded/6
2017-q1-update/bin/../lib/gcc/arm-none-eabi/6.3.1/../../../../arm-none-eabi/lib\libc.a(lib_a-exit.o):
In function `exit':
exit.c:(.text.exit+0x2c): undefined reference to `_exit'
collect2.exe: error: ld returned 1 exit status
CMakeFiles\cmTC_8c052.dir\build.make:96: recipe for target 'cmTC_8c052'
failed
mingw32-make.exe[1]: *** [cmTC_8c052] Error 1
mingw32-make.exe[1]: Leaving directory
'D:/git/myTestBuild/build/CMakeFiles/CMakeTmp'
Makefile:125: recipe for target 'cmTC_8c052/fast' failed
mingw32-make.exe: *** [cmTC_8c052/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:5 (project)
It fails. The compiler can't link the simple demo program because it does not find the "_exit" symbol. This problem should be overcome by adding "--specs=nosys.specs". Seems that it does not work.
Any ideas?

Turning my comment into an answer
I've given a reduced version of your an example a try. I could reproduce your initial error and could fix the compiler detection by setting CMAKE_TRY_COMPILE_TARGET_TYPE to STATIC_LIBRARY. But then building an "executable" would still fail.
So you can set CMAKE_EXE_LINKER_FLAGS_INIT to --specs=nosys.specs (since those are linker flags). Just make sure to start from an empty binary output directory if you are using ..._INIT flags, since the resulting CMAKE_EXE_LINKER_FLAGS is cached.
I prefer to force the result CMAKE_EXE_LINKER_FLAGS variable (INTERNAL does imply FORCE).
CMakeLists.txt
cmake_minimum_required(VERSION 3.6)
project(testApp)
file(WRITE main.cpp "int main(void) { return 0; }")
set(testApp "testApp")
list(
APPEND testApp_sources
main.cpp
)
add_executable(
${testApp}
${testApp_sources}
)
toolchain.cmake
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_C_COMPILER "arm-none-eabi-gcc.exe")
set(CMAKE_CXX_COMPILER "arm-none-eabi-g++.exe")
set(CMAKE_EXE_LINKER_FLAGS "--specs=nosys.specs" CACHE INTERNAL "")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
Does:
build> cmake -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE:PATH="..\toolchain.cmake" ..
-- The C compiler identification is GNU 6.3.1
-- The CXX compiler identification is GNU 6.3.1
-- Check for working C compiler: C:/Program Files (x86)/GNU Tools ARM Embedded/6 2017-q1-update/bin/arm-none-eabi-gcc.exe
-- Check for working C compiler: C:/Program Files (x86)/GNU Tools ARM Embedded/6 2017-q1-update/bin/arm-none-eabi-gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Program Files (x86)/GNU Tools ARM Embedded/6 2017-q1-update/bin/arm-none-eabi-g++.exe
-- Check for working CXX compiler: C:/Program Files (x86)/GNU Tools ARM Embedded/6 2017-q1-update/bin/arm-none-eabi-g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: build
build> cmake --build .
Scanning dependencies of target testApp
[ 50%] Building CXX object CMakeFiles/testApp.dir/main.obj
[100%] Linking CXX executable testApp
[100%] Built target testApp
References
cmake cross-compile with specific linker doesn't pass arguments to armlink
What's the CMake syntax to set and use variables?

Related

How can I compile example in ESP-IDF

I've installed esp-idf and I'm trying to compile example build_system/cmake/idf_as_lib
and I got the error in the ESP-IDF CMD which not allow me to compile that example. The same problem is in Visual Studio Code.
Probably I should set environment path CMAKE_C_COMPILER but I don't know what should I point.
I've installed CMAKE on my windows
My actual environment paths:
IDF_PYTHON_ENV_PATH -> C:\esp\tools.espressif\python_env\idf4.4_py3.8_env\Scripts\python.exe
IDF_TOOLS_PATH -> C:\esp\tools.espressif
IDF_PATH -> C:\esp\esp-idf
C:\esp\esp-idf\examples\build_system\cmake\idf_as_lib>idf.py build
Executing action: all (aliases: build)
Running cmake in directory c:\esp\esp-idf\examples\build_system\cmake\idf_as_lib\build
Executing "cmake -G Ninja -DPYTHON_DEPS_CHECKED=1 -DESP_PLATFORM=1 -DCCACHE_ENABLE=1 c:\esp\esp-idf\examples\build_system\cmake\idf_as_lib"...
-- The C compiler identification is unknown
CMake Error at CMakeLists.txt:3 (project):
No CMAKE_C_COMPILER could be found.
Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
See also "C:/esp/esp-idf/examples/build_system/cmake/idf_as_lib/build/CMakeFiles/CMakeOutput.log".
See also "C:/esp/esp-idf/examples/build_system/cmake/idf_as_lib/build/CMakeFiles/CMakeError.log".
cmake failed with exit code 1
CMakeList
cmake_minimum_required(VERSION 3.5)
project(idf_as_lib C)
if("${TARGET}" STREQUAL "esp32")
# Include for ESP-IDF build system functions
include($ENV{IDF_PATH}/tools/cmake/idf.cmake)
# Create idf::esp32 and idf::freertos static libraries
idf_build_process(esp32
# try and trim the build; additional components
# will be included as needed based on dependency tree
#
# although esptool_py does not generate static library,
# processing the component is needed for flashing related
# targets and file generation
COMPONENTS esp32 freertos esptool_py
SDKCONFIG ${CMAKE_CURRENT_LIST_DIR}/sdkconfig
BUILD_DIR ${CMAKE_BINARY_DIR})
else()
# Create stubs for esp32 and freertos, stub::esp32 and stub::freertos
add_subdirectory(stubs/esp32)
add_subdirectory(stubs/freertos)
add_subdirectory(stubs/spi_flash)
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(elf_file ${CMAKE_PROJECT_NAME}.elf)
add_executable(${elf_file} main.c)
# Link the static libraries to the executable
if("${TARGET}" STREQUAL "esp32")
target_link_libraries(${elf_file} idf::esp32 idf::freertos idf::spi_flash)
# Attach additional targets to the executable file for flashing,
# linker script generation, partition_table generation, etc.
idf_build_executable(${elf_file})
else()
target_link_libraries(${elf_file} stub::esp32 stub::freertos stub::spi_flash)
endif()

cmake: Could NOT find CURL (missing: CURL_LIBRARY CURL_INCLUDE_DIR)

I'm on windows 10 and I want to use curlpp library. The building of curlpp depends on the availability of curl and curl is by default present in my system but when i try to run the cmake, it gives the following output
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.19043.
-- The C compiler identification is MSVC 19.29.30145.0
-- The CXX compiler identification is MSVC 19.29.30145.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- curlpp version=[0.8.1]
-- curlpp version num=[000801]
-- Looking for CURL
-- Could NOT find CURL (missing: CURL_LIBRARY CURL_INCLUDE_DIR)
CMake Error at C:/Program Files/CMake/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find CURL (missing: CURL_LIBRARY CURL_INCLUDE_DIR)
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
C:/Program Files/CMake/share/cmake-3.22/Modules/FindCURL.cmake:181 (find_package_handle_standard_args)
CMakeLists.txt:60 (find_package)
Here is the CmakeLists.txt of curlpp
project(curlpp)
# In response to CMake 3.0 generating warnings regarding policy CMP0042,
# the OSX RPATH settings have been updated per recommendations found
# in the CMake Wiki:
# http://www.cmake.org/Wiki/CMake_RPATH_handling#Mac_OS_X_and_the_RPATH
if(POLICY CMP0042)
cmake_policy(SET CMP0042 NEW) # MACOSX_RPATH
set(CMAKE_MACOSX_RPATH TRUE)
endif()
# for unix platform, define install directories.
include(GNUInstallDirs)
if(WIN32)
# cmake 3.4 is required for CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS
cmake_minimum_required(VERSION 3.4)
# c++ 11 support from cmake 3.4 or newer
set(CMAKE_CXX_STANDARD 11) # C++11...
set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required...
set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
else()
if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_LESS 3.1)
cmake_minimum_required(VERSION 2.8)
# c++11 support for cmake 2.8.12 - 3.0.x
#
# for non-windows platform we try to keep cmake 2.8 support
# since entreprise distribution tends to have 2.8 version.
add_compile_options(-std=c++11)
else()
# c++ 11 support from cmake 3.1 or newer
set(CMAKE_CXX_STANDARD 11) # C++11...
set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required...
set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11
endif()
endif()
# Conan.io integration
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/conanbuildinfo.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
endif()
# extra (pkg-config-related files)
add_subdirectory(extras)
#########################################################################################
# Look for dependencies
# Documented at https://cmake.org/cmake/help/v3.0/module/FindCURL.html?highlight=curlpp
# Seems simple.
message(STATUS "Looking for CURL")
include(FindCURL)
find_package(CURL REQUIRED)
if(CURL_FOUND)
message(STATUS "Found CURL version: ${CURL_VERSION_STRING}")
message(STATUS "Using CURL include dir(s): ${CURL_INCLUDE_DIRS}")
message(STATUS "Using CURL lib(s): ${CURL_LIBRARIES}")
else()
message(FATAL_ERROR "Could not find CURL")
endif()
# All following targets should search these directories for headers
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/include
${CURL_INCLUDE_DIRS}
)
#########################################################################################
# Define Targets
# If building on windows, install path will be in build/winbuild
if(CMAKE_SYSTEM MATCHES "Windows")
set(CMAKE_INSTALL_PREFIX "winbuild")
endif()
file(GLOB_RECURSE HeaderFileList "${CMAKE_CURRENT_SOURCE_DIR}/include/*")
file(GLOB_RECURSE SourceFileList "${CMAKE_CURRENT_SOURCE_DIR}/src/*")
add_library(${PROJECT_NAME} SHARED ${HeaderFileList} ${SourceFileList})
target_link_libraries(${PROJECT_NAME} ${CURL_LIBRARIES} ${CONAN_LIBS})
set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION 1 VERSION 1.0.0)
add_library(${PROJECT_NAME}_static STATIC ${HeaderFileList} ${SourceFileList})
# Make sure that on unix-platforms shared and static libraries have
# the same root name, but different suffixes.
#
# (solution taken from https://cmake.org/Wiki/CMake_FAQ#How_do_I_make_my_shared_and_static_libraries_have_the_same_root_name.2C_but_different_suffixes.3F)
#
# Making shared and static libraries have the same root name, but different suffixes
SET_TARGET_PROPERTIES(${PROJECT_NAME}_static PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
# Now the library target "curlpp_static" will be named "curlpp.lib" with MS tools.
# This conflicts with the "curlpp.lib" import library corresponding to "curlpp.dll",
# so we add a "lib" prefix (which is default on other platforms anyway):
SET_TARGET_PROPERTIES(${PROJECT_NAME}_static PROPERTIES PREFIX "lib")
target_link_libraries(${PROJECT_NAME}_static ${CURL_LIBRARIES} ${CONAN_LIBS})
# install headers
install(DIRECTORY include/utilspp/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/utilspp")
install(DIRECTORY include/curlpp/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/curlpp")
install(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}_static
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
I've also downloaded curl from GitHub and had successfully build it but i don't know how to tell the cmake to find the curl
Any help would be appreciated. thanks

CMake issue when Avast is running

I have an issue when running CMake on Windows 10 when avast antivirus is running.
I wrote a small basic CMakeLists.txt :
cmake_minimum_required(VERSION 3.10)
# set the project name
project(RayTracing)
# add the executable
add_executable(rat_tracing main.cpp)
When I run cmake -G "MSYS Makefiles" CMakeLists.txt with Avast activated I get::
-- The C compiler identification is GNU 10.3.0
-- The CXX compiler identification is GNU 10.3.0
-- Detecting C compiler ABI info
CMake Error at C:/Program Files/CMake/share/cmake-3.23/Modules/CMakeDetermineCompilerABI.cmake:49 (try_compile):
Failed to open
C:/Users/pc/Documents/C++/MyRayTracing/CMakeFiles/CMakeTmp/CMakeLists.txt
Permission denied
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.23/Modules/CMakeTestCCompiler.cmake:26 (CMAKE_DETERMINE_COMPILER_ABI)
CMakeLists.txt:4 (project)
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/Program Files/msys64/mingw64/bin/gcc.exe
CMake Error at C:/Program Files/CMake/share/cmake-3.23/Modules/CMakeTestCCompiler.cmake:56 (try_compile):
Failed to open
C:/Users/pc/Documents/C++/MyRayTracing/CMakeFiles/CMakeTmp/CMakeLists.txt
Permission denied
Call Stack (most recent call first):
CMakeLists.txt:4 (project)
-- Check for working C compiler: C:/Program Files/msys64/mingw64/bin/gcc.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-3.23/Modules/CMakeTestCCompiler.cmake:69 (message):
The C compiler
"C:/Program Files/msys64/mingw64/bin/gcc.exe"
is not able to compile a simple test program.
It fails with the following output:
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:4 (project)
-- Configuring incomplete, errors occurred!
See also "C:/Users/pc/Documents/C++/MyRayTracing/CMakeFiles/CMakeOutput.log".
See also "C:/Users/pc/Documents/C++/MyRayTracing/CMakeFiles/CMakeError.log".
But when I disable Avast, everything works fine and I get :
-- The C compiler identification is GNU 10.3.0
-- The CXX compiler identification is GNU 10.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/msys64/mingw64/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/msys64/mingw64/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/pc/Documents/C++/MyRayTracing
I've done some research, but no one seems to have had the same problem. The most similar cases are those where Avast thinks Cmake is a virus.
Thx.
While working on another small c++ project, I find a solution to this problem.
Create a small "Hello word !" program.
main.cpp
#include <iostream>
int main() {
std::cout << "Hello word ! " << std::endl;
return 0;
}
And a small CMakeLists.txt.
CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
# set the project name
project(Tutorial)
# add the executable
add_executable(Tutorial main.cpp)
The use cmake or cmake-gui to configure and build the project.
At this point, a warning from Avast will appear. It will say that CMakeLists.txt is trying to modify a protected directory, in my case it was "C:/Users/pc/Documents/" and will ask if you allow it or not.
Authorize it and it will work on any other project.

OpenMP CMake Apple

I am currently trying to compile a project on Mac using cmake, but running into trouble. I have already looked at this article [1], but am still running into some trouble. My CMakeLists.txt looks as follows.
project(tpch_framework)
# enable c++11
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_C_COMPILER "/usr/local/Cellar/llvm/10.0.0_3/bin/clang")
set(CMAKE_CXX_COMPILER "/usr/local/Cellar/llvm/10.0.0_3/bin/clang++")
set(OPENMP_LIBRARIES "/usr/local/Cellar/llvm/10.0.0_3/lib")
set(OPENMP_INCLUDES "/usr/local/Cellar/llvm/10.0.0_3/include")
OPTION (USE_OpenMP "Use OpenMP to enamble <omp.h>" ON)
# Find OpenMP
if(APPLE AND USE_OpenMP)
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp")
set(OpenMP_C_LIB_NAMES "omp")
set(OpenMP_omp_LIBRARY omp)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp")
set(OpenMP_CXX_LIB_NAMES "omp")
set(OpenMP_omp_LIBRARY omp)
endif()
endif()
if(USE_OpenMP)
find_package(OpenMP REQUIRED)
endif(USE_OpenMP)
if (OPENMP_FOUND)
include_directories("${OPENMP_INCLUDES}")
link_directories("${OPENMP_LIBRARIES}")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS} -libomp")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS} -libomp")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif(OPENMP_FOUND)
# Configure required Boost libraries
set(BOOST_ROOT "" CACHE PATH "Boost build root (useful on Windows)")
option(Boost_USE_STATIC_LIBS
"Search for static boost libs" OFF)
option(Boost_USE_MULTITHREADED
"Search for multithreaded boost libs" ON)
option(Boost_USE_STATIC_RUNTIME
"Search for boost libs linked against static C++ runtime" OFF)
find_package(Boost 1.47.0 REQUIRED filesystem system)
# ensure that dependant libraries not explicitly specified here
# are found by the linker:
link_directories(${Boost_LIBRARY_DIRS})
include_directories(${Boost_INCLUDE_DIRS})
set(LIBS ${LIBS} ${Boost_LIBRARIES})
#Bring the headers into the project
include_directories(include)
FILE(GLOB_RECURSE INC_ALL "include/*.hpp")
#However, the file(GLOB...) allows for wildcard additions:
file(GLOB SOURCES "src/*.cpp")
add_library(tpch_framework ${SOURCES})
add_executable(framework main.cpp ${INC_ALL})
target_link_libraries(framework tpch_framework)
#target_link_libraries(framework stdc++fs)
target_link_libraries(framework ${LIBS})
When I execute this, I get the following output.
-- The C compiler identification is AppleClang 11.0.0.11000033
-- The CXX compiler identification is AppleClang 11.0.0.11000033
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenMP_C: -Xpreprocessor -fopenmp
-- Found OpenMP_CXX: -Xpreprocessor -fopenmp
-- Found OpenMP: TRUE
-- Found Boost: /usr/local/lib/cmake/Boost-1.72.0/BoostConfig.cmake (found suitable version "1.72.0", minimum required is "1.47.0") found components: filesystem system
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/...
However, when I then use make, I get the following error.
/Users/myname/Desktop/Uni/MHD/tpch_framework_challenge_mhd_2020/src/task4.cpp:48:5: error: use of undeclared identifier 'omp_set_num_threads'
omp_set_num_threads(4);
Which I am guessing comes, as I get this warning: clang-10: warning: -libomp: 'linker' input unused [-Wunused-command-line-argument].
Does anybody have any ideas? I have been stuck with this for way too long and would appreciate any tips.
Kind regards,
Moritz
If you can use a recent version of CMake, this build should work.
# NOTE: Every top-level CMakeLists.txt must start with these two lines
cmake_minimum_required(VERSION 3.16)
project(tpch_framework)
## Enable C++14
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
## Find dependencies
# OpenMP
find_package(OpenMP REQUIRED)
# Boost
set(BOOST_ROOT "" CACHE PATH "Boost build root (useful on Windows)")
option(Boost_USE_STATIC_LIBS
"Search for static boost libs" OFF)
option(Boost_USE_MULTITHREADED
"Search for multithreaded boost libs" ON)
option(Boost_USE_STATIC_RUNTIME
"Search for boost libs linked against static C++ runtime" OFF)
find_package(Boost 1.47.0 REQUIRED COMPONENTS filesystem system)
## Add main project targets
# NOTE: This is completely wrong and will break incremental builds after
# doing a "git pull" or similar. You should never glob for source
# files, but instead list them explicitly.
file(GLOB SOURCES "src/*.cpp")
add_library(tpch_framework ${SOURCES})
target_include_directories(tpch_framework PUBLIC BUILD_INTERFACE:include)
target_link_libraries(tpch_framework
PUBLIC
OpenMP::OpenMP_CXX
Boost::boost
Boost::filesystem
Boost::system)
add_executable(framework main.cpp)
target_link_libraries(framework PRIVATE tpch_framework)
There is so much bad CMake advice here on SO and in tutorials, it's a real shame.

CMake 3.10 not working at all with Visual Studio 2015, 2017

I'm trying to compile two different git projects via CMake.
I have Visual Studio 2017 Community, MinGW and CodeBlocks installed and CMake throws an error with all of them. Keep in mind I have not used CMake before.
With "Visual Studio 15 2017 selected I get this error:
The C compiler identification is MSVC 19.12.25835.0
The CXX compiler identification is MSVC 19.12.25835.0
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.12.25827/bin/Hostx86/x86/cl.exe
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.12.25827/bin/Hostx86/x86/cl.exe -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.12.25827/bin/Hostx86/x86/cl.exe
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.12.25827/bin/Hostx86/x86/cl.exe -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
Build type: Release
Performing Test COMPILER_SUPPORTS_CXX11
Performing Test COMPILER_SUPPORTS_CXX11 - Failed
Performing Test COMPILER_SUPPORTS_CXX0X
Performing Test COMPILER_SUPPORTS_CXX0X - Failed
CMake Error at CMakeLists.txt:26 (message):
The compiler C:/Program Files (x86)/Microsoft Visual
Studio/2017/Community/VC/Tools/MSVC/14.12.25827/bin/Hostx86/x86/cl.exe has
no C++11 support. Please use a different C++ compiler.
With "MinGW Makefiles" selected I get a cc1.exe errors about a bunch of ddls. Sadly the popup error messages are in german even though I've set everything in Win10 to english so I dont know what they say exactly.
With "CodeBlocks - MinGW Makefiles" I get the same as above.
Link to one of the git projects Im trying to compile:
https://github.com/raulmur/ORB_SLAM2
https://github.com/YutaItoh/3D-Eye-Tracker
By the way, I tried the same with VS 2015 previously.
Content of the CMakeLists file:
cmake_minimum_required(VERSION 2.8)
project(ORB_SLAM2)
IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE Release)
ENDIF()
MESSAGE("Build type: " ${CMAKE_BUILD_TYPE})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O3 -march=native ")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3 -march=native")
# Check C++11 or C++0x support
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
add_definitions(-DCOMPILEDWITHC11)
message(STATUS "Using flag -std=c++11.")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
add_definitions(-DCOMPILEDWITHC0X)
message(STATUS "Using flag -std=c++0x.")
else()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules)
find_package(OpenCV 3.0 QUIET)
if(NOT OpenCV_FOUND)
find_package(OpenCV 2.4.3 QUIET)
if(NOT OpenCV_FOUND)
message(FATAL_ERROR "OpenCV > 2.4.3 not found.")
endif()
endif()
find_package(Eigen3 3.1.0 REQUIRED)
find_package(Pangolin REQUIRED)
include_directories(
${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/include
${EIGEN3_INCLUDE_DIR}
${Pangolin_INCLUDE_DIRS}
)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
add_library(${PROJECT_NAME} SHARED
src/System.cc
src/Tracking.cc
src/LocalMapping.cc
src/LoopClosing.cc
src/ORBextractor.cc
src/ORBmatcher.cc
src/FrameDrawer.cc
src/Converter.cc
src/MapPoint.cc
src/KeyFrame.cc
src/Map.cc
src/MapDrawer.cc
src/Optimizer.cc
src/PnPsolver.cc
src/Frame.cc
src/KeyFrameDatabase.cc
src/Sim3Solver.cc
src/Initializer.cc
src/Viewer.cc
)
target_link_libraries(${PROJECT_NAME}
${OpenCV_LIBS}
${EIGEN3_LIBS}
${Pangolin_LIBRARIES}
${PROJECT_SOURCE_DIR}/Thirdparty/DBoW2/lib/libDBoW2.so
${PROJECT_SOURCE_DIR}/Thirdparty/g2o/lib/libg2o.so
)
# Build examples
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/Examples/RGB-D)
add_executable(rgbd_tum
Examples/RGB-D/rgbd_tum.cc)
target_link_libraries(rgbd_tum ${PROJECT_NAME})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/Examples/Stereo)
add_executable(stereo_kitti
Examples/Stereo/stereo_kitti.cc)
target_link_libraries(stereo_kitti ${PROJECT_NAME})
add_executable(stereo_euroc
Examples/Stereo/stereo_euroc.cc)
target_link_libraries(stereo_euroc ${PROJECT_NAME})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/Examples/Monocular)
add_executable(mono_tum
Examples/Monocular/mono_tum.cc)
target_link_libraries(mono_tum ${PROJECT_NAME})
add_executable(mono_kitti
Examples/Monocular/mono_kitti.cc)
target_link_libraries(mono_kitti ${PROJECT_NAME})
add_executable(mono_euroc
Examples/Monocular/mono_euroc.cc)
target_link_libraries(mono_euroc ${PROJECT_NAME})
The C++11 capability check will always fail with MSVC. Use CMake's CMAKE_CXX_STANDARD variable.

Resources