1 function(link_package NAME)
2 cmake_parse_arguments(LP "ENCOURAGED" "TARGET" "" ${ARGN})
5 string(TOUPPER "${NAME}" UCNAME)
6 # Some libraries have a dash, which is not allowed in a preprocessor macro.
7 string(REPLACE "-" "_" UCNAME "${UCNAME}")
9 add_definitions(-DWITH_${UCNAME})
10 # Some libraries' cmake packages (looking at you, SDL2) leave trailing whitespace in the link commands,
11 # which (later) cmake considers to be an error. Work around this with by stripping the incoming string.
12 if(LP_TARGET AND TARGET ${LP_TARGET})
13 string(STRIP "${LP_TARGET}" LP_TARGET)
14 target_link_libraries(openttd_lib ${LP_TARGET})
15 message(STATUS "${NAME} found -- -DWITH_${UCNAME} -- ${LP_TARGET}")
17 string(STRIP "${${NAME}_LIBRARY}" ${NAME}_LIBRARY)
18 string(STRIP "${${NAME}_LIBRARIES}" ${NAME}_LIBRARIES)
19 include_directories(${${NAME}_INCLUDE_DIRS} ${${NAME}_INCLUDE_DIR})
20 target_link_libraries(openttd_lib ${${NAME}_LIBRARIES} ${${NAME}_LIBRARY})
21 message(STATUS "${NAME} found -- -DWITH_${UCNAME} -- ${${NAME}_INCLUDE_DIRS} ${${NAME}_INCLUDE_DIR} -- ${${NAME}_LIBRARIES} ${${NAME}_LIBRARY}")
24 message(WARNING "${NAME} not found; compiling OpenTTD without ${NAME} is strongly discouraged")