Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ufo_find to reduce code duplication in the cmake find modules #27

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 60 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,24 @@ set(UFOAI_PROJECT_UFORADIANT "uforadiant")
set(UFOAI_PROJECT_UFOTESTALL "ufotestall")

# cmake paths
set(ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE STRING "Root dir")
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${ROOT_DIR})
set(CMAKE_CONFIG_DIR "${CMAKE_SOURCE_DIR}/cmake/config")
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
${CMAKE_SOURCE_DIR}/cmake/modules
)

if (NOT CMAKE_TOOLCHAIN_FILE)
if (WIN32)
include(${ROOT_DIR}/cmake/toolchains/windows-toolchain.cmake)
elseif (APPLE)
include(${ROOT_DIR}/cmake/toolchains/darwin-toolchain.cmake)
else()
include(${ROOT_DIR}/cmake/toolchains/linux-toolchain.cmake)
endif()
endif()

if(NOT CMAKE_BUILD_TYPE)
message(STATUS "CMake build type is not set, defaulting to 'RelWithDebInfo'")
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
Expand All @@ -27,6 +39,7 @@ endif()
set(UFOAI_SRC "${CMAKE_SOURCE_DIR}/src")

# For some reason, when building against win xp, WINVER and _WIN32_WINNT needs to be defined
# TODO: should go into toolchain file
if(WIN32 AND CMAKE_SYSTEM_VERSION)
set(win_ver ${CMAKE_SYSTEM_VERSION})
string(REPLACE "." "" win_ver ${win_ver})
Expand All @@ -41,6 +54,7 @@ endif()

# MSVC2013 conflicts std::min/std::max by including minwindef.h. To avoid that, we can define NOMINMAX
if(WIN32 AND MSVC)
# TODO: should go into toolchain file
add_definitions(-DNOMINMAX)
endif()

Expand Down Expand Up @@ -104,10 +118,12 @@ message(STATUS "Search path dependencies: ${UFOAI_DEP_SEARCH_PATH}")
set(CMAKE_PREFIX_PATH ${UFOAI_DEP_SEARCH_PATH} ${CMAKE_PREFIX_PATH})

## Packages
find_package(OpenGL)

if(UFOAI_BUILD_UFODED OR
UFOAI_BUILD_UFO OR
UFOAI_BUILD_UFOTESTALL)
find_package(CURL)
find_package(curl)
endif()

if(UFOAI_BUILD_UFORADIANT)
Expand All @@ -119,17 +135,17 @@ if(UFOAI_BUILD_UFO2MAP OR
UFOAI_BUILD_UFOMODEL OR
UFOAI_BUILD_UFOSLICER OR
UFOAI_BUILD_UFOTESTALL)
find_package(JPEG)
find_package(jpeg)
endif()

if(UFOAI_BUILD_UFO)
find_package(LibIntl)
find_package(intl)
endif()

if(UFOAI_BUILD_UFO OR
UFOAI_BUILD_UFORADIANT OR
UFOAI_BUILD_UFOTESTALL)
find_package(OGG)
find_package(ogg)
endif()

if(UFOAI_BUILD_UFORADIANT)
Expand All @@ -141,7 +157,7 @@ if(UFOAI_BUILD_UFO2MAP OR
UFOAI_BUILD_UFOMODEL OR
UFOAI_BUILD_UFOSLICER OR
UFOAI_BUILD_UFOTESTALL)
find_package(PNG)
find_package(png)
endif()

if(UFOAI_BUILD_GAME OR
Expand All @@ -168,7 +184,8 @@ endif()
if(UFOAI_BUILD_UFO OR
UFOAI_BUILD_UFORADIANT OR
UFOAI_BUILD_UFOTESTALL)
find_package(VORBIS)
find_package(vorbis)
find_package(vorbisfile)
endif()

if(UFOAI_BUILD_UFO2MAP OR
Expand All @@ -178,7 +195,7 @@ if(UFOAI_BUILD_UFO2MAP OR
UFOAI_BUILD_UFOSLICER OR
UFOAI_BUILD_UFORADIANT OR
UFOAI_BUILD_UFOTESTALL)
find_package(ZLIB)
find_package(zlib)
endif()

###############################################################################
Expand Down Expand Up @@ -224,6 +241,7 @@ if(UFOAI_BUILD_GAME)
${UFOAI_SRC}/game/inventory.cpp
${UFOAI_SRC}/game/q_shared.cpp

# TODO: support system wide lua installation
${UFOAI_SRC}/libs/lua/lapi.c
${UFOAI_SRC}/libs/lua/lauxlib.c
${UFOAI_SRC}/libs/lua/lbaselib.c
Expand Down Expand Up @@ -379,6 +397,7 @@ if(UFOAI_BUILD_UFO2MAP)
PRIVATE ${ZLIB_INCLUDE_DIRS}
)

# TODO: should be part of the toolchain file
if(MINGW)
target_link_libraries(${UFOAI_PROJECT_UFO2MAP}
mingw32
Expand All @@ -393,6 +412,7 @@ if(UFOAI_BUILD_UFO2MAP)
${ZLIB_LIBRARIES}
)

# TODO: should be part of the toolchain file
if(WIN32)
target_link_libraries(${UFOAI_PROJECT_UFO2MAP}
imm32
Expand Down Expand Up @@ -508,6 +528,7 @@ if(UFOAI_BUILD_UFODED)
endforeach(OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES)

# since we embed our manifest, we should not generate a default one
# TODO: should be part of the ufo_add_executable macro
if(WIN32 AND MSVC)
set_target_properties(${UFOAI_PROJECT_UFODED} PROPERTIES LINK_FLAGS "/MANIFEST:NO")
endif()
Expand All @@ -530,6 +551,7 @@ if(UFOAI_BUILD_UFODED)
${ZLIB_LIBRARIES}
)

# TODO: should be part of the toolchain file
if(WIN32)
target_link_libraries(${UFOAI_PROJECT_UFODED}
imm32
Expand Down Expand Up @@ -871,6 +893,7 @@ if(UFOAI_BUILD_UFO)
${UFOAI_SRC}/shared/stringhunk.cpp
${UFOAI_SRC}/shared/utf8.cpp

# TODO: support system wide lua
${UFOAI_SRC}/libs/lua/lapi.c
${UFOAI_SRC}/libs/lua/lauxlib.c
${UFOAI_SRC}/libs/lua/lbaselib.c
Expand Down Expand Up @@ -963,6 +986,7 @@ if(UFOAI_BUILD_UFO)
endforeach(OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES)

# since we embed our manifest, we should not generate a default one
# TODO: should be part of the ufo_add_executable macro
if(WIN32 AND MSVC)
set_target_properties(${UFOAI_PROJECT_UFO} PROPERTIES LINK_FLAGS "/MANIFEST:NO")
endif()
Expand All @@ -982,10 +1006,11 @@ if(UFOAI_BUILD_UFO)
PRIVATE ${SDLTTF_INCLUDE_DIR}
PRIVATE ${CURL_INCLUDE_DIR}
PRIVATE ${VORBIS_INCLUDE_DIR}
PRIVATE ${VORBISFILE_INCLUDE_DIR}
PRIVATE ${OGG_INCLUDE_DIR}
PRIVATE ${JPEG_INCLUDE_DIR}
PRIVATE ${PNG_INCLUDE_DIRS}
PRIVATE ${LIBINTL_INCLUDE_DIR}
PRIVATE ${INTL_INCLUDE_DIR}
PRIVATE ${ZLIB_INCLUDE_DIRS}
)

Expand All @@ -1002,31 +1027,33 @@ if(UFOAI_BUILD_UFO)
${SDL_TTF_LIBRARIES}
${CURL_LIBRARIES}
${VORBIS_LIBRARY}
${VORBISFILE_LIBRARY}
${OGG_LIBRARIES}
${JPEG_LIBRARIES}
${PNG_LIBRARIES}
${ZLIB_LIBRARIES}
)

# TODO: should be part of the toolchain file
if(WIN32 AND MSVC)
target_link_libraries(${UFOAI_PROJECT_UFO}
opengl32
${LIBINTL_LIBRARIES}
${OPENGL_LIBRARIES}
${INTL_LIBRARIES}
winmm
Ws2_32
)
elseif(WIN32)
target_link_libraries(${UFOAI_PROJECT_UFO}
opengl32
${OPENGL_LIBRARIES}
imm32
${LIBINTL_LIBRARIES}
${INTL_LIBRARIES}
version
winmm
Ws2_32
)
elseif(UNIX)
target_link_libraries(${UFOAI_PROJECT_UFO}
GL
${OPENGL_LIBRARIES}
rt
)
endif()
Expand Down Expand Up @@ -1108,6 +1135,7 @@ if(UFOAI_BUILD_UFOMODEL)
PRIVATE ${ZLIB_INCLUDE_DIRS}
)

# TODO: should be part of the toolchain file
if(MINGW)
target_link_libraries(${UFOAI_PROJECT_UFOMODEL}
mingw32
Expand All @@ -1122,6 +1150,7 @@ if(UFOAI_BUILD_UFOMODEL)
${ZLIB_LIBRARIES}
)

# TODO: should be part of the toolchain file
if(WIN32)
target_link_libraries(${UFOAI_PROJECT_UFOMODEL}
imm32
Expand Down Expand Up @@ -1202,6 +1231,7 @@ if(UFOAI_BUILD_UFOSLICER)
PRIVATE ${ZLIB_INCLUDE_DIRS}
)

# TODO: should be part of the toolchain file
if(MINGW)
target_link_libraries(${UFOAI_PROJECT_UFOSLICER}
mingw32
Expand All @@ -1216,6 +1246,7 @@ if(UFOAI_BUILD_UFOSLICER)
${ZLIB_LIBRARIES}
)

# TODO: should be part of the toolchain file
if(WIN32)
target_link_libraries(${UFOAI_PROJECT_UFOSLICER}
imm32
Expand Down Expand Up @@ -1525,6 +1556,7 @@ if(UFOAI_BUILD_UFORADIANT)
${UFOAI_SRC}/tools/radiant/radiant/xyview/XYWnd.cpp
${UFOAI_SRC}/tools/radiant/radiant/xyview/grid/Grid.cpp

# TODO support system wide picomodel
${UFOAI_SRC}/libs/picomodel/picointernal.c
${UFOAI_SRC}/libs/picomodel/picomodel.c
${UFOAI_SRC}/libs/picomodel/picomodules.c
Expand Down Expand Up @@ -1563,14 +1595,16 @@ if(UFOAI_BUILD_UFORADIANT)
PRIVATE ${GTK_INCLUDE_DIRS}
PRIVATE ${OPENAL_INCLUDE_DIR}
PRIVATE ${VORBIS_INCLUDE_DIR}
PRIVATE ${VORBISFILE_INCLUDE_DIR}
PRIVATE ${OGG_INCLUDE_DIR}
PRIVATE ${LIBINTL_INCLUDE_DIR}
PRIVATE ${INTL_INCLUDE_DIR}
PRIVATE ${ZLIB_INCLUDE_DIRS}
)

target_link_libraries(${UFOAI_PROJECT_UFORADIANT}
${GTK_LIBRARIES}
${VORBIS_LIBRARY_FILE}
${VORBISFILE_LIBRARY_FILE}
${VORBIS_LIBRARY}
${OGG_LIBRARIES}
${OPENAL_LIBRARIES}
Expand All @@ -1579,17 +1613,18 @@ if(UFOAI_BUILD_UFORADIANT)
${ZLIB_LIBRARIES}
)

# TODO: should be part of the toolchain file
if(WIN32)
target_link_libraries(${UFOAI_PROJECT_UFORADIANT}
opengl32
${OPENGL_LIBRARIES}
imm32
${LIBINTL_LIBRARIES}
${INTL_LIBRARIES}
version
winmm
)
elseif(UNIX)
target_link_libraries(${UFOAI_PROJECT_UFORADIANT}
GL
${OPENGL_LIBRARIES}
X11
dl
rt
Expand Down Expand Up @@ -2072,13 +2107,15 @@ if(UFOAI_BUILD_UFOTESTALL)
PRIVATE ${SDLTTF_INCLUDE_DIR}
PRIVATE ${CURL_INCLUDE_DIR}
PRIVATE ${VORBIS_INCLUDE_DIR}
PRIVATE ${VORBISFILE_INCLUDE_DIR}
PRIVATE ${OGG_INCLUDE_DIR}
PRIVATE ${JPEG_INCLUDE_DIR}
PRIVATE ${PNG_INCLUDE_DIRS}
PRIVATE ${LIBINTL_INCLUDE_DIR}
PRIVATE ${INTL_INCLUDE_DIR}
PRIVATE ${ZLIB_INCLUDE_DIRS}
)

# TODO: should be part of the toolchain file
if(MINGW)
target_link_libraries(${UFOAI_PROJECT_UFOTESTALL}
mingw32
Expand All @@ -2092,24 +2129,26 @@ if(UFOAI_BUILD_UFOTESTALL)
${SDL_TTF_LIBRARIES}
${CURL_LIBRARIES}
${VORBIS_LIBRARY}
${VORBISFILE_LIBRARY}
${OGG_LIBRARIES}
${JPEG_LIBRARIES}
${PNG_LIBRARIES}
${ZLIB_LIBRARIES}
)

# TODO: should be part of the toolchain file
if(WIN32)
target_link_libraries(${UFOAI_PROJECT_UFOTESTALL}
opengl32
${OPENGL_LIBRARIES}
imm32
${LIBINTL_LIBRARIES}
${INTL_LIBRARIES}
version
winmm
Ws2_32
)
elseif(UNIX)
target_link_libraries(${UFOAI_PROJECT_UFOTESTALL}
GL
${OPENGL_LIBRARIES}
rt
)
endif()
Expand Down
11 changes: 9 additions & 2 deletions cmake/macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ endmacro()
# Example: ufo_find(SDL2_image SDL_image.h include/SDL2)
#
macro(ufo_find LIB HEADER SUFFIX)
string(TOUPPER ${LIB} PREFIX_)
STRING(REGEX REPLACE "^LIB" "" PREFIX ${PREFIX_})
message(STATUS "Checking for ${PREFIX} (${LIB})")
if (NOT USE_BUILTIN)
string(TOUPPER ${LIB} PREFIX)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_PROCESSOR_ARCH "x64")
else()
Expand All @@ -99,7 +101,6 @@ macro(ufo_find LIB HEADER SUFFIX)
set(PKG_PREFIX _${PREFIX})
endif()
if (PKG_CONFIG_FOUND)
message(STATUS "Checking for ${LIB}")
pkg_check_modules(_${PREFIX} ${LIB})
if (_${PREFIX}_FOUND)
set(${PREFIX}_COMPILERFLAGS ${${PKG_PREFIX}_CFLAGS_OTHER})
Expand Down Expand Up @@ -137,6 +138,12 @@ macro(ufo_find LIB HEADER SUFFIX)
ufo_var_global(${PREFIX}_LIBRARIES)
ufo_var_global(${PREFIX}_FOUND)
endif()
if (${PREFIX}_FOUND)
message(STATUS "LIBS: ${${PREFIX}_LIBRARIES}")
message(STATUS "INCLUDE_DIRS: ${${PREFIX}_INCLUDE_DIRS}")
else()
message(STATUS "${LIB} not found")
endif()
endif()
endmacro()

Expand Down
Loading