summaryrefslogtreecommitdiff
path: root/cmake/LinkPackage.cmake
diff options
context:
space:
mode:
authorCharles Pigott <charlespigott@googlemail.com>2020-09-25 22:41:34 +0100
committerCharles Pigott <charlespigott@googlemail.com>2020-10-03 16:17:11 +0100
commita0307652f37474cb0bba1143a644e8692b3b23f0 (patch)
tree98e43f1a6201e52993df5eb75af7a0a2abe83a33 /cmake/LinkPackage.cmake
parent53f36f4afae2210b508699c043992c17d54b8140 (diff)
downloadopenttd-a0307652f37474cb0bba1143a644e8692b3b23f0.tar.xz
Fix: Work around cmake bug by stripping link target strings
Diffstat (limited to 'cmake/LinkPackage.cmake')
-rw-r--r--cmake/LinkPackage.cmake5
1 files changed, 5 insertions, 0 deletions
diff --git a/cmake/LinkPackage.cmake b/cmake/LinkPackage.cmake
index 9977ecc45..0f62d3296 100644
--- a/cmake/LinkPackage.cmake
+++ b/cmake/LinkPackage.cmake
@@ -4,10 +4,15 @@ function(link_package NAME)
if(${NAME}_FOUND)
string(TOUPPER "${NAME}" UCNAME)
add_definitions(-DWITH_${UCNAME})
+ # Some libraries' cmake packages (looking at you, SDL2) leave trailing whitespace in the link commands,
+ # which (later) cmake considers to be an error. Work around this with by stripping the incoming string.
if(LP_TARGET AND TARGET ${LP_TARGET})
+ string(STRIP "${LP_TARGET}" LP_TARGET)
target_link_libraries(openttd ${LP_TARGET})
message(STATUS "${NAME} found -- -DWITH_${UCNAME} -- ${LP_TARGET}")
else()
+ string(STRIP "${${NAME}_LIBRARY}" ${NAME}_LIBRARY)
+ string(STRIP "${${NAME}_LIBRARIES}" ${NAME}_LIBRARIES)
include_directories(${${NAME}_INCLUDE_DIRS} ${${NAME}_INCLUDE_DIR})
target_link_libraries(openttd ${${NAME}_LIBRARIES} ${${NAME}_LIBRARY})
message(STATUS "${NAME} found -- -DWITH_${UCNAME} -- ${${NAME}_INCLUDE_DIRS} ${${NAME}_INCLUDE_DIR} -- ${${NAME}_LIBRARIES} ${${NAME}_LIBRARY}")