Skip to content

Commit ba7c718

Browse files
committed
fixes CMake for nomacs (Windows)
1 parent 89241f2 commit ba7c718

File tree

3 files changed

+66
-17
lines changed

3 files changed

+66
-17
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ debian/qt-heif-image-plugin.debhelper.log
88
debian/qt-heif-image-plugin.substvars
99
debian/qt-heif-image-plugin/
1010
obj-*-linux-gnu/
11+
12+
CMakeUserPaths.cmake

CMakeUserPathsGit.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# If you want to use prefix paths with cmake, copy and rename this file to CMakeUserPaths.cmake
2+
# Do not add this file to GIT!
3+
4+
IF (CMAKE_CL_64)
5+
6+
SET(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "C:/Qt/Qt5.11.1-x64/bin")
7+
ELSE()
8+
9+
SET(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "C:/Qt/Qt5.11.1-x86/bin")
10+
ENDIF()

src/CMakeLists.txt

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,32 @@ set(CMAKE_CXX_STANDARD 11)
44
set(CMAKE_CXX_STANDARD_REQUIRED ON)
55
set(CMAKE_CXX_EXTENSIONS OFF)
66

7+
# load paths from the user file if exists
8+
if (EXISTS ${CMAKE_SOURCE_DIR}/CMakeUserPaths.cmake)
9+
include(${CMAKE_SOURCE_DIR}/CMakeUserPaths.cmake)
10+
11+
if(NOT QT_QMAKE_EXECUTABLE)
12+
find_program(QT_QMAKE_EXECUTABLE NAMES "qmake" "qmake-qt5" "qmake.exe")
13+
endif()
14+
if(NOT QT_QMAKE_EXECUTABLE)
15+
message(FATAL_ERROR "you have to set the path to the Qt5 qmake executable")
16+
endif()
17+
18+
message(STATUS "QMake found: ${QT_QMAKE_EXECUTABLE}")
19+
get_filename_component(QT_QMAKE_PATH ${QT_QMAKE_EXECUTABLE} PATH)
20+
21+
set(QT_ROOT ${QT_QMAKE_PATH}/)
22+
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${QT_QMAKE_PATH}/../lib/cmake/Qt5)
23+
24+
message(STATUS "using user paths, new prefix path: ${CMAKE_PREFIX_PATH}")
25+
elseif(MSVC)
26+
message(WARNING "Could not find CMakeUserPaths.cmake - please use this file to specify your install directories (see CMakeUserPathsGit.cmake)")
27+
endif()
28+
729
# make release build, if not specified
830
# (from https://blog.kitware.com/cmake-and-the-default-build-type/)
931
set(default_build_type "RelWithDebInfo")
32+
set(CMAKE_DEBUG_POSTFIX "d")
1033

1134
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
1235
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Build type" FORCE)
@@ -17,19 +40,23 @@ endif ()
1740

1841
# compiler flags
1942
# TODO: separate GCC and Clang warnings; add more
20-
set(
21-
CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
22-
-Wall \
23-
-Wextra \
24-
-Wshadow \
25-
-Wformat-nonliteral \
26-
-Wformat-security \
27-
-Wnon-virtual-dtor \
28-
")
29-
30-
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og")
31-
32-
set(sanitizer_flags "-fsanitize=address -fsanitize=undefined")
43+
if (!MSVC)
44+
set(
45+
CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
46+
-Wall \
47+
-Wextra \
48+
-Wshadow \
49+
-Wformat-nonliteral \
50+
-Wformat-security \
51+
-Wnon-virtual-dtor \
52+
")
53+
54+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og")
55+
set(sanitizer_flags "-fsanitize=address -fsanitize=undefined")
56+
57+
endif()
58+
59+
3360
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${sanitizer_flags}")
3461
set(CMAKE_MODULE_LINKER_FLAGS_DEBUG
3562
"${CMAKE_MODULE_LINKER_FLAGS_DEBUG} ${sanitizer_flags}")
@@ -44,15 +71,25 @@ add_definitions(-DQT_NO_KEYWORDS)
4471
set(CMAKE_AUTOMOC ON)
4572

4673
# libheif
47-
find_package(PkgConfig)
48-
pkg_check_modules(libheif REQUIRED libheif>=1.1)
74+
if (!MSVC)
75+
find_package(PkgConfig)
76+
pkg_check_modules(libheif REQUIRED libheif>=1.1)
77+
else()
78+
79+
find_package(libheif)
80+
include_directories( ${libheif_INCLUDE_DIR})
81+
82+
if(!LIBHEIF_FOUND)
83+
message(FATAL_ERROR "I could not find libheif which is needed. You should add its path to the CMAKE_PREFIX_PATHS")
84+
endif()
85+
86+
endif()
4987

5088
#
5189
# project source
5290
#
5391

5492
set(CMAKE_INCLUDE_CURRENT_DIR ON)
55-
5693
set(sources main.cpp qheifhandler.cpp)
5794

5895
add_library(qheif MODULE ${sources})
@@ -61,7 +98,7 @@ target_link_libraries(
6198
qheif
6299
PRIVATE
63100
Qt5::Gui
64-
${libheif_LIBRARIES}
101+
${libheif_LIBRARIES}
65102
)
66103

67104
#

0 commit comments

Comments
 (0)