2016-11-28 00:24:23 +08:00
|
|
|
cmake_minimum_required(VERSION 3.4)
|
|
|
|
|
|
|
|
include(GNUInstallDirs)
|
|
|
|
|
|
|
|
project(FreeImage C CXX)
|
|
|
|
|
2019-02-27 00:16:20 +08:00
|
|
|
if(MSVC)
|
|
|
|
add_definitions("-D_CRT_SECURE_NO_WARNINGS")
|
|
|
|
set(CMAKE_CXX_FLAGS "/wd4828 ${CMAKE_CXX_FLAGS}")
|
2018-11-11 22:19:42 +08:00
|
|
|
endif()
|
2016-11-28 00:24:23 +08:00
|
|
|
|
2020-01-07 05:15:20 +08:00
|
|
|
find_package(ZLIB REQUIRED)
|
2019-02-27 00:16:20 +08:00
|
|
|
find_package(PNG REQUIRED)
|
|
|
|
find_package(JPEG REQUIRED)
|
|
|
|
find_package(TIFF REQUIRED)
|
|
|
|
find_package(OpenJPEG REQUIRED)
|
|
|
|
find_package(WebP REQUIRED)
|
|
|
|
find_package(JXR REQUIRED)
|
|
|
|
find_package(LibRaw REQUIRED)
|
|
|
|
find_package(OpenEXR REQUIRED)
|
2016-11-28 00:24:23 +08:00
|
|
|
|
|
|
|
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
|
2017-04-01 00:03:37 +08:00
|
|
|
option(INSTALL_HEADERS "Install the development headers" ON)
|
2016-11-28 00:24:23 +08:00
|
|
|
|
|
|
|
set(REAL_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Source)
|
|
|
|
|
|
|
|
# Add a debug postfix
|
|
|
|
set(CMAKE_DEBUG_POSTFIX "d")
|
|
|
|
|
|
|
|
# List the public header files
|
|
|
|
set(PUBLIC_HEADERS ${REAL_SOURCE_DIR}/FreeImage.h)
|
|
|
|
|
|
|
|
# List the private header files
|
2019-02-27 00:16:20 +08:00
|
|
|
set(ROOT_PRIVATE_HEADERS ${REAL_SOURCE_DIR}/CacheFile.h
|
|
|
|
${REAL_SOURCE_DIR}/FreeImageIO.h
|
2016-11-28 00:24:23 +08:00
|
|
|
${REAL_SOURCE_DIR}/MapIntrospector.h
|
2019-02-27 00:16:20 +08:00
|
|
|
${REAL_SOURCE_DIR}/Plugin.h
|
|
|
|
${REAL_SOURCE_DIR}/Quantizers.h
|
|
|
|
${REAL_SOURCE_DIR}/ToneMapping.h
|
2018-11-11 22:16:11 +08:00
|
|
|
${REAL_SOURCE_DIR}/Utilities.h)
|
|
|
|
|
2016-11-28 00:24:23 +08:00
|
|
|
file(GLOB FREEIMAGE_PRIVATE_HEADERS ${REAL_SOURCE_DIR}/FreeImage/*.h)
|
|
|
|
file(GLOB FREEIMAGE_TOOLKIT_PRIVATE_HEADERS ${REAL_SOURCE_DIR}/FreeImageToolkit/*.h)
|
|
|
|
file(GLOB METADATA_PRIVATE_HEADERS ${REAL_SOURCE_DIR}/Metadata/*.h)
|
|
|
|
|
|
|
|
set(PRIVATE_HEADERS ${ROOT_PRIVATE_HEADERS}
|
|
|
|
${FREEIMAGE_PRIVATE_HEADERS}
|
|
|
|
${FREEIMAGE_TOOLKIT_PRIVATE_HEADERS}
|
|
|
|
${METADATA_PRIVATE_HEADERS})
|
|
|
|
|
|
|
|
# List the source files
|
|
|
|
file(GLOB DEPRECATION_SRCS ${REAL_SOURCE_DIR}/DeprecationManager/*.cpp)
|
|
|
|
file(GLOB FREEIMAGE_TOOLKIT_SRCS ${REAL_SOURCE_DIR}/FreeImageToolkit/*.cpp)
|
|
|
|
file(GLOB FREEIMAGE_SRCS ${REAL_SOURCE_DIR}/FreeImage/*.cpp)
|
|
|
|
file(GLOB METADATA_SRCS ${REAL_SOURCE_DIR}/Metadata/*.cpp)
|
|
|
|
|
|
|
|
# The G3 plugin is disabled because it require the private copy of tiff
|
|
|
|
list(REMOVE_ITEM FREEIMAGE_SRCS ${REAL_SOURCE_DIR}/FreeImage/PluginG3.cpp)
|
|
|
|
|
2019-02-27 00:16:20 +08:00
|
|
|
# The JPEGTransform plugin is disable because it requires a private copy of jpeg
|
2016-11-28 00:24:23 +08:00
|
|
|
list(REMOVE_ITEM FREEIMAGE_TOOLKIT_SRCS ${REAL_SOURCE_DIR}/FreeImageToolkit/JPEGTransform.cpp)
|
|
|
|
|
|
|
|
|
|
|
|
set(SRCS ${DEPRECATION_SRCS}
|
|
|
|
${FREEIMAGE_SRCS}
|
|
|
|
${FREEIMAGE_TOOLKIT_SRCS}
|
|
|
|
${METADATA_SRCS}
|
|
|
|
)
|
|
|
|
|
2019-02-27 00:16:20 +08:00
|
|
|
# If FreeImage is used as a static library, FREEIMAGE_LIB
|
|
|
|
# needs to be defined (at the C preprocessor level) to correctly
|
2016-11-28 00:24:23 +08:00
|
|
|
# define (to nothing instead of _declspec(dllimport) ) the DLL_API macro.
|
|
|
|
# For this purpouse we include (depending on the BUILD_SHARED_LIBS )
|
|
|
|
# the appropriate FreeImageConfig.h .
|
2017-10-12 22:52:48 +08:00
|
|
|
if(BUILD_SHARED_LIBS)
|
2016-11-28 00:24:23 +08:00
|
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/FreeImageConfig-dynamic.h ${CMAKE_CURRENT_BINARY_DIR}/FreeImageConfig.h)
|
|
|
|
else()
|
|
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/FreeImageConfig-static.h ${CMAKE_CURRENT_BINARY_DIR}/FreeImageConfig.h)
|
|
|
|
endif()
|
|
|
|
list(APPEND PUBLIC_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/FreeImageConfig.h)
|
|
|
|
|
|
|
|
add_library(FreeImage ${SRCS} ${PRIVATE_HEADERS} ${PUBLIC_HEADERS})
|
|
|
|
|
2017-10-12 22:52:48 +08:00
|
|
|
if(BUILD_SHARED_LIBS)
|
2016-11-28 00:24:23 +08:00
|
|
|
target_compile_definitions(FreeImage PRIVATE -DFREEIMAGE_EXPORTS)
|
|
|
|
else()
|
|
|
|
target_compile_definitions(FreeImage PRIVATE -DFREEIMAGE_LIB)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
target_include_directories(FreeImage PRIVATE ${REAL_SOURCE_DIR}
|
2019-02-27 00:16:20 +08:00
|
|
|
${ZLIB_INCLUDE_DIRS}
|
2016-11-28 00:24:23 +08:00
|
|
|
${JPEG_INCLUDE_DIRS}
|
|
|
|
${TIFF_INCLUDE_DIRS}
|
|
|
|
${PNG_INCLUDE_DIRS}
|
|
|
|
${OPENJPEG_INCLUDE_DIRS}
|
|
|
|
${WEBP_INCLUDE_DIRS}
|
|
|
|
${JXR_INCLUDE_DIRS}
|
|
|
|
${LibRaw_INCLUDE_DIRS}
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR})
|
2017-04-01 00:03:37 +08:00
|
|
|
|
2016-11-28 00:24:23 +08:00
|
|
|
|
|
|
|
target_link_libraries(FreeImage ${ZLIB_LIBRARIES}
|
|
|
|
${JPEG_LIBRARIES}
|
|
|
|
${TIFF_LIBRARIES}
|
|
|
|
${PNG_LIBRARIES}
|
|
|
|
${OPENJPEG_LIBRARIES}
|
|
|
|
${WEBP_LIBRARIES}
|
|
|
|
${JXR_LIBRARIES}
|
|
|
|
${LibRaw_LIBRARIES}
|
2020-07-28 08:43:23 +08:00
|
|
|
OpenEXR::IlmImf)
|
2016-11-28 00:24:23 +08:00
|
|
|
|
|
|
|
target_compile_definitions(FreeImage PRIVATE ${PNG_DEFINITIONS})
|
|
|
|
|
2017-04-01 00:03:37 +08:00
|
|
|
# FreeImagePlus
|
|
|
|
file(GLOB FREEIMAGEPLUS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Wrapper/FreeImagePlus/src/*.cpp)
|
|
|
|
add_library(FreeImagePlus
|
|
|
|
${FREEIMAGEPLUS_SOURCES}
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/Wrapper/FreeImagePlus/FreeImagePlus.h
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/Wrapper/FreeImagePlus/FreeImagePlus.rc)
|
|
|
|
|
2017-10-12 22:52:48 +08:00
|
|
|
if(BUILD_SHARED_LIBS)
|
2017-04-01 00:03:37 +08:00
|
|
|
target_compile_definitions(FreeImagePlus PRIVATE -DFIP_EXPORTS)
|
|
|
|
else()
|
|
|
|
target_compile_definitions(FreeImagePlus PRIVATE -DFREEIMAGE_LIB)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
target_include_directories(FreeImagePlus PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Wrapper/FreeImagePlus
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
${REAL_SOURCE_DIR})
|
|
|
|
|
|
|
|
target_link_libraries(FreeImagePlus PUBLIC FreeImage)
|
|
|
|
|
|
|
|
list(APPEND PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/Wrapper/FreeImagePlus/FreeImagePlus.h)
|
|
|
|
|
2016-11-28 00:24:23 +08:00
|
|
|
install(TARGETS FreeImage
|
|
|
|
COMPONENT runtime
|
|
|
|
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT bin
|
|
|
|
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT shlib
|
|
|
|
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT lib)
|
|
|
|
|
2017-04-01 00:03:37 +08:00
|
|
|
install(TARGETS FreeImagePlus
|
|
|
|
COMPONENT runtime-cpp
|
|
|
|
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT bin
|
|
|
|
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT shlib
|
|
|
|
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT lib)
|
|
|
|
|
|
|
|
if(INSTALL_HEADERS)
|
|
|
|
install(FILES ${PUBLIC_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
2019-02-27 00:16:20 +08:00
|
|
|
endif()
|