Skip to content
Merged
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
65 changes: 37 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
cmake_minimum_required(VERSION 3.22)

option(MV_UNITY_BUILD "Combine target source files into batches for faster compilation" OFF)
option(MV_IML_USE_SYSTEM_FREEIMAGE "Use local freeimage installation instead of building it" OFF)

# -----------------------------------------------------------------------------
# ImageLoader Plugin
# -----------------------------------------------------------------------------
set(PROJECT "ImageLoaderPlugin")
PROJECT(${PROJECT})
PROJECT(${PROJECT} C CXX)

# -----------------------------------------------------------------------------
# CMake Options
Expand All @@ -16,43 +17,51 @@ set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(MSVC)
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DWIN32 /EHsc /MP /permissive- /Zc:__cplusplus")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /MD")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD")
endif(MSVC)

include(FetchContent)
endif()

# -----------------------------------------------------------------------------
# Dependencies
# -----------------------------------------------------------------------------
find_package(Qt6 COMPONENTS Widgets WebEngineWidgets Concurrent REQUIRED)
find_package(ManiVault COMPONENTS Core PointData ImageData CONFIG QUIET)

FetchContent_Declare(
FreeImage
GIT_REPOSITORY https://github.com/biovault/FreeImage
GIT_TAG 2fcb6ca6d3d4dd36f7be82368275dcce918227fa # master as of 19-11-2024, version 3.18.0 with cmake files
)

FetchContent_MakeAvailable(FreeImage)

set_target_properties(FreeImage FreeImageLib LibJPEG LibJXR LibOpenJPEG LibPNG LibRaw LibTIFF4 LibWebP OpenEXR ZLibFreeImage
PROPERTIES
FOLDER LoaderPlugins/Dependencies/ImageLoaderPlugin
)

# Do not build static library
set_target_properties(FreeImageLib PROPERTIES EXCLUDE_FROM_ALL ON)

# Remove /permissive- for OpenEXR and FreeImage
if(MSVC)
target_compile_options(OpenEXR PRIVATE /permissive)
target_compile_options(FreeImage PRIVATE /permissive)
target_compile_options(FreeImageLib PRIVATE /permissive) # we don't need the static library, but just in case someone does build it
endif(MSVC)
if(MV_IML_USE_SYSTEM_FREEIMAGE)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
find_package(FreeImage REQUIRED)
else()
include(FetchContent)

FetchContent_Declare(
FreeImage
GIT_REPOSITORY https://github.com/biovault/FreeImage
GIT_TAG v3.19.0 # version 3.19.0.1, freeimage + cmake files + some updated modules
)

FetchContent_MakeAvailable(FreeImage)

get_target_property(FreeImageVersion FreeImageLib VERSION)
message(STATUS "FreeImage Version: ${FreeImageVersion}")

set_target_properties(FreeImage FreeImageLib LibJPEG LibJXR LibOpenJPEG LibPNG LibRaw LibTIFF4 LibWebP OpenEXR ZLibFreeImage
PROPERTIES
FOLDER LoaderPlugins/Dependencies/ImageLoaderPlugin
)

# Do not build static library
set_target_properties(FreeImageLib PROPERTIES EXCLUDE_FROM_ALL ON)

# Remove /permissive- for OpenEXR and FreeImage
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_options(OpenEXR PRIVATE /permissive)
target_compile_options(FreeImage PRIVATE /permissive)
target_compile_options(FreeImageLib PRIVATE /permissive) # we don't need the static library, but just in case someone does build it
endif()
endif()

# -----------------------------------------------------------------------------
# Source files
Expand Down Expand Up @@ -200,7 +209,7 @@ set_target_properties(${PROJECT}
# Miscellaneous
# -----------------------------------------------------------------------------
# Automatically set the debug environment (command + working directory) for MSVC
if(MSVC)
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set_property(TARGET ${PROJECT} PROPERTY VS_DEBUGGER_WORKING_DIRECTORY $<IF:$<CONFIG:DEBUG>,${ManiVault_INSTALL_DIR}/Debug,$<IF:$<CONFIG:RELWITHDEBINFO>,${ManiVault_INSTALL_DIR}/RelWithDebInfo,${ManiVault_INSTALL_DIR}/Release>>)
set_property(TARGET ${PROJECT} PROPERTY VS_DEBUGGER_COMMAND $<IF:$<CONFIG:DEBUG>,"${ManiVault_INSTALL_DIR}/Debug/ManiVault Studio.exe",$<IF:$<CONFIG:RELWITHDEBINFO>,"${ManiVault_INSTALL_DIR}/RelWithDebInfo/ManiVault Studio.exe","${ManiVault_INSTALL_DIR}/Release/ManiVault Studio.exe">>)
endif()
54 changes: 54 additions & 0 deletions cmake/FindFreeImage.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
set(FREEIMAGE_INCLUDE_DIR_HINTS "" CACHE PATH "FreeImage include directory")
set(FREEIMAGE_LIBRARY_DIR_HINTS "" CACHE PATH "FreeImage library directory")

unset(FREEIMAGE_FOUND)

if(TARGET FreeImage)
set(FREEIMAGE_FOUND TRUE)
message(STATUS "Found FreeImage")
message(STATUS " Target : FreeImage")
else()
list(APPEND FREEIMAGE_CHECK_INCLUDE_DIRS
${FREEIMAGE_INCLUDE_DIR_HINTS}
/usr/include
/usr/local/include
/opt/homebrew/include
)

list(APPEND FREEIMAGE_CHECK_LIBRARY_DIRS
${FREEIMAGE_LIBRARY_DIR_HINTS}
/usr/lib
/usr/local/lib
/opt/homebrew/lib
)

find_path(FreeImage_INCLUDE_DIRS
NAMES
FreeImage.h
PATHS
${FREEIMAGE_CHECK_INCLUDE_DIRS})
)

find_library(FreeImage_LIBRARIES
NAMES
freeimage
PATHS
${FREEIMAGE_CHECK_LIBRARY_DIRS})
)

if(FREEIMAGE_INCLUDE_DIRS AND FREEIMAGE_LIBRARIES)
set(FREEIMAGE_FOUND TRUE)

add_library(FreeImage INTERFACE IMPORTED)
target_include_directories(
FreeImage INTERFACE ${FREEIMAGE_INCLUDE_DIRS})
target_link_libraries(
FreeImage INTERFACE ${FREEIMAGE_LIBRARIES})

message(STATUS "Found FreeImage")
message(STATUS " Includes : ${FREEIMAGE_INCLUDE_DIRS}")
message(STATUS " Libraries : ${FREEIMAGE_LIBRARIES}")
else()
message(FATAL_ERROR "Could not find FreeImage")
endif()
endif()