Skip to content

Commit

Permalink
Merge pull request #39787 from jbytheway/cmake_object_library
Browse files Browse the repository at this point in the history
CMake tweaks to support build acceleration
  • Loading branch information
kevingranade authored Apr 22, 2020
2 parents 43af505 + 8e199b1 commit 7bdd0c7
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 51 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ option(LOCALIZE "Support for language localizations. Also enable UTF support
option(LANGUAGES "Compile localization files for specified languages." "")
option(DYNAMIC_LINKING "Use dynamic linking. Or use static to remove MinGW dependency instead." "ON")
option(JSON_FORMAT "Build JSON formatter" "OFF")
option(CATA_CCACHE "Try to find and build with ccache" "ON")
option(CATA_CLANG_TIDY_PLUGIN "Build Cata's custom clang-tidy plugin" "OFF")
set(CATA_CLANG_TIDY_INCLUDE_DIR "" CACHE STRING "Path to internal clang-tidy headers required for plugin (e.g. ClangTidy.h)")
set(CATA_CHECK_CLANG_TIDY "" CACHE STRING "Path to check_clang_tidy.py for plugin tests")
Expand Down Expand Up @@ -392,9 +393,9 @@ ADD_CUSTOM_TARGET(uninstall
)

find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
if(CCACHE_FOUND AND CATA_CCACHE)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif(CCACHE_FOUND)
endif()

# vim:noet
99 changes: 52 additions & 47 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
cmake_minimum_required(VERSION 3.1.4)

SET(MAIN_CPP ${CMAKE_SOURCE_DIR}/src/main.cpp)
SET(MESSAGES_CPP ${CMAKE_SOURCE_DIR}/src/messages.cpp)
SET(RESOURCE_RC ${CMAKE_SOURCE_DIR}/src/resource.rc)

FILE(GLOB CATACLYSM_DDA_SOURCES
${CMAKE_SOURCE_DIR}/src/*.cpp
)

LIST(REMOVE_ITEM CATACLYSM_DDA_SOURCES ${MAIN_CPP})
LIST(REMOVE_ITEM CATACLYSM_DDA_SOURCES ${MAIN_CPP} ${MESSAGES_CPP})

FILE(GLOB CATACLYSM_DDA_HEADERS
${CMAKE_SOURCE_DIR}/src/*.h
Expand All @@ -33,98 +34,100 @@ ADD_CUSTOM_COMMAND (

# Build tiles version if requested
IF(TILES)
add_library(libcataclysm-tiles STATIC
add_library(cataclysm-tiles-common OBJECT
${CATACLYSM_DDA_SOURCES}
${CATACLYSM_DDA_HEADERS}
)
target_include_directories(libcataclysm-tiles INTERFACE ${CMAKE_SOURCE_DIR}/src)
target_include_directories(cataclysm-tiles-common INTERFACE ${CMAKE_SOURCE_DIR}/src)

IF(WIN32)
ADD_DEFINITIONS(-DUSE_WINMAIN)
ADD_EXECUTABLE(cataclysm-tiles WIN32
${MAIN_CPP}
${MESSAGES_CPP}
${RESOURCE_RC}
)
ELSE(WIN32)
ADD_EXECUTABLE(cataclysm-tiles
${MAIN_CPP}
${MESSAGES_CPP}
)
ENDIF(WIN32)

ADD_DEPENDENCIES(libcataclysm-tiles get_version)
ADD_DEPENDENCIES(cataclysm-tiles-common get_version)

target_link_libraries(cataclysm-tiles libcataclysm-tiles)
target_compile_definitions(libcataclysm-tiles PUBLIC TILES )
target_link_libraries(cataclysm-tiles cataclysm-tiles-common)
target_compile_definitions(cataclysm-tiles-common PUBLIC TILES )

IF (LOCALIZE)
target_include_directories(libcataclysm-tiles PUBLIC
target_include_directories(cataclysm-tiles-common PUBLIC
${LIBINTL_INCLUDE_DIR}
${ICONV_INCLUDE_DIR}
)
target_link_libraries(libcataclysm-tiles
target_link_libraries(cataclysm-tiles-common
${LIBINTL_LIBRARIES}
${ICONV_LIBRARIES}
)
ENDIF (LOCALIZE)

IF(CMAKE_USE_PTHREADS_INIT)
target_compile_options(libcataclysm-tiles PUBLIC "-pthread")
target_compile_options(cataclysm-tiles-common PUBLIC "-pthread")
ENDIF(CMAKE_USE_PTHREADS_INIT)

IF(CMAKE_THREAD_LIBS_INIT)
target_link_libraries(libcataclysm-tiles ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(cataclysm-tiles-common ${CMAKE_THREAD_LIBS_INIT})
ENDIF(CMAKE_THREAD_LIBS_INIT)

IF (NOT DYNAMIC_LINKING)
# SDL, SDL_Image, SDL_ttf deps are required for static build
target_include_directories(libcataclysm-tiles PUBLIC
target_include_directories(cataclysm-tiles-common PUBLIC
${FREETYPE_INCLUDE_DIRS}
${PNG_INCLUDE_DIRS}
${JPEG_INCLUDE_DIR}
${ZLIB_INCLUDE_DIRS}
${BZIP2_INCLUDE_DIR}
)
target_link_libraries(libcataclysm-tiles
target_link_libraries(cataclysm-tiles-common
${FREETYPE_LIBRARIES}
${PNG_LIBRARIES}
${JPEG_LIBRARIES}
${ZLIB_LIBRARIES}
${BZIP2_LIBRARIES}
)
ENDIF (NOT DYNAMIC_LINKING)
target_include_directories(libcataclysm-tiles PUBLIC
target_include_directories(cataclysm-tiles-common PUBLIC
${SDL2_INCLUDE_DIR}
${SDL2_IMAGE_INCLUDE_DIRS}
${SDL2_TTF_INCLUDE_DIRS}
)
target_link_libraries(libcataclysm-tiles
target_link_libraries(cataclysm-tiles-common
${SDL2_LIBRARY}
${SDL2_IMAGE_LIBRARIES}
${SDL2_TTF_LIBRARIES}
)

IF(SOUND)
target_compile_definitions(libcataclysm-tiles PUBLIC SDL_SOUND )
target_include_directories(libcataclysm-tiles PUBLIC ${OGGVORBIS_INCLUDE_DIR})
target_link_libraries(libcataclysm-tiles ${OGG_LIBRARY})
target_link_libraries(libcataclysm-tiles ${VORBIS_LIBRARY})
target_link_libraries(libcataclysm-tiles ${VORBISFILE_LIBRARY})
target_include_directories(libcataclysm-tiles PUBLIC ${SDL2_MIXER_INCLUDE_DIRS})
target_link_libraries(libcataclysm-tiles ${SDL2_MIXER_LIBRARIES})
target_compile_definitions(cataclysm-tiles-common PUBLIC SDL_SOUND )
target_include_directories(cataclysm-tiles-common PUBLIC ${OGGVORBIS_INCLUDE_DIR})
target_link_libraries(cataclysm-tiles-common ${OGG_LIBRARY})
target_link_libraries(cataclysm-tiles-common ${VORBIS_LIBRARY})
target_link_libraries(cataclysm-tiles-common ${VORBISFILE_LIBRARY})
target_include_directories(cataclysm-tiles-common PUBLIC ${SDL2_MIXER_INCLUDE_DIRS})
target_link_libraries(cataclysm-tiles-common ${SDL2_MIXER_LIBRARIES})
ENDIF(SOUND)

IF(WIN32)
# Global settings for Windows targets (at end)
target_link_libraries(libcataclysm-tiles gdi32.lib)
target_link_libraries(libcataclysm-tiles winmm.lib)
target_link_libraries(libcataclysm-tiles imm32.lib)
target_link_libraries(libcataclysm-tiles ole32.lib)
target_link_libraries(libcataclysm-tiles oleaut32.lib)
target_link_libraries(libcataclysm-tiles version.lib)
target_link_libraries(cataclysm-tiles-common gdi32.lib)
target_link_libraries(cataclysm-tiles-common winmm.lib)
target_link_libraries(cataclysm-tiles-common imm32.lib)
target_link_libraries(cataclysm-tiles-common ole32.lib)
target_link_libraries(cataclysm-tiles-common oleaut32.lib)
target_link_libraries(cataclysm-tiles-common version.lib)
IF (BACKTRACE)
target_link_libraries(libcataclysm-tiles dbghelp.lib)
target_link_libraries(cataclysm-tiles-common dbghelp.lib)
IF(LIBBACKTRACE)
target_link_libraries(libcataclysm-tiles backtrace)
target_link_libraries(cataclysm-tiles-common backtrace)
ENDIF(LIBBACKTRACE)
ENDIF(BACKTRACE)
ENDIF(WIN32)
Expand All @@ -136,60 +139,62 @@ ENDIF(TILES)

# Build curses version if requested
IF(CURSES)
add_library(libcataclysm STATIC
add_library(cataclysm-common OBJECT
${CATACLYSM_DDA_SOURCES}
${CATACLYSM_DDA_HEADERS}
)
target_include_directories(libcataclysm INTERFACE ${CMAKE_SOURCE_DIR}/src)
target_include_directories(cataclysm-common INTERFACE ${CMAKE_SOURCE_DIR}/src)

IF(WIN32)
ADD_EXECUTABLE(cataclysm
${MAIN_CPP}
${MESSAGES_CPP}
${RESOURCE_RC}
)
ELSE(WIN32)
ADD_EXECUTABLE(cataclysm
${MAIN_CPP}
${MESSAGES_CPP}
)
ENDIF(WIN32)

ADD_DEPENDENCIES(libcataclysm get_version)
target_link_libraries(cataclysm libcataclysm)
ADD_DEPENDENCIES(cataclysm-common get_version)
target_link_libraries(cataclysm cataclysm-common)

IF (LOCALIZE)
target_include_directories(libcataclysm PUBLIC
target_include_directories(cataclysm-common PUBLIC
${LIBINTL_INCLUDE_DIR}
${ICONV_INCLUDE_DIR}
)
target_link_libraries(libcataclysm
target_link_libraries(cataclysm-common
${LIBINTL_LIBRARIES}
${ICONV_LIBRARIES}
)
ENDIF (LOCALIZE)

target_include_directories(libcataclysm PUBLIC ${CURSES_INCLUDE_DIR})
target_link_libraries(libcataclysm ${CURSES_LIBRARIES})
target_include_directories(cataclysm-common PUBLIC ${CURSES_INCLUDE_DIR})
target_link_libraries(cataclysm-common ${CURSES_LIBRARIES})

IF(CMAKE_USE_PTHREADS_INIT)
target_compile_options(libcataclysm PUBLIC "-pthread")
target_compile_options(cataclysm-common PUBLIC "-pthread")
ENDIF(CMAKE_USE_PTHREADS_INIT)

IF(CMAKE_THREAD_LIBS_INIT)
target_link_libraries(libcataclysm ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(cataclysm-common ${CMAKE_THREAD_LIBS_INIT})
ENDIF(CMAKE_THREAD_LIBS_INIT)

IF(WIN32)
# Global settings for Windows targets (at end)
target_link_libraries(libcataclysm gdi32.lib)
target_link_libraries(libcataclysm winmm.lib)
target_link_libraries(libcataclysm imm32.lib)
target_link_libraries(libcataclysm ole32.lib)
target_link_libraries(libcataclysm oleaut32.lib)
target_link_libraries(libcataclysm version.lib)
target_link_libraries(cataclysm-common gdi32.lib)
target_link_libraries(cataclysm-common winmm.lib)
target_link_libraries(cataclysm-common imm32.lib)
target_link_libraries(cataclysm-common ole32.lib)
target_link_libraries(cataclysm-common oleaut32.lib)
target_link_libraries(cataclysm-common version.lib)
IF (BACKTRACE)
target_link_libraries(libcataclysm dbghelp.lib)
target_link_libraries(cataclysm-common dbghelp.lib)
IF(LIBBACKTRACE)
target_link_libraries(libcataclysm backtrace)
target_link_libraries(cataclysm-common backtrace)
ENDIF(LIBBACKTRACE)
ENDIF(BACKTRACE)
ENDIF(WIN32)
Expand Down
4 changes: 2 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ IF(BUILD_TESTING)

IF(TILES)
add_executable(cata_test-tiles ${CATACLYSM_DDA_TEST_SOURCES})
target_link_libraries(cata_test-tiles libcataclysm-tiles)
target_link_libraries(cata_test-tiles cataclysm-tiles-common)
add_test(NAME test-tiles
COMMAND sh -c
"$<TARGET_FILE:cata_test-tiles> -r cata --rng-seed `shuf -i 0-1000000000 -n 1`"
Expand All @@ -14,7 +14,7 @@ IF(BUILD_TESTING)

IF(CURSES)
add_executable(cata_test ${CATACLYSM_DDA_TEST_SOURCES})
target_link_libraries(cata_test libcataclysm)
target_link_libraries(cata_test cataclysm-common)
add_test(NAME test
COMMAND sh -c
"$<TARGET_FILE:cata_test> -r cata --rng-seed `shuf -i 0-1000000000 -n 1`"
Expand Down

0 comments on commit 7bdd0c7

Please sign in to comment.