Defining standard library directories in toolchain.
Hi, I am trying to cross-compile CMake project using the following toolchain file:
cmake_minimum_required (VERSION 3.6)
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_VERSION 10.0)
set(CMAKE_SYSTEM_PROCESSOR AMD64)
set(CMAKE_C_COMPILER "${MY_TOOLCHAIN}/path/to/c_compiler.exe")
set(CMAKE_CXX_COMPILER "${MY_TOOLCHAIN}/path/to/cxx_compiler.exe")
# Why there is no CMAKE_<LANG>_STANDARD_LINK_DIRECTORIES variable?
foreach(TARGET EXE SHARED STATIC MODULE)
set(CMAKE_${TARGET}_LINKER_FLAGS_INIT "/LIBPATH:\"${MY_TOOLCHAIN}/path/to/library_directories\"")
string(REPLACE ";" " " CMAKE_${TARGET}_LINKER_FLAGS_INIT "${CMAKE_${TARGET}_LINKER_FLAGS_INIT}")
endforeach()
foreach(LANG C CXX)
set(CMAKE_${LANG}_STANDARD_INCLUDE_DIRECTORIES "${MY_TOOLCHAIN}/path/to/include_directories")
endforeach()
set(CMAKE_FIND_ROOT_PATH "${MY_TOOLCHAIN}")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
Essentially I am cross-compiling C and C++ applications on Windows 10 64-bit.
In order to accomplish that I am specifying paths to:
-
C and C++ compilers (using CMAKE_<LANG>_COMPILER variables),
-
include and library directories,
which are provided by the MSVC compiler (like C and C++ standard libraries)
and Windows OS (like Windows SDK).
For include directories I've used CMAKE_<LANG>_STANDARD_INCLUDE_DIRECTORIES variables,
which worked great!
Unfortunately I have trouble with library directories,
because CMAKE_<LANG>_STANDARD_LINK_DIRECTORIES variables don't exist.
For now I am using CMAKE_EXE_LINKER_FLAGS_INIT and similar variables,
but this looks like a hack to me, because I am manually
passing "/LIBPATH" option and convert CMake list to a string separated with spaces.
What's the best way of defining paths to standard libraries in a toolchain file?
Is there a reason why CMAKE_<LANG>_STANDARD_LINK_DIRECTORIES variables don't exist?
If not, maybe future versions of CMake could introduce these variables?