Fix: [CMake] cross-compiling requires native tools
(cherry picked from commit fdaf0d0b2f82701c8ea1e9a1125415351cf49e57)
This commit is contained in:

committed by
Jonathan G Rennison

parent
33c2150c49
commit
909c9656ce
@@ -143,10 +143,48 @@ compile_flags()
|
|||||||
add_executable(openttd WIN32 ${GENERATED_SOURCE_FILES})
|
add_executable(openttd WIN32 ${GENERATED_SOURCE_FILES})
|
||||||
# All other files are added via target_sources()
|
# All other files are added via target_sources()
|
||||||
|
|
||||||
|
set(host_tools_list strgen settingsgen)
|
||||||
|
|
||||||
|
if(CMAKE_CROSSCOMPILING)
|
||||||
|
# Pawn off the creation of the host utilities into its own dedicated space
|
||||||
|
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/host_tools)
|
||||||
|
file(TO_NATIVE_PATH ${CMAKE_COMMAND} native_cmake_command)
|
||||||
|
file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR} native_cmake_current_source_dir)
|
||||||
|
execute_process(
|
||||||
|
COMMAND "${native_cmake_command}" "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" "${native_cmake_current_source_dir}"
|
||||||
|
"-DCMAKE_C_COMPILER=/usr/bin/cc" "-DCMAKE_CXX_COMPILER=/usr/bin/c++"
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/host_tools
|
||||||
|
)
|
||||||
|
|
||||||
|
add_custom_target(host_tools
|
||||||
|
COMMAND ${CMAKE_COMMAND} --build . --target host_tools --config $<CONFIG>
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/host_tools
|
||||||
|
)
|
||||||
|
include(${CMAKE_CURRENT_BINARY_DIR}/host_tools/host_tools.cmake)
|
||||||
|
|
||||||
|
foreach(tgt IN ITEMS ${host_tools_list})
|
||||||
|
add_dependencies(host${tgt} host_tools)
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
else()
|
||||||
|
# Add an empty target, host tools are built inplace
|
||||||
|
add_custom_target(host_tools
|
||||||
|
DEPENDS ${host_tools_list}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
include(AddCustomXXXTimestamp)
|
include(AddCustomXXXTimestamp)
|
||||||
add_subdirectory(${CMAKE_SOURCE_DIR}/src)
|
add_subdirectory(${CMAKE_SOURCE_DIR}/src)
|
||||||
add_subdirectory(${CMAKE_SOURCE_DIR}/media/baseset)
|
add_subdirectory(${CMAKE_SOURCE_DIR}/media/baseset)
|
||||||
|
|
||||||
|
if(NOT CMAKE_CROSSCOMPILING)
|
||||||
|
foreach(tgt IN ITEMS ${host_tools_list})
|
||||||
|
add_executable(host${tgt} ALIAS ${tgt})
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
export(TARGETS ${host_tools_list} NAMESPACE host FILE host_tools.cmake)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_dependencies(openttd
|
add_dependencies(openttd
|
||||||
find_version)
|
find_version)
|
||||||
|
|
||||||
@@ -265,6 +303,7 @@ add_custom_target(find_version
|
|||||||
-DFIND_VERSION_BINARY_DIR=${CMAKE_BINARY_DIR}/generated
|
-DFIND_VERSION_BINARY_DIR=${CMAKE_BINARY_DIR}/generated
|
||||||
-DCPACK_BINARY_DIR=${CMAKE_BINARY_DIR}
|
-DCPACK_BINARY_DIR=${CMAKE_BINARY_DIR}
|
||||||
-DCONFIGURE_DEFINES="${CFG_DEFS}"
|
-DCONFIGURE_DEFINES="${CFG_DEFS}"
|
||||||
|
$<$<PLATFORM_ID:Windows>:-DWIN32=TRUE>
|
||||||
-P "${CMAKE_SOURCE_DIR}/cmake/scripts/FindVersion.cmake"
|
-P "${CMAKE_SOURCE_DIR}/cmake/scripts/FindVersion.cmake"
|
||||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||||
BYPRODUCTS ${GENERATED_SOURCE_FILES}
|
BYPRODUCTS ${GENERATED_SOURCE_FILES}
|
||||||
|
@@ -67,11 +67,11 @@ foreach(LANG_SOURCE_FILE IN LISTS LANG_SOURCE_FILES)
|
|||||||
|
|
||||||
add_custom_command(OUTPUT ${LANG_BINARY_FILE}
|
add_custom_command(OUTPUT ${LANG_BINARY_FILE}
|
||||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${LANG_BINARY_DIR}
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${LANG_BINARY_DIR}
|
||||||
COMMAND strgen
|
COMMAND hoststrgen
|
||||||
-s ${CMAKE_CURRENT_SOURCE_DIR}
|
-s ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
-d ${LANG_BINARY_DIR}
|
-d ${LANG_BINARY_DIR}
|
||||||
${LANG_SOURCE_FILE}
|
${LANG_SOURCE_FILE}
|
||||||
DEPENDS strgen
|
DEPENDS hoststrgen
|
||||||
MAIN_DEPENDENCY ${LANG_SOURCE_FILE}
|
MAIN_DEPENDENCY ${LANG_SOURCE_FILE}
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
COMMENT "Compiling language ${LANG_SOURCE_FILE_NAME_WE}"
|
COMMENT "Compiling language ${LANG_SOURCE_FILE_NAME_WE}"
|
||||||
@@ -96,10 +96,10 @@ set(TABLE_BINARY_DIR ${GENERATED_BINARY_DIR}/table)
|
|||||||
# Generate a command and target to create the strings table
|
# Generate a command and target to create the strings table
|
||||||
add_custom_command_timestamp(OUTPUT ${TABLE_BINARY_DIR}/strings.h
|
add_custom_command_timestamp(OUTPUT ${TABLE_BINARY_DIR}/strings.h
|
||||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${TABLE_BINARY_DIR}
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${TABLE_BINARY_DIR}
|
||||||
COMMAND strgen
|
COMMAND hoststrgen
|
||||||
-s ${CMAKE_CURRENT_SOURCE_DIR}
|
-s ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
-d ${TABLE_BINARY_DIR}
|
-d ${TABLE_BINARY_DIR}
|
||||||
DEPENDS strgen ${LANG_SOURCE_FILES}
|
DEPENDS hoststrgen ${LANG_SOURCE_FILES}
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
COMMENT "Generating table/strings.h"
|
COMMENT "Generating table/strings.h"
|
||||||
)
|
)
|
||||||
|
@@ -14,12 +14,12 @@ set(TABLE_INI_SOURCE_FILES
|
|||||||
# Generate a command and target to create the settings table
|
# Generate a command and target to create the settings table
|
||||||
add_custom_command_timestamp(OUTPUT ${TABLE_BINARY_DIR}/settings.h
|
add_custom_command_timestamp(OUTPUT ${TABLE_BINARY_DIR}/settings.h
|
||||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${TABLE_BINARY_DIR}
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${TABLE_BINARY_DIR}
|
||||||
COMMAND settingsgen
|
COMMAND hostsettingsgen
|
||||||
-o ${TABLE_BINARY_DIR}/settings.h
|
-o ${TABLE_BINARY_DIR}/settings.h
|
||||||
-b ${CMAKE_SOURCE_DIR}/src/table/settings.h.preamble
|
-b ${CMAKE_SOURCE_DIR}/src/table/settings.h.preamble
|
||||||
-a ${CMAKE_SOURCE_DIR}/src/table/settings.h.postamble
|
-a ${CMAKE_SOURCE_DIR}/src/table/settings.h.postamble
|
||||||
${TABLE_INI_SOURCE_FILES}
|
${TABLE_INI_SOURCE_FILES}
|
||||||
DEPENDS settingsgen ${TABLE_INI_SOURCE_FILES}
|
DEPENDS hostsettingsgen ${TABLE_INI_SOURCE_FILES}
|
||||||
${CMAKE_SOURCE_DIR}/src/table/settings.h.preamble
|
${CMAKE_SOURCE_DIR}/src/table/settings.h.preamble
|
||||||
${CMAKE_SOURCE_DIR}/src/table/settings.h.postamble
|
${CMAKE_SOURCE_DIR}/src/table/settings.h.postamble
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
Reference in New Issue
Block a user