-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
79 lines (59 loc) · 2.24 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
cmake_minimum_required(VERSION 3.0.0)
project(FreeImage)
#set(FI_SRCS_FILE fipMakefile.srcs)
set(FI_SRCS_FILE Makefile.srcs CACHE FILEPATH ".srcs file from freeimage source code")
message(STATUS "Generate Project From ${FI_SRCS_FILE}")
# read file content
file(STRINGS ${FI_SRCS_FILE} SRCS_File)
# find VER_MAJOR
string(REGEX MATCH "VER_MAJOR = ([0-9.]*);" VER_MAJOR_STR "${SRCS_File}")
set(VER_MAJOR ${CMAKE_MATCH_1})
# find VER_MINOR
string(REGEX MATCH "VER_MINOR = ([0-9.]*);" VER_MINOR_STR "${SRCS_File}")
set(VER_MINOR ${CMAKE_MATCH_1})
message(STATUS "FreeImage Version ${VER_MAJOR}.${VER_MINOR}")
# find SRCS
string(REGEX MATCH "SRCS = ([^;]*);" SRCS_STR "${SRCS_File}")
set(SRCS ${CMAKE_MATCH_1})
# FreeImagePlus.DllMain confilct with FreeImage.DllMain
string(REPLACE "FreeImagePlus.cpp" "" SRCS ${SRCS})
string(REPLACE " " ";" SRCS ${SRCS})
# find INCLS
string(REGEX MATCH "INCLS = ([^;]*);" INCLS_STR "${SRCS_File}")
set(INCLS ${CMAKE_MATCH_1})
if(INCLS)
# remove missing FreeImage.h file
string(REPLACE "./Dist/FreeImage.h" "" INCLS ${INCLS})
string(REPLACE " " ";" INCLS ${INCLS})
endif()
# find INCLUDE
string(REGEX MATCH "INCLUDE = ([^;]*)" INCLUDE_STR "${SRCS_File}")
set(INCLUDE ${CMAKE_MATCH_1})
string(REGEX REPLACE " ?-I" ";" INCLUDE ${INCLUDE})
# source_group
foreach(FILE ${SRCS} ${INCLS})
get_filename_component(PARENT_DIR "${FILE}" PATH)
# ignore .
string(REGEX REPLACE "\\.[/\\\\]" "" GROUP "${PARENT_DIR}")
string(REPLACE "/" "\\" GROUP "${GROUP}")
# group into "Source Files" and "Header Files"
if ("${FILE}" MATCHES ".*\\.cp{0,2}")
set(GROUP "Source Files\\${GROUP}")
elseif("${FILE}" MATCHES ".*\\.h")
set(GROUP "Header Files\\${GROUP}")
endif()
source_group("${GROUP}" FILES "${FILE}")
endforeach()
# add library
add_library(FreeImage ${SRCS} ${INCLS})
# config library
target_compile_definitions(FreeImage PRIVATE LIBRAW_NODLL OPJ_STATIC DISABLE_PERF_MEASUREMENT)
if(NOT MSVC)
target_compile_definitions(FreeImage PRIVATE __ANSI__)
endif()
if(BUILD_SHARED_LIBS)
target_compile_definitions(FreeImage PRIVATE FIP_EXPORTS FREEIMAGE_EXPORTS)
else()
target_compile_definitions(FreeImage PUBLIC FREEIMAGE_LIB)
endif()
target_include_directories(FreeImage PRIVATE ${INCLUDE})