Fix #9735: Fix OrderBackup::Reset in non-GUI case
[openttd-github.git] / cmake / LinkPackage.cmake
blob0f62d3296c5251195230d516b69ae6cf9bbfc967
1 function(link_package NAME)
2     cmake_parse_arguments(LP "ENCOURAGED" "TARGET" "" ${ARGN})
4     if(${NAME}_FOUND)
5         string(TOUPPER "${NAME}" UCNAME)
6         add_definitions(-DWITH_${UCNAME})
7         # Some libraries' cmake packages (looking at you, SDL2) leave trailing whitespace in the link commands,
8         # which (later) cmake considers to be an error. Work around this with by stripping the incoming string.
9         if(LP_TARGET AND TARGET ${LP_TARGET})
10             string(STRIP "${LP_TARGET}" LP_TARGET)
11             target_link_libraries(openttd ${LP_TARGET})
12             message(STATUS "${NAME} found -- -DWITH_${UCNAME} -- ${LP_TARGET}")
13         else()
14             string(STRIP "${${NAME}_LIBRARY}" ${NAME}_LIBRARY)
15             string(STRIP "${${NAME}_LIBRARIES}" ${NAME}_LIBRARIES)
16             include_directories(${${NAME}_INCLUDE_DIRS} ${${NAME}_INCLUDE_DIR})
17             target_link_libraries(openttd ${${NAME}_LIBRARIES} ${${NAME}_LIBRARY})
18             message(STATUS "${NAME} found -- -DWITH_${UCNAME} -- ${${NAME}_INCLUDE_DIRS} ${${NAME}_INCLUDE_DIR} -- ${${NAME}_LIBRARIES} ${${NAME}_LIBRARY}")
19         endif()
20     elseif(LP_ENCOURAGED)
21         message(WARNING "${NAME} not found; compiling OpenTTD without ${NAME} is strongly disencouraged")
22     endif()
23 endfunction()