cmake: Use add_executable when not cross-compiling.

This commit is contained in:
orbea 2019-10-06 08:31:26 -07:00 committed by Rafael Kitover
parent 61520df789
commit abff89e4fb
2 changed files with 24 additions and 33 deletions

View File

@ -1,10 +1,9 @@
function(host_compile src dst_cmd)
if(CMAKE_CROSSCOMPILING)
unset(link_flags)
if(CMAKE_HOST_WIN32)
if(NOT dst MATCHES "\\.[Ee][Xx][Ee]\$")
set(dst "${dst_cmd}.exe")
endif()
if(CMAKE_COMPILER_IS_GNUCXX)
set(link_flags -Wl,--subsystem,console)
@ -13,17 +12,14 @@ function(host_compile src dst_cmd)
set(dst "${dst_cmd}")
endif()
if(NOT MSVC)
# assume cc foo.c -o foo # will work on most hosts
set(compile_command cc ${src} -o ${dst} ${link_flags})
else()
# special case for Visual Studio
set(compile_command ${CMAKE_C_COMPILER} ${src} /link "/out:${dst}")
endif()
add_custom_command(
OUTPUT "${dst}"
COMMAND ${compile_command}
COMMAND cc ${src} -o ${dst} ${link_flags}
DEPENDS "${src}"
)
else()
get_filename_component(dst "${dst_cmd}" NAME)
add_executable("${dst}" "${src}")
endif()
endfunction()

View File

@ -524,19 +524,14 @@ set(XRC_SOURCES
# wxrc does not support xrs files in -c output (> 10x compression)
# we do it using the bin2c.c utility
if(CMAKE_CROSSCOMPILING)
set(BIN2C ${CMAKE_BINARY_DIR}/bin2c)
else()
set(BIN2C bin2c)
endif()
if(NOT MSVC)
include(HostCompile)
host_compile(${CMAKE_CURRENT_SOURCE_DIR}/bin2c.c ${BIN2C})
set(BIN2C_DEP ${BIN2C})
else()
# on the appveyor visual studio environment, cl.exe cannot be run from
# cmake
add_executable(bin2c ${CMAKE_CURRENT_SOURCE_DIR}/bin2c.c)
set(BIN2C bin2c)
set(BIN2C_DEP bin2c)
endif()
if(WXRC)
separate_arguments(WXRC UNIX_COMMAND ${WXRC})
@ -613,14 +608,14 @@ add_custom_command(
add_custom_command(
OUTPUT builtin-xrc.h
COMMAND ${BIN2C} wxvbam.xrs builtin-xrc.h builtin_xrs
DEPENDS wxvbam.xrs ${BIN2C_DEP}
DEPENDS wxvbam.xrs ${BIN2C}
)
# use a built-in vba-over.ini if no config file present
add_custom_command(
OUTPUT builtin-over.h
COMMAND ${BIN2C} ${CMAKE_CURRENT_SOURCE_DIR}/../vba-over.ini builtin-over.h builtin_over
DEPENDS ../vba-over.ini ${BIN2C_DEP}
DEPENDS ../vba-over.ini ${BIN2C}
)
# I don't like duplicating/triplicating code, so I only declare