Merge pull request #9 from DoumanAsh/full_cmake

Add cmake support for GUI part
This commit is contained in:
Akash Mozumdar 2018-07-28 22:39:21 -07:00 committed by GitHub
commit 5d297404f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 134 additions and 4 deletions

View File

@ -0,0 +1,109 @@
macro(msvc_registry_search)
IF(MSVC)
# look for user-registry pointing to qtcreator
get_filename_component(QT_BIN [HKEY_CURRENT_USER\\Software\\Classes\\Applications\\QtProject.QtCreator.cpp\\shell\\Open\\Command] PATH)
# get root path so we can search for 5.3, 5.4, 5.5, etc
string(REPLACE "/Tools" ";" QT_BIN "${QT_BIN}")
list(GET QT_BIN 0 QT_BIN)
file(GLOB QT_VERSIONS "${QT_BIN}/5.*")
list(SORT QT_VERSIONS)
# assume the latest version will be last alphabetically
list(REVERSE QT_VERSIONS)
list(GET QT_VERSIONS 0 QT_VERSION)
# fix any double slashes which seem to be common
string(REPLACE "//" "/" QT_VERSION "${QT_VERSION}")
if(MSVC_VERSION GREATER_EQUAL "1910")
set(QT_MSVC "2017")
elseif(MSVC_VERSION GREATER_EQUAL "1900")
set(QT_MSVC "2015")
else()
# Latest QT versions >5.10 provides only 2015 and 2017 prebuilt binaries
message(WARNING "Unsupported MSVC toolchain version")
endif()
if(QT_MSVC)
# check for 64-bit target
if(CMAKE_CL_64)
SET(QT_MSVC "${QT_MSVC}_64")
endif()
set(QT_TOLLCHAIN "${QT_VERSION}/msvc${QT_MSVC}")
if(EXISTS ${QT_TOLLCHAIN})
set(Qt5_DIR "${QT_TOLLCHAIN}/lib/cmake/Qt5")
elseif(QT_MSVC EQUAL "2017")
#2017 is ABI compatible with 2015
if(CMAKE_CL_64)
set(QT_TOLLCHAIN "${QT_VERSION}/msvc2015_64")
else()
set(QT_TOLLCHAIN "${QT_VERSION}/msvc2015")
endif()
if(EXISTS ${QT_TOLLCHAIN})
set(Qt5_DIR "${QT_TOLLCHAIN}/lib/cmake/Qt5")
else()
message(WARNING "Required QT5 toolchain is not installed")
endif()
else()
message(WARNING "Required QT5 toolchain is not installed")
endif()
endif()
ENDIF()
endmacro()
macro(find_qt5)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
add_definitions(-DQT_DEPRECATED_WARNINGS -DQT_DISABLE_DEPRECATED_BEFORE=0x060000)
find_package(Qt5 COMPONENTS ${ARGN})
if(Qt5_FOUND)
if(WIN32 AND TARGET Qt5::qmake AND NOT TARGET Qt5::windeployqt)
get_target_property(_qt5_qmake_location Qt5::qmake IMPORTED_LOCATION)
execute_process(
COMMAND "${_qt5_qmake_location}" -query QT_INSTALL_PREFIX
RESULT_VARIABLE return_code
OUTPUT_VARIABLE qt5_install_prefix
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(imported_location "${qt5_install_prefix}/bin/windeployqt.exe")
if(EXISTS ${imported_location})
add_executable(Qt5::windeployqt IMPORTED)
set_target_properties(Qt5::windeployqt PROPERTIES
IMPORTED_LOCATION ${imported_location}
)
endif()
endif()
else()
message(FATAL_ERROR "Cannot find QT5!")
endif()
endmacro(find_qt5)
# Copies required DLLs to directory with target
# Optionally can provide QML directory as second argument
function(install_qt5_libs target)
if(TARGET Qt5::windeployqt)
set(EXTRA "")
if(EXISTS ${ARGV1})
message("QML directory to be scanned=${ARGV1}")
list(APPEND EXTRA --qmldir ${ARGV1})
endif()
# execute windeployqt in a tmp directory after build
add_custom_command(TARGET ${target}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E remove_directory "${CMAKE_CURRENT_BINARY_DIR}/windeployqt"
COMMAND set PATH=%PATH%$<SEMICOLON>${qt5_install_prefix}/bin
COMMAND Qt5::windeployqt --dir $<TARGET_FILE_DIR:${target}> "$<TARGET_FILE_DIR:${target}>/$<TARGET_FILE_NAME:${target}>" ${EXTRA}
)
endif()
endfunction(install_qt5_libs)

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
build/
Builds/
*.vs/
*.pro.user

View File

@ -1,4 +1,7 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.5)
set(MODULE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/.cmake/Modules")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${MODULE_DIR})
project(NextHooker)
@ -30,3 +33,4 @@ set(CMAKE_CONFIGURATION_TYPES Debug Release)
add_subdirectory(texthook)
add_subdirectory(vnrhook)
add_subdirectory(GUI)

16
GUI/CMakeLists.txt Normal file
View File

@ -0,0 +1,16 @@
include(QtUtils)
msvc_registry_search()
find_qt5(Core Widgets)
# Populate a CMake variable with the sources
set(gui_SRCS
main.cpp
mainwindow.cpp
hostsignaller.cpp
misc.cpp
extensions.cpp
)
add_executable(${PROJECT_NAME} WIN32 ${gui_SRCS})
target_link_libraries(${PROJECT_NAME} Qt5::Widgets vnrhost)
install_qt5_libs(${PROJECT_NAME})

View File

@ -16,7 +16,7 @@ set_target_properties(vnrhost PROPERTIES LINK_FLAGS /SUBSYSTEM:WINDOWS)
target_compile_options(vnrhost PRIVATE
# /GR-
$<$<CONFIG:Release>:/MT>
$<$<CONFIG:Release>:>
$<$<CONFIG:Debug>:>
)

View File

@ -53,7 +53,7 @@ set_target_properties(vnrhook PROPERTIES
target_compile_options(vnrhook PRIVATE
/EHa
$<$<CONFIG:Release>:/MT>
$<$<CONFIG:Release>:>
$<$<CONFIG:Debug>:>
)