Skip to content

Commit 782d3fb

Browse files
authored
Update to Freeimage 3.19 (#122)
* Update freeimage to 319 * Add languages to cmake file * New freeimage version * Optionally use system installation of freeimage * CMake: be more specific about CMAKE_CXX_COMPILER_ID * use tag
1 parent 7388a1c commit 782d3fb

2 files changed

Lines changed: 91 additions & 28 deletions

File tree

CMakeLists.txt

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
cmake_minimum_required(VERSION 3.22)
22

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

56
# -----------------------------------------------------------------------------
67
# ImageLoader Plugin
78
# -----------------------------------------------------------------------------
89
set(PROJECT "ImageLoaderPlugin")
9-
PROJECT(${PROJECT})
10+
PROJECT(${PROJECT} C CXX)
1011

1112
# -----------------------------------------------------------------------------
1213
# CMake Options
@@ -16,43 +17,51 @@ set(CMAKE_AUTORCC ON)
1617
set(CMAKE_AUTOUIC ON)
1718
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1819

19-
if(MSVC)
20+
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
2021
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DWIN32 /EHsc /MP /permissive- /Zc:__cplusplus")
2122
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd")
2223
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /MD")
2324
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD")
24-
endif(MSVC)
25-
26-
include(FetchContent)
25+
endif()
2726

2827
# -----------------------------------------------------------------------------
2928
# Dependencies
3029
# -----------------------------------------------------------------------------
3130
find_package(Qt6 COMPONENTS Widgets WebEngineWidgets Concurrent REQUIRED)
3231
find_package(ManiVault COMPONENTS Core PointData ImageData CONFIG QUIET)
3332

34-
FetchContent_Declare(
35-
FreeImage
36-
GIT_REPOSITORY https://github.com/biovault/FreeImage
37-
GIT_TAG 2fcb6ca6d3d4dd36f7be82368275dcce918227fa # master as of 19-11-2024, version 3.18.0 with cmake files
38-
)
39-
40-
FetchContent_MakeAvailable(FreeImage)
41-
42-
set_target_properties(FreeImage FreeImageLib LibJPEG LibJXR LibOpenJPEG LibPNG LibRaw LibTIFF4 LibWebP OpenEXR ZLibFreeImage
43-
PROPERTIES
44-
FOLDER LoaderPlugins/Dependencies/ImageLoaderPlugin
45-
)
46-
47-
# Do not build static library
48-
set_target_properties(FreeImageLib PROPERTIES EXCLUDE_FROM_ALL ON)
49-
50-
# Remove /permissive- for OpenEXR and FreeImage
51-
if(MSVC)
52-
target_compile_options(OpenEXR PRIVATE /permissive)
53-
target_compile_options(FreeImage PRIVATE /permissive)
54-
target_compile_options(FreeImageLib PRIVATE /permissive) # we don't need the static library, but just in case someone does build it
55-
endif(MSVC)
33+
if(MV_IML_USE_SYSTEM_FREEIMAGE)
34+
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
35+
find_package(FreeImage REQUIRED)
36+
else()
37+
include(FetchContent)
38+
39+
FetchContent_Declare(
40+
FreeImage
41+
GIT_REPOSITORY https://github.com/biovault/FreeImage
42+
GIT_TAG v3.19.0 # version 3.19.0.1, freeimage + cmake files + some updated modules
43+
)
44+
45+
FetchContent_MakeAvailable(FreeImage)
46+
47+
get_target_property(FreeImageVersion FreeImageLib VERSION)
48+
message(STATUS "FreeImage Version: ${FreeImageVersion}")
49+
50+
set_target_properties(FreeImage FreeImageLib LibJPEG LibJXR LibOpenJPEG LibPNG LibRaw LibTIFF4 LibWebP OpenEXR ZLibFreeImage
51+
PROPERTIES
52+
FOLDER LoaderPlugins/Dependencies/ImageLoaderPlugin
53+
)
54+
55+
# Do not build static library
56+
set_target_properties(FreeImageLib PROPERTIES EXCLUDE_FROM_ALL ON)
57+
58+
# Remove /permissive- for OpenEXR and FreeImage
59+
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
60+
target_compile_options(OpenEXR PRIVATE /permissive)
61+
target_compile_options(FreeImage PRIVATE /permissive)
62+
target_compile_options(FreeImageLib PRIVATE /permissive) # we don't need the static library, but just in case someone does build it
63+
endif()
64+
endif()
5665

5766
# -----------------------------------------------------------------------------
5867
# Source files
@@ -200,7 +209,7 @@ set_target_properties(${PROJECT}
200209
# Miscellaneous
201210
# -----------------------------------------------------------------------------
202211
# Automatically set the debug environment (command + working directory) for MSVC
203-
if(MSVC)
212+
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
204213
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>>)
205214
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">>)
206215
endif()

cmake/FindFreeImage.cmake

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
set(FREEIMAGE_INCLUDE_DIR_HINTS "" CACHE PATH "FreeImage include directory")
2+
set(FREEIMAGE_LIBRARY_DIR_HINTS "" CACHE PATH "FreeImage library directory")
3+
4+
unset(FREEIMAGE_FOUND)
5+
6+
if(TARGET FreeImage)
7+
set(FREEIMAGE_FOUND TRUE)
8+
message(STATUS "Found FreeImage")
9+
message(STATUS " Target : FreeImage")
10+
else()
11+
list(APPEND FREEIMAGE_CHECK_INCLUDE_DIRS
12+
${FREEIMAGE_INCLUDE_DIR_HINTS}
13+
/usr/include
14+
/usr/local/include
15+
/opt/homebrew/include
16+
)
17+
18+
list(APPEND FREEIMAGE_CHECK_LIBRARY_DIRS
19+
${FREEIMAGE_LIBRARY_DIR_HINTS}
20+
/usr/lib
21+
/usr/local/lib
22+
/opt/homebrew/lib
23+
)
24+
25+
find_path(FreeImage_INCLUDE_DIRS
26+
NAMES
27+
FreeImage.h
28+
PATHS
29+
${FREEIMAGE_CHECK_INCLUDE_DIRS})
30+
)
31+
32+
find_library(FreeImage_LIBRARIES
33+
NAMES
34+
freeimage
35+
PATHS
36+
${FREEIMAGE_CHECK_LIBRARY_DIRS})
37+
)
38+
39+
if(FREEIMAGE_INCLUDE_DIRS AND FREEIMAGE_LIBRARIES)
40+
set(FREEIMAGE_FOUND TRUE)
41+
42+
add_library(FreeImage INTERFACE IMPORTED)
43+
target_include_directories(
44+
FreeImage INTERFACE ${FREEIMAGE_INCLUDE_DIRS})
45+
target_link_libraries(
46+
FreeImage INTERFACE ${FREEIMAGE_LIBRARIES})
47+
48+
message(STATUS "Found FreeImage")
49+
message(STATUS " Includes : ${FREEIMAGE_INCLUDE_DIRS}")
50+
message(STATUS " Libraries : ${FREEIMAGE_LIBRARIES}")
51+
else()
52+
message(FATAL_ERROR "Could not find FreeImage")
53+
endif()
54+
endif()

0 commit comments

Comments
 (0)