Add: [NewGRF] Vehicle prop that allows refittability based on cargo class intersection.
[openttd-github.git] / cmake / LinkPackage.cmake
blob9fb2cf5910327fea01485903cb04170f04aa60f0
1 function(link_package NAME)
2     cmake_parse_arguments(LP "ENCOURAGED" "TARGET" "" ${ARGN})
4     if(${NAME}_FOUND)
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}")
16         else()
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}")
22         endif()
23     elseif(LP_ENCOURAGED)
24         message(WARNING "${NAME} not found; compiling OpenTTD without ${NAME} is strongly discouraged")
25     endif()
26 endfunction()