LINK_FLAGS order in CMake link step

OS: Ubuntu 18.04

Version: 3.10.2

Other relevant info:

cmake_minimum_required (VERSION 3.4)

I have the following target

add_custom_target(fpga_emu DEPENDS ${EMULATOR_TARGET})
add_dependencies(${EMULATOR_TARGET} create_library_archive)
set_target_properties(${EMULATOR_TARGET} PROPERTIES LINK_FLAGS "-fintelfpga ${LIBRARY_ARCHIVE}")

CMake’s generated link command: dpcpp -fintelfpga lib.a CMakeFiles/use_library.fpga_emu.dir/use_library.cpp.o -o ../use_library.fpga_emu

I was told this is the wrong order on Linux, since the GNU linker is only “forward looking”. Is there a way to get the link flags to appear after the object file, something like this?

dpcpp CMakeFiles/use_library.fpga_emu.dir/use_library.cpp.o -fintelfpga lib.a -o ../use_library.fpga_emu

Thanks team!

I don’t think CMake offers such fine-grained control over the link line.

Cc: @brad.king

target_link_libraries supports passing flags in addition to libraries. Although target_link_options should be preferred for most flags, target_link_libraries is appropriate for flags meant to add toolchain-provided libraries.

Awesome, that worked, thanks Brad!