Add target_link_libraries() for sublibraries

With this change we remove some internal variables/lists like sys_libs,
libs3rdparty, etc. And we fix dependencies problems between targets.
This commit is contained in:
David Capello 2015-07-13 12:16:55 -03:00
parent 420b38e426
commit 55f90d8b8b
15 changed files with 231 additions and 211 deletions

View File

@ -142,24 +142,108 @@ if(NOT USE_SHARED_CURL)
set(CURL_STATICLIB ON BOOL)
endif()
if(NOT USE_SHARED_ZLIB)
# zlib
if(USE_SHARED_ZLIB)
find_package(ZLIB)
if(NOT ZLIB_FOUND)
message(FATAL_ERROR "zlib not found")
endif()
else()
set(ZLIB_LIBRARIES zlib)
set(ZLIB_INCLUDE_DIR ${ZLIB_DIR})
# Zlib generated zconf.h file
include_directories(${CMAKE_BINARY_DIR}/third_party/zlib)
endif()
include_directories(${ZLIB_INCLUDE_DIR})
# libpng
if(USE_SHARED_LIBPNG)
find_package(PNG)
if(NOT PNG_FOUND)
message(FATAL_ERROR "libpng not found")
endif()
add_definitions(${PNG_DEFINITIONS})
include_directories(${PNG_INCLUDE_DIR})
else()
include_directories(${LIBPNG_DIR})
set(PNG_LIBRARIES libpng)
set(PNG_INCLUDE_DIR ${LIBPNG_DIR})
endif()
include_directories(${PNG_INCLUDE_DIR})
add_definitions(-DPNG_NO_MMX_CODE) # Do not use MMX optimizations in PNG code
# tinyxml
if(USE_SHARED_TINYXML)
find_library(TINYXML_LIBRARY NAMES tinyxml)
find_path(TINYXML_INCLUDE_DIR NAMES tinyxml.h)
else()
set(TINYXML_LIBRARY tinyxml)
set(TINYXML_INCLUDE_DIR ${TINYXML_DIR})
endif()
include_directories(${TINYXML_INCLUDE_DIR})
# pixman
if(USE_SHARED_PIXMAN)
find_library(PIXMAN_LIBRARY NAMES pixman pixman-1)
find_path(PIXMAN_INCLUDE_DIR NAMES pixman.h PATH_SUFFIXES pixman-1)
else()
set(PIXMAN_LIBRARY pixman)
set(PIXMAN_INCLUDE_DIR ${PIXMAN_DIR}/pixman)
# For pixman-version.h
include_directories(${CMAKE_BINARY_DIR})
endif()
include_directories(${PIXMAN_INCLUDE_DIR})
if(USE_SHARED_GIFLIB)
find_package(GIF REQUIRED)
if(NOT GIF_FOUND)
message(FATAL_ERROR "giflib not found")
endif()
else()
set(GIF_LIBRARIES giflib)
set(GIF_INCLUDE_DIR ${GIFLIB_DIR}/lib)
endif()
include_directories(${GIF_INCLUDE_DIR})
if(USE_SHARED_JPEGLIB)
find_package(JPEG)
if(NOT JPEG_FOUND)
message(FATAL_ERROR "jpeg not found")
endif()
else()
set(JPEG_LIBRARIES jpeg)
set(JPEG_INCLUDE_DIR ${LIBJPEG_DIR})
endif()
include_directories(${JPEG_INCLUDE_DIR})
if(USE_ALLEG4_BACKEND)
if(USE_SHARED_LIBLOADPNG)
find_library(LOADPNG_LIBRARY NAMES loadpng)
find_path(LOADPNG_INCLUDE_DIR NAMES loadpng.h)
else()
set(LOADPNG_LIBRARY loadpng)
set(LOADPNG_INCLUDE_DIR ${LOADPNG_DIR})
endif()
include_directories(${LOADPNG_INCLUDE_DIR})
endif()
# Do not use MMX optimizations in PNG code
add_definitions(-DPNG_NO_MMX_CODE)
if(USE_SHARED_CURL)
find_library(LIBCURL_LIBRARY NAMES curl)
find_path(LIBCURL_INCLUDE_DIR NAMES curl/curl.h)
else()
set(LIBCURL_LIBRARY libcurl)
set(LIBCURL_INCLUDE_DIR ${CURL_DIR}/include)
endif()
include_directories(${LIBCURL_INCLUDE_DIR})
# mongoose
if(ENABLE_WEBSERVER)
set(MONGOOSE_LIBRARY mongoose)
include_directories(${MONGOOSE_DIR})
add_definitions(-DENABLE_WEBSERVER)
endif()
# simpleini
set(SIMPLEINI_LIBRARY simpleini)
include_directories(${SIMPLEINI_DIR})
######################################################################
# Allegro 4 backend
@ -190,6 +274,8 @@ if(USE_ALLEG4_BACKEND)
# Static Allegro (the code of Allegro library is embedded).
add_definitions(-DALLEGRO_STATICLINK)
set(LIBALLEGRO4_LINK_FLAGS allegro)
endif()
endif()
@ -246,33 +332,15 @@ endif()
# -- Windows --
if(WIN32)
if(USE_ALLEG4_BACKEND)
find_package(DXGuid)
if(NOT DXGUID_FOUND)
if(MSVC)
message(FATAL_ERROR "DirectX required for Windows port. You might need to add DirectX include and lib directories to your INCLUDE and LIB environment variables.")
else()
message(FATAL_ERROR "DirectX required for Windows port.")
endif()
endif()
include_directories(SYSTEM ${DXGUID_INCLUDE_DIR})
else()
set(DXGUID_LIBRARIES)
endif()
list(APPEND PLATFORM_LIBS
kernel32 user32 gdi32 comdlg32 ole32 winmm
shlwapi psapi wininet comctl32 dbghelp
${DXGUID_LIBRARIES})
shlwapi psapi wininet comctl32 dbghelp)
# Windows XP is the minimum supported platform.
add_definitions(-D_WIN32_WINNT=0x0501 -DWINVER=0x0501)
# We need Unicode support
add_definitions(-DUNICODE -D_UNICODE)
endif(WIN32)
# -- Mac OS X --

View File

@ -37,124 +37,14 @@ else()
set(updater_lib)
endif()
# Aseprite libraries
#
# TODO These libraries are in a specific order to avoid linking errors
# on Unix-like platforms. We could avoid this specific order if for
# each library we specify its dependencies using target_link_libraries()
#
set(aseprite_libraries
app-lib
fixmath-lib
cfg-lib
css-lib
doc-lib
render-lib
scripting-lib
undo-lib
filters-lib
ui-lib
she
gfx-lib
${updater_lib}
net-lib
base-lib)
# Directories where .h files can be found
include_directories(. .. ../third_party)
######################################################################
# Allegro 4 backend
if(USE_ALLEG4_BACKEND)
if(NOT USE_SHARED_ALLEGRO4)
# Use patched version of Allegro 4 (with window resize support).
add_subdirectory(allegro)
set(libs3rdparty ${libs3rdparty} allegro)
endif()
# Use patched version of Allegro 4 (with window resize support).
if(USE_ALLEG4_BACKEND AND NOT USE_SHARED_ALLEGRO4)
add_subdirectory(allegro)
endif()
######################################################################
# Other third party libraries
if(USE_SHARED_JPEGLIB)
find_package(JPEG)
if(JPEG_FOUND)
set(libs3rdparty ${libs3rdparty} ${JPEG_LIBRARIES})
include_directories(${JPEG_INCLUDE_DIR})
endif(JPEG_FOUND)
else()
set(libs3rdparty ${libs3rdparty} jpeg)
include_directories(${LIBJPEG_DIR})
endif()
if(USE_SHARED_ZLIB)
find_package(ZLIB)
if(ZLIB_FOUND)
set(libs3rdparty ${libs3rdparty} ${ZLIB_LIBRARIES})
include_directories(${ZLIB_INCLUDE_DIR})
endif(ZLIB_FOUND)
else()
set(libs3rdparty ${libs3rdparty} zlib)
include_directories(${ZLIB_DIR})
endif()
if(USE_SHARED_LIBPNG)
set(libs3rdparty ${libs3rdparty} ${PNG_LIBRARIES})
else()
set(libs3rdparty ${libs3rdparty} libpng)
endif()
if(USE_SHARED_GIFLIB)
find_package(GIF REQUIRED)
if(GIF_FOUND)
set(libs3rdparty ${libs3rdparty} ${GIF_LIBRARIES})
include_directories(${GIF_INCLUDE_DIR})
endif(GIF_FOUND)
else()
set(libs3rdparty ${libs3rdparty} giflib)
include_directories(${GIFLIB_DIR}/lib)
endif()
if(USE_SHARED_TINYXML)
find_library(LIBTINYXML_LIBRARY NAMES tinyxml)
find_path(LIBTINYXML_INCLUDE_DIR NAMES tinyxml.h)
set(libs3rdparty ${libs3rdparty} ${LIBTINYXML_LIBRARY})
include_directories(${LIBTINYXML_INCLUDE_DIR})
else()
set(libs3rdparty ${libs3rdparty} tinyxml)
include_directories(${TINYXML_DIR})
endif()
if(USE_ALLEG4_BACKEND)
if(USE_SHARED_LIBLOADPNG)
find_library(LIBLOADPNG_LIBRARY NAMES loadpng)
find_path(LIBLOADPNG_INCLUDE_DIR NAMES loadpng.h)
set(libs3rdparty ${libs3rdparty} ${LIBLOADPNG_LIBRARY})
include_directories(${LIBLOADPNG_INCLUDE_DIR})
else()
set(libs3rdparty loadpng ${libs3rdparty})
include_directories(${LOADPNG_DIR})
endif()
endif()
if(USE_SHARED_PIXMAN)
find_library(LIBPIXMAN_LIBRARY NAMES pixman pixman-1)
find_path(LIBPIXMAN_INCLUDE_DIR NAMES pixman.h PATH_SUFFIXES pixman-1)
set(libs3rdparty ${libs3rdparty} ${LIBPIXMAN_LIBRARY})
include_directories(${LIBPIXMAN_INCLUDE_DIR})
else()
set(libs3rdparty ${libs3rdparty} pixman)
include_directories(${PIXMAN_DIR}/pixman)
include_directories(${CMAKE_BINARY_DIR})
endif()
set(libs3rdparty simpleini ${libs3rdparty})
include_directories(${SIMPLEINI_DIR})
######################################################################
# Add C++11 support only for our code (avoid Allegro)
@ -163,39 +53,29 @@ if(UNIX)
endif()
######################################################################
# Liburl
# pthread
if (CMAKE_USE_PTHREADS_INIT)
set(sys_libs ${sys_libs} ${CMAKE_THREAD_LIBS_INIT})
list(APPEND PLATFORM_LIBS ${CMAKE_THREAD_LIBS_INIT})
endif()
######################################################################
# Custom Aseprite website (for testing server-side)
if(NOT "${CUSTOM_WEBSITE_URL}" STREQUAL "")
add_definitions(-DCUSTOM_WEBSITE_URL="${CUSTOM_WEBSITE_URL}")
endif()
if(USE_SHARED_CURL)
find_library(LIBCURL_LIBRARY NAMES curl)
find_path(LIBCURL_INCLUDE_DIR NAMES curl/curl.h)
set(libs3rdparty ${libs3rdparty} ${LIBCURL_LIBRARY})
include_directories(${LIBCURL_INCLUDE_DIR})
else()
set(libs3rdparty ${libs3rdparty} libcurl)
include_directories(${CURL_DIR}/include)
if(CURL_STATICLIB)
add_definitions(-DCURL_STATICLIB)
endif()
endif()
if(ENABLE_WEBSERVER)
set(libs3rdparty ${libs3rdparty} mongoose)
include_directories(${MONGOOSE_DIR})
set(aseprite_libraries ${aseprite_libraries} webserver-lib)
add_definitions(-DENABLE_WEBSERVER)
endif()
######################################################################
# Full-version or trial-mode?
if(NOT USE_SHARED_CURL AND CURL_STATICLIB)
add_definitions(-DCURL_STATICLIB)
endif()
######################################################################
# Full-version or trial-mode?
if(NOT ENABLE_TRIAL_MODE)
add_definitions(-DENABLE_SAVE -DENABLE_DATA_RECOVERY)
else()
@ -206,8 +86,9 @@ endif()
# Aseprite Libraries (in preferred order to be built)
add_subdirectory(base)
# Directory where base/config.h file is located
include_directories(${BASE_INCLUDE_DIR})
list(APPEND libs3rdparty ${BASE_EXTRA_LIBRARIES})
add_subdirectory(cfg)
add_subdirectory(css)
@ -233,20 +114,8 @@ endif()
add_subdirectory(app)
if(V8_FOUND)
list(APPEND libs3rdparty ${V8_LIBRARIES})
endif()
if(USE_SKIA_BACKEND)
list(APPEND sys_libs ${PLATFORM_LIBS})
list(APPEND libs3rdparty ${SKIA_LIBRARIES})
endif()
# All libraries for .exe files
set(all_libs ${aseprite_libraries} ${libs3rdparty} ${sys_libs})
if(USE_ALLEG4_BACKEND AND LIBALLEGRO4_LINK_FLAGS)
set(all_libs ${all_libs} ${LIBALLEGRO4_LINK_FLAGS})
list(APPEND PLATFORM_LIBS ${SKIA_LIBRARIES})
endif()
######################################################################
@ -279,7 +148,7 @@ add_executable(aseprite WIN32
main/main.cpp
${win32_resources}
${x11_resources})
target_link_libraries(aseprite ${all_libs})
target_link_libraries(aseprite app-lib ${PLATFORM_LIBS})
add_dependencies(aseprite copy_data)
install(TARGETS aseprite
@ -315,10 +184,7 @@ function(find_tests dir dependencies)
PROPERTIES LINK_FLAGS -ENTRY:"mainCRTStartup")
endif()
target_link_libraries(${testname} gtest ${ARGV})
if(USE_ALLEG4_BACKEND AND LIBALLEGRO4_LINK_FLAGS)
target_link_libraries(${testname} ${LIBALLEGRO4_LINK_FLAGS})
endif()
target_link_libraries(${testname} gtest ${PLATFORM_LIBS} ${ARGV})
if(extra_definitions)
set_target_properties(${testname}
@ -340,16 +206,16 @@ function(find_tests dir dependencies)
set(non_ui_runs ${non_ui_runs} ${local_non_ui_runs} PARENT_SCOPE)
endfunction()
find_tests(base base-lib ${sys_libs})
find_tests(undo undo-lib ${sys_libs})
find_tests(gfx gfx-lib base-lib ${libs3rdparty} ${sys_libs})
find_tests(doc doc-lib gfx-lib base-lib ${libs3rdparty} ${sys_libs})
find_tests(render render-lib doc-lib gfx-lib base-lib ${libs3rdparty} ${sys_libs})
find_tests(css css-lib gfx-lib base-lib ${libs3rdparty} ${sys_libs})
find_tests(ui ui-lib she gfx-lib base-lib ${libs3rdparty} ${sys_libs})
find_tests(app/file ${all_libs})
find_tests(app ${all_libs})
find_tests(. ${all_libs})
find_tests(base base-lib)
find_tests(undo undo-lib)
find_tests(gfx gfx-lib)
find_tests(doc doc-lib)
find_tests(render render-lib)
find_tests(css css-lib)
find_tests(ui ui-lib)
find_tests(app/file app-lib)
find_tests(app app-lib)
find_tests(. app-lib)
# To run tests
add_custom_target(run_all_tests DEPENDS ${all_runs})

View File

@ -381,3 +381,31 @@ add_library(app-lib
xml_exception.cpp
${data_recovery_files}
${generated_files})
target_link_libraries(app-lib
base-lib
cfg-lib
css-lib
doc-lib
filters-lib
fixmath-lib
gfx-lib
net-lib
render-lib
scripting-lib
she
ui-lib
undo-lib
${TINYXML_LIBRARY}
${JPEG_LIBRARIES}
${GIF_LIBRARIES}
${PNG_LIBRARIES}
${ZLIB_LIBRARIES})
if(ENABLE_UPDATER)
target_link_libraries(app-lib updater-lib)
endif()
if(ENABLE_WEBSERVER)
target_link_libraries(app-lib webserver-lib)
endif()

View File

@ -38,14 +38,6 @@ configure_file(${CMAKE_CURRENT_LIST_DIR}/config.h.cmakein
set(BASE_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}
CACHE INTERNAL "Extra include directory for base lib")
if(WIN32)
set(EXTRA_LIBS dbghelp shlwapi)
else()
set(EXTRA_LIBS)
endif()
set(BASE_EXTRA_LIBRARIES ${EXTRA_LIBS}
CACHE INTERNAL "Extra libraries needed by base lib")
include_directories(${BASE_INCLUDE_DIR})
set(BASE_SOURCES
@ -85,6 +77,6 @@ endif()
add_library(base-lib ${BASE_SOURCES})
if(ENABLE_MEMLEAK AND MSVC)
target_link_libraries(base-lib dbghelp)
if(WIN32)
target_link_libraries(base-lib dbghelp shlwapi)
endif()

View File

@ -1,4 +1,7 @@
# Aseprite Config Library
# Copyright (c) 2014 David Capello
# Copyright (c) 2014, 2015 David Capello
add_library(cfg-lib cfg.cpp)
target_link_libraries(cfg-lib
${SIMPLEINI_LIBRARY})

View File

@ -53,3 +53,10 @@ add_library(doc-lib
sprites.cpp
string_io.cpp
subobjects_io.cpp)
# TODO Remove 'she' as dependency and move conversion_she.cpp/h files
# to other library/layer (render-lib? new conversion-lib?)
target_link_libraries(doc-lib
she
gfx-lib
base-lib)

View File

@ -13,9 +13,6 @@ if(MSVC)
PROPERTIES LINK_FLAGS -ENTRY:"mainCRTStartup")
endif()
target_link_libraries(gen base-lib)
if(USE_SHARED_TINYXML)
target_link_libraries(gen ${LIBTINYXML_LIBRARY})
else()
target_link_libraries(gen tinyxml)
endif()
target_link_libraries(gen
base-lib
${TINYXML_LIBRARY})

View File

@ -1,5 +1,5 @@
# Aseprite
# Copyright (C) 2001-2014 David Capello
# Copyright (C) 2001-2015 David Capello
add_library(gfx-lib
clip.cpp
@ -8,3 +8,6 @@ add_library(gfx-lib
region.cpp
rgb.cpp
transformation.cpp)
target_link_libraries(gfx-lib
${PIXMAN_LIBRARY})

View File

@ -5,3 +5,6 @@ add_library(net-lib
http_headers.cpp
http_request.cpp
http_response.cpp)
target_link_libraries(net-lib
${LIBCURL_LIBRARY})

View File

@ -1,8 +1,13 @@
# Aseprite Render Library
# Copyright (C) 2001-2014 David Capello
# Copyright (C) 2001-2015 David Capello
add_library(render-lib
get_sprite_pixel.cpp
quantization.cpp
render.cpp
zoom.cpp)
target_link_libraries(render-lib
doc-lib
gfx-lib
base-lib)

View File

@ -3,7 +3,22 @@
set(SHE_SOURCES)
######################################################################
# Allegro 4 backend
if(USE_ALLEG4_BACKEND)
if(WIN32)
find_package(DXGuid)
if(NOT DXGUID_FOUND)
if(MSVC)
message(FATAL_ERROR "DirectX required for Windows port. You might need to add DirectX include and lib directories to your INCLUDE and LIB environment variables.")
else()
message(FATAL_ERROR "DirectX required for Windows port.")
endif()
endif()
include_directories(SYSTEM ${DXGUID_INCLUDE_DIR})
endif()
list(APPEND SHE_SOURCES
alleg4/clock.cpp
alleg4/close_button.cpp
@ -18,6 +33,9 @@ if(USE_ALLEG4_BACKEND)
endif()
endif()
######################################################################
# Skia backend
if(USE_SKIA_BACKEND)
set(SKIA_DIR "" CACHE PATH "Skia source code directory")
@ -127,6 +145,8 @@ if(USE_SKIA_BACKEND)
endif()
endif()
######################################################################
if(WIN32)
list(APPEND SHE_SOURCES
win/clipboard.cpp
@ -141,3 +161,14 @@ if(APPLE)
endif()
add_library(she ${SHE_SOURCES})
target_link_libraries(she
gfx-lib
base-lib)
if(USE_ALLEG4_BACKEND)
target_link_libraries(she
${LOADPNG_LIBRARY}
${LIBALLEGRO4_LINK_FLAGS}
${DXGUID_LIBRARIES})
endif()

View File

@ -1,5 +1,5 @@
# ASEPRITE
# Copyright (C) 2001-2014 David Capello
# Copyright (C) 2001-2015 David Capello
add_library(ui-lib
accelerator.cpp
@ -50,3 +50,9 @@ add_library(ui-lib
viewport.cpp
widget.cpp
window.cpp)
target_link_libraries(ui-lib
she
gfx-lib
base-lib
${PIXMAN_LIBRARY})

View File

@ -12,3 +12,7 @@ elseif(APPLE)
endif()
add_library(updater-lib ${UPDATER_LIB_SOURCES})
target_link_libraries(updater-lib
net-lib
${TINYXML_LIBRARY})

View File

@ -1,5 +1,8 @@
# ASEPRITE
# Copyright (C) 2001-2013 David Capello
# Copyright (C) 2001-2013, 2015 David Capello
add_library(webserver-lib
webserver.cpp)
target_link_libraries(webserver-lib
${MONGOOSE_LIBRARY})

View File

@ -5,3 +5,7 @@ add_library(loadpng
loadpng.c
savepng.c
regpng.c)
target_link_libraries(loadpng
${PNG_LIBRARIES}
${ZLIB_LIBRARIES})