Reputation:
Windows 10, CMake 3.19.1
Im trying to compile test project with XC8 compiler, CMake and custom toolchain (third party). Link: Toolchain repository
Toolchains quick guide says to only add two strings at top of my CMakeLists.txt. So ive got the next CMakeLists.txt:
project(Test)
# set up the Microchip cross toolchain
set(CMAKE_TOOLCHAIN_FILE ./external/cmake-microchip/toolchain.cmake)
# set the default MCU model
set(MICROCHIP_MCU PIC18F97J60)
add_executable(main main.c)
But occasionaly, every time CMake generation output starts with:
-- Building for: Visual Studio 16 2019
-- The C compiler identification is MSVC 19.28.29333.0
-- The CXX compiler identification is MSVC 19.28.29333.0
..... more
And i havent any Makefile in the output folder. Also im try to run CMake with -G "Unix makefiles". And makefile been generated, with wrong output and any trace of custom toolchain use. Output been:
-- The C compiler identification is GNU 9.2.0
-- The CXX compiler identification is GNU 9.2.0
-- Detecting C compiler ABI info
Every CMake generation try, im cleanup the output folder. Why custom toolchain doesnt starts?
Upvotes: 1
Views: 1633
Reputation: 66098
The variable CMAKE_TOOLCHAIN_FILE should be set before the first project()
call:
cmake_minimum_required(VERSION <..>)
# set up the Microchip cross toolchain
set(CMAKE_TOOLCHAIN_FILE ./external/cmake-microchip/toolchain.cmake)
project(Test)
# set the default MCU model
set(MICROCHIP_MCU PIC18F97J60)
add_executable(main main.c)
When first project()
call is processed, CMake automatically calls the script specified in CMAKE_TOOLCHAIN_FILE
.
Note, that preferred way is to not hardcode path to the toolchain in the CMakeLists.txt
but pass -DCMAKE_TOOLCHAIN_FILE=/path/to/toolchain
option to the cmake
.
Upvotes: 2