2017-09-17 02:47:39 +00:00
|
|
|
function(host_compile src dst_cmd)
|
2019-10-06 15:31:26 +00:00
|
|
|
if(CMAKE_CROSSCOMPILING)
|
|
|
|
unset(link_flags)
|
2022-12-30 02:30:08 +00:00
|
|
|
set(dst "${dst_cmd}")
|
2017-09-17 02:47:39 +00:00
|
|
|
|
2019-10-06 15:31:26 +00:00
|
|
|
if(CMAKE_HOST_WIN32)
|
|
|
|
if(CMAKE_COMPILER_IS_GNUCXX)
|
|
|
|
set(link_flags -Wl,--subsystem,console)
|
|
|
|
endif()
|
2022-12-30 02:30:08 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(MSVC)
|
|
|
|
set(msvc_compile_script ${CMAKE_SOURCE_DIR}/cmake/MSVC_x86_Host_Compile.cmake)
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${dst}
|
|
|
|
DEPENDS ${src} ${msvc_compile_script}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -D "src=${src}" -D "dst=${dst}" -P ${msvc_compile_script}
|
|
|
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
|
|
|
)
|
2019-10-06 15:31:26 +00:00
|
|
|
else()
|
2019-10-17 21:53:15 +00:00
|
|
|
set(dst ${dst_cmd})
|
2017-09-17 02:47:39 +00:00
|
|
|
|
2022-12-30 02:30:08 +00:00
|
|
|
# Assume: cc foo.c -o foo # will work on most hosts
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${dst}
|
|
|
|
DEPENDS ${src}
|
|
|
|
COMMAND cc ${src} -o ${dst} ${link_flags}
|
|
|
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
|
|
|
)
|
|
|
|
endif()
|
2017-09-17 02:47:39 +00:00
|
|
|
else()
|
2019-10-17 21:53:15 +00:00
|
|
|
get_filename_component(dst ${dst_cmd} NAME)
|
|
|
|
|
|
|
|
add_executable(${dst} ${src})
|
|
|
|
|
|
|
|
# this is necessary because we override main with SDL_main
|
|
|
|
target_compile_definitions(${dst} PRIVATE -Dmain=main)
|
2017-09-17 02:47:39 +00:00
|
|
|
endif()
|
|
|
|
endfunction()
|