summaryrefslogtreecommitdiff
path: root/cmake/LinkPackage.cmake
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2019-04-07 11:57:55 +0200
committerglx22 <glx22@users.noreply.github.com>2020-06-05 19:36:05 +0200
commit56d54cf60eb5814f77dfcce91cf12879f01e1d1b (patch)
treee35fc5b7becc8f993d8c44179bc16e2586c3c64d /cmake/LinkPackage.cmake
parent85315e2e3132dd7aff9ee96c1ba8d282350d9d5e (diff)
downloadopenttd-56d54cf60eb5814f77dfcce91cf12879f01e1d1b.tar.xz
Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC, Clang, and many more. It allows for a single way of doing things, so no longer we need shell scripts and vbs scripts to work on all our supported platforms. Additionally, CMake allows to generate project files for like MSVC, KDevelop, etc. This heavily reduces the lines of code we need to support multiple platforms from a project perspective. Addtiionally, this heavily improves our detection of libraries, etc.
Diffstat (limited to 'cmake/LinkPackage.cmake')
-rw-r--r--cmake/LinkPackage.cmake18
1 files changed, 18 insertions, 0 deletions
diff --git a/cmake/LinkPackage.cmake b/cmake/LinkPackage.cmake
new file mode 100644
index 000000000..f64ccfd51
--- /dev/null
+++ b/cmake/LinkPackage.cmake
@@ -0,0 +1,18 @@
+function(link_package NAME)
+ cmake_parse_arguments(LP "ENCOURAGED" "TARGET" "" ${ARGN})
+
+ if (${NAME}_FOUND)
+ string(TOUPPER "${NAME}" UCNAME)
+ add_definitions(-DWITH_${UCNAME})
+ if (LP_TARGET AND TARGET ${LP_TARGET})
+ target_link_libraries(openttd ${LP_TARGET})
+ message(STATUS "${NAME} found -- -DWITH_${UCNAME} -- ${LP_TARGET}")
+ else()
+ 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}")
+ endif()
+ elseif (LP_ENCOURAGED)
+ message(WARNING "${NAME} not found; compiling OpenTTD without ${NAME} is strongly disencouraged")
+ endif()
+endfunction()