Skip to content

Commit

Permalink
add cmake build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangjipeng committed Jun 1, 2024
1 parent 2750142 commit 5897360
Show file tree
Hide file tree
Showing 19 changed files with 616 additions and 3 deletions.
20 changes: 20 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.16.0)

project(picasso LANGUAGES C CXX ASM HOMEPAGE_URL https://onecoolx.github.io/picasso/)

set(BUILD_SHARED_LIBS ON) # build shared library, OFF for static

set(PROJECT_ROOT ${CMAKE_CURRENT_LIST_DIR})

iF (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build Type" FORCE)
ENDIF()

include (${CMAKE_CURRENT_LIST_DIR}/build/configs.cmake)
include (${CMAKE_CURRENT_LIST_DIR}/build/defines.cmake)
include (${CMAKE_CURRENT_LIST_DIR}/third_party/third_party.cmake)
include (${CMAKE_CURRENT_LIST_DIR}/src/src.cmake)
include (${CMAKE_CURRENT_LIST_DIR}/ext/ext.cmake)
include (${CMAKE_CURRENT_LIST_DIR}/test/test.cmake)
include (${CMAKE_CURRENT_LIST_DIR}/demos/demos.cmake)

11 changes: 11 additions & 0 deletions build/configs.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Picasso - a vector graphics library
#
# Copyright (C) 2024 Zhang Ji Peng
# Contact: [email protected]

IF (WIN32)
ELSEIF (UNIX AND NOT APPLE)
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -Wall -g -fPIC -std=c++11 -fno-rtti -fno-exceptions -Wno-unused-result -Wno-register -Wno-attributes")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wall -fPIC -std=c++11 -fno-rtti -fno-exceptions -Wno-unused-result -Wno-register -Wno-attributes")
ELSEIF (APPLE)
ENDIF()
17 changes: 17 additions & 0 deletions build/defines.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Picasso - a vector graphics library
#
# Copyright (C) 2024 Zhang Ji Peng
# Contact: [email protected]

IF (WIN32)
add_compile_definitions(WIN32)
add_compile_definitions(DLL_EXPORT)
add_compile_definitions(ENABLE_FAST_COPY=1)
add_compile_definitions(ENABLE_SYSTEM_MALLOC=1)
add_compile_definitions(__SSE2__=1)
ELSEIF (UNIX AND NOT APPLE)
add_compile_definitions(ENABLE_FREE_TYPE2=1)
add_compile_definitions(ENABLE_FONT_CONFIG=1)
ELSEIF (APPLE)
add_compile_definitions(ENABLE_SYSTEM_MALLOC=1)
ENDIF()
27 changes: 27 additions & 0 deletions demos/demos.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Picasso - a vector graphics library
#
# Copyright (C) 2024 Zhang Ji Peng
# Contact: [email protected]

if (WIN32)
elseif (UNIX AND NOT APPLE)
find_package(GTK2 REQUIRED)
set(main_file ${PROJECT_ROOT}/demos/platform_gtk2.c)
set(main_gui_inc ${GTK2_INCLUDE_DIRS})
set(main_gui_lib ${GTK2_LIBRARIES} pthread)
elseif (APPLE)
endif()

set(DEMOS_SOURCES ${PROJECT_ROOT}/demos/clock.c
${PROJECT_ROOT}/demos/flowers.c
${PROJECT_ROOT}/demos/tiger.c
${PROJECT_ROOT}/demos/subwaymap.c)

foreach(demo_file ${DEMOS_SOURCES})
get_filename_component(demo ${demo_file} NAME_WLE)
add_executable(${demo} ${demo_file} ${main_file})

include_directories(${demo} ${main_gui_inc})
target_link_libraries(${demo} PRIVATE picasso PUBLIC ${main_gui_lib})

endforeach(demo_file ${DEMOS_SOURCES})
7 changes: 7 additions & 0 deletions ext/ext.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Picasso - a vector graphics library
#
# Copyright (C) 2024 Zhang Ji Peng
# Contact: [email protected]

include (${CMAKE_CURRENT_LIST_DIR}/image_loader/image.cmake)

21 changes: 21 additions & 0 deletions ext/image_loader/gif/gif.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Picasso - a vector graphics library
#
# Copyright (C) 2024 Zhang Ji Peng
# Contact: [email protected]

set(PXGIF_DIR ${PROJECT_ROOT}/ext/image_loader/gif)

set(PXGIF_SOURCES
${PXGIF_DIR}/../psx_image_io.h
${PXGIF_DIR}/../psx_image_io.c
${PXGIF_DIR}/gif_module.c
)

add_definitions(-DEXPORT)
add_library(psxm_image_gif ${PXGIF_SOURCES})
target_link_libraries(psxm_image_gif PRIVATE gif)

set_target_properties(psxm_image_gif
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/modules"
)
31 changes: 31 additions & 0 deletions ext/image_loader/image.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Picasso - a vector graphics library
#
# Copyright (C) 2024 Zhang Ji Peng
# Contact: [email protected]

set(PXIMG_DIR ${PROJECT_ROOT}/ext/image_loader)

set(PXIMG_SOURCES
${PXIMG_DIR}/psx_list.h
${PXIMG_DIR}/psx_image_io.h
${PXIMG_DIR}/psx_image_io.c
${PXIMG_DIR}/psx_image_loader.h
${PXIMG_DIR}/psx_image_loader.c
${PXIMG_DIR}/psx_image_modules.h
${PXIMG_DIR}/psx_image_modules.c
)

add_definitions(-DEXPORT)
add_library(psx_image ${PXIMG_SOURCES})

include_directories(${PXIMG_DIR} ${PROJECT_ROOT}/include)
target_link_libraries(psx_image PRIVATE picasso PUBLIC dl)

if (NOT APPLE)
include (${PXIMG_DIR}/png/png.cmake)
include (${PXIMG_DIR}/jpeg/jpeg.cmake)
include (${PXIMG_DIR}/gif/gif.cmake)
include (${PXIMG_DIR}/webp/webp.cmake)
else()
include (${PXIMG_DIR}/apple/apple.cmake)
endif()
21 changes: 21 additions & 0 deletions ext/image_loader/jpeg/jpeg.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Picasso - a vector graphics library
#
# Copyright (C) 2024 Zhang Ji Peng
# Contact: [email protected]

set(PXJPEG_DIR ${PROJECT_ROOT}/ext/image_loader/jpeg)

set(PXJPEG_SOURCES
${PXJPEG_DIR}/../psx_image_io.h
${PXJPEG_DIR}/../psx_image_io.c
${PXJPEG_DIR}/jpeg_module.c
)

add_definitions(-DEXPORT)
add_library(psxm_image_jpeg ${PXJPEG_SOURCES})
target_link_libraries(psxm_image_jpeg PRIVATE jpeg)

set_target_properties(psxm_image_jpeg
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/modules"
)
21 changes: 21 additions & 0 deletions ext/image_loader/png/png.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Picasso - a vector graphics library
#
# Copyright (C) 2024 Zhang Ji Peng
# Contact: [email protected]

set(PXPNG_DIR ${PROJECT_ROOT}/ext/image_loader/png)

set(PXPNG_SOURCES
${PXPNG_DIR}/../psx_image_io.h
${PXPNG_DIR}/../psx_image_io.c
${PXPNG_DIR}/png_module.c
)

add_definitions(-DEXPORT)
add_library(psxm_image_png ${PXPNG_SOURCES})
target_link_libraries(psxm_image_png PRIVATE png)

set_target_properties(psxm_image_png
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/modules"
)
21 changes: 21 additions & 0 deletions ext/image_loader/webp/webp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Picasso - a vector graphics library
#
# Copyright (C) 2024 Zhang Ji Peng
# Contact: [email protected]

set(PXWEBP_DIR ${PROJECT_ROOT}/ext/image_loader/webp)

set(PXWEBP_SOURCES
${PXWEBP_DIR}/../psx_image_io.h
${PXWEBP_DIR}/../psx_image_io.c
${PXWEBP_DIR}/webp_module.c
)

add_definitions(-DEXPORT)
add_library(psxm_image_webp ${PXWEBP_SOURCES})
target_link_libraries(psxm_image_webp PRIVATE webp)

set_target_properties(psxm_image_webp
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/modules"
)
6 changes: 3 additions & 3 deletions include/picasso.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
\verbatim
Copyright (C) 2008 ~ 2018 Zhang Ji Peng
Copyright (C) 2008 ~ 2024 Zhang Ji Peng
All rights reserved.
Expand Down Expand Up @@ -1826,8 +1826,8 @@ PEXPORT void PICAPI ps_clip_rect(ps_context* ctx, const ps_rect* rect);

/**
* \fn void ps_scissor_rect(ps_context* ctx, const ps_rect* rect)
* \brief The fast way to clipping specified rectangle, the clip rect can not be rotated
* by world matrix. (Deprecated)
* \brief The fast way to clipping specified rectangle, the clip rect can not be transformed
* by world matrix.
*
* \param ctx Pointer to an existing context object.
* \param rect The rectangle which will be clipped.
Expand Down
24 changes: 24 additions & 0 deletions src/src.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Picasso - a vector graphics library
#
# Copyright (C) 2024 Zhang Ji Peng
# Contact: [email protected]

file(GLOB_RECURSE SOURCES ${PROJECT_ROOT}/src/*.cpp)

add_library(picasso ${SOURCES})

include_directories(${PROJECT_ROOT}/build
${PROJECT_ROOT}/include
${PROJECT_ROOT}/src/include
${PROJECT_ROOT}/src
${PROJECT_ROOT}/src/gfx
${PROJECT_ROOT}/src/simd)

IF (WIN32)
ELSEIF (UNIX AND NOT APPLE)
find_package(Freetype REQUIRED)
find_package(Fontconfig REQUIRED)
target_include_directories(picasso PRIVATE ${FREETYPE_INCLUDE_DIRS} ${FONTCONFIG_INCLUDE_DIRS})
target_link_libraries(picasso PUBLIC Freetype::Freetype Fontconfig::Fontconfig)
ELSEIF (APPLE)
ENDIF()
50 changes: 50 additions & 0 deletions test/test.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Picasso - a vector graphics library
#
# Copyright (C) 2024 Zhang Ji Peng
# Contact: [email protected]


file(GLOB_RECURSE TEST_SOURCES ${PROJECT_ROOT}/test/*_func.c)
file(GLOB_RECURSE IMAGE_SOURCES ${PROJECT_ROOT}/test/image_*.c)

if (WIN32)
elseif (UNIX AND NOT APPLE)
find_package(GTK2 REQUIRED)
set(thread_file ${PROJECT_ROOT}/test/thr_posix.c)
set(main_file ${PROJECT_ROOT}/test/testGtk2.c)
set(host_gui_inc ${GTK2_INCLUDE_DIRS})
set(host_gui_lib ${GTK2_LIBRARIES} pthread)
configure_file(${PROJECT_ROOT}/test/pat.png ${CMAKE_CURRENT_BINARY_DIR}/pat.png COPYONLY)
configure_file(${PROJECT_ROOT}/test/selt2.png ${CMAKE_CURRENT_BINARY_DIR}/selt2.png COPYONLY)
elseif (APPLE)
endif()

foreach(test_file ${TEST_SOURCES})
get_filename_component(test_name ${test_file} NAME_WLE)
string(REPLACE "_" ";" test_app ${test_name})
list(GET test_app 0 test)

if (${test} STREQUAL "thread")
add_executable(${test} ${test_file} ${main_file} ${thread_file})
else()
add_executable(${test} ${test_file} ${main_file})
endif()

include_directories(${test} ${host_gui_inc})
target_link_libraries(${test} PRIVATE picasso PUBLIC ${host_gui_lib})

endforeach(test_file ${TEST_SOURCES})

foreach(image_file ${IMAGE_SOURCES})
get_filename_component(image_name ${image_file} NAME_WLE)

if (${image_name} STREQUAL "image_info")
add_executable(${image_name} ${image_file})
else()
add_executable(${image_name} ${image_file} ${main_file})
endif()

include_directories(${image_name} ${host_gui_inc})
target_link_libraries(${image_name} PRIVATE picasso psx_image PUBLIC ${host_gui_lib})

endforeach(image_file ${IMAGE_SOURCES})
27 changes: 27 additions & 0 deletions third_party/giflib.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Picasso - a vector graphics library
#
# Copyright (C) 2024 Zhang Ji Peng
# Contact: [email protected]

set(GIF_DIR ${PROJECT_ROOT}/third_party/giflib-5.1.3)

set(GIF_SOURCES
${GIF_DIR}/lib/gif_hash.h
${GIF_DIR}/lib/gif_lib.h
${GIF_DIR}/lib/gif_lib_private.h
${GIF_DIR}/lib/dgif_lib.c
${GIF_DIR}/lib/egif_lib.c
${GIF_DIR}/lib/gif_err.c
${GIF_DIR}/lib/gif_font.c
${GIF_DIR}/lib/gif_hash.c
${GIF_DIR}/lib/gifalloc.c
${GIF_DIR}/lib/openbsd-reallocarray.c
${GIF_DIR}/lib/quantize.c
)

configure_file(${GIF_DIR}/lib/gif_lib.h ${CMAKE_CURRENT_BINARY_DIR}/include/gif_lib.h)

add_library(gif ${GIF_SOURCES})

include_directories(${GIF_DIR} ${CMAKE_CURRENT_BINARY_DIR}/include)

Loading

0 comments on commit 5897360

Please sign in to comment.