I am trying to setup a toolchain file for cross compilation with CMake 3.12.0 version.
My object files have a different extensions than .obj
on Windows and .o
in UNIX.
Thus, I set my CMAKE_LANG_OUTPUT_EXTENSION
to .src
.
Unfortunately, this variable is overwritten by CMakeCInformation.cmake
file in these lines:
# some compilers use different extensions (e.g. sdcc uses .rel)
# so set the extension here first so it can be overridden by the compiler specific file
if(UNIX)
set(CMAKE_C_OUTPUT_EXTENSION .o)
else()
set(CMAKE_C_OUTPUT_EXTENSION .obj)
endif()
If I comment these lines my configurations will work and the right object extension will be used.
I think my toolchain file is configured so that CMake will not execute its internal compiler checks.
This is how my toolchain file entry lines look:
SET(CMAKE_SYSTEM_NAME Generic)
INCLUDE(CMakeForceCompiler)
SET(CMAKE_C_COMPILER_FORCED TRUE)
SET(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
#other compiler configuration lines here
SET(CMAKE_C_OUTPUT_EXTENSION .src)
SET(CMAKE_ASM_OUTPUT_EXTENSION .o)
SET(CMAKE_C_OUTPUT_EXTENSION_REPLACE 1)
SET(CMAKE_ASM_OUTPUT_EXTENSION_REPLACE 1)
I know CMakeForceCompiler
is depreciated and CMAKE_TRY_COMPILE_TARGET_TYPE
should be used that is why both are there.
I am telling CMake about my toolchain file using -DCMAKE_TOOLCHAIN_FILE
Can you please help me figure out what I am doing wrong?
EDIT: I was also trying to CACHE
the value of CMAKE_C_OUTPUT_EXTENSION
. At least for me this didn't work.
include
commands, maybe you can define a custom platform file where you override those values, name and place it in a dir structure that follows the required conventions for inclusion and, lastly, update theCMAKE_MODULE_PATH
with the root location for theinclude
to actually work. – ThaxterCMAKE_LANG_OUTPUT_EXTENSION
in the third line of your question supposed to beCMAKE_C_OUTPUT_EXTENSION
(typo)? – AntemundaneSET(CMAKE_C_COMPILER_FORCED TRUE)
and addCMAKE_FORCE_C_COMPILER
with the desired compiler name and id for cross-compiling. – Antemundane