forked from pit-ray/win-vind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
157 lines (132 loc) · 5.27 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
cmake_minimum_required(VERSION 3.6.0)
project(win-vind VERSION 4.3.2)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
if(NOT BIT_TYPE)
set(BIT_TYPE 64)
endif()
option(CCACHE_ENABLE ON)
enable_language(CXX)
if(${MSVC})
add_compile_options(/W4 /std:c++17 /MT /D_UNICODE /DUNICODE /utf-8)
if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
add_compile_options(/DEBUG)
add_compile_options(/DDEBUG)
elseif(${CMAKE_BUILD_TYPE} STREQUAL "Release")
add_compile_options(/O2)
endif()
else()
if(NOT WINDOWS_SDK_INCLUDE_DIR)
get_filename_component(WINDOWS_SDK_ROOT_DIR
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot10]" REALPATH)
file(GLOB WINDOWS_SDK_INCS LIST_DIRECTORIES true "${WINDOWS_SDK_ROOT_DIR}/Include/10.0.*.*")
list(SORT WINDOWS_SDK_INCS ORDER DESCENDING)
list(GET WINDOWS_SDK_INCS 0 WINDOWS_SDK_INCLUDE_DIR)
endif()
if(NOT EXISTS ${WINDOWS_SDK_INCLUDE_DIR})
message(FATAL_ERROR "Could not find the directory; ${WINDOWS_SDK_INCLUDE_DIR}."
"You can fix by the cmake flag; -DWINDOWS_SDK_INCLUDE_DIR=<Path>")
endif()
message(STATUS "Detected Windows SDK: ${WINDOWS_SDK_INCLUDE_DIR}")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_FLAGS
-static
-std=c++17
-lstdc++
-lstdc++fs
-lgcc
-Wall
-Wextra
-Wcast-align
-Wno-unknown-pragmas
-Wcast-qual
-Wctor-dtor-privacy
-Wdelete-non-virtual-dtor
-Wdouble-promotion
-Weffc++
-Wold-style-cast
-Woverloaded-virtual
-Wreorder
-Wshadow
-Wsuggest-override
-Wuseless-cast
-fdiagnostics-color
-DUNICODE
-D_UNICODE
-Wl,--allow-multiple-definition #UUID of wxWidgets and one of MinGW
-DWINVER=0x0A00
-D_WIN32_WINNT=0x0A00
-Wa,-mbig-obj
--coverage
)
list(REMOVE_DUPLICATES CMAKE_CXX_FLAGS)
string(REPLACE ";" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
if(${BIT_TYPE} STREQUAL 32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64")
endif()
if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g3 -DDEBUG")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
endif()
message(STATUS "g++ flags: ${CMAKE_CXX_FLAGS}")
set(CMAKE_SH "CMAKE_SH-NOTFOUND")
endif()
include(ProcessorCount)
ProcessorCount(PROC_N)
message(STATUS "The number of processors: " ${PROC_N})
set(CMAKE_MAKE_PROGRAM "${CMAKE_MAKE_PROGRAM} -j ${PROC_N}")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake_modules)
find_program(CCACHE ccache)
if(CCACHE)
if(${CCACHE_ENABLE})
if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
message(STATUS "Enable ccache")
if(CMAKE_CXX_COMPILER_LAUNCHER)
set(CMAKE_CXX_COMPILER_LAUNCHER "${CMAKE_CXX_COMPILER_LAUNCHER}" "${CCACHE}")
else()
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE}")
endif()
endif()
endif()
endif()
add_subdirectory(src)
#CPack-----------------------------------------------------------------------------
install(TARGETS win-vind RUNTIME DESTINATION .)
install(DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/res/resources
${CMAKE_CURRENT_SOURCE_DIR}/res/default_config
DESTINATION .
)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
set(CPACK_GENERATOR NSIS)
set(CPACK_PACKAGE_NAME ${CPACK_PROJECT_NAME})
set(CPACK_PACKAGE_VERSION ${CPACK_PROJECT_VERSION})
set(CPACK_PACKAGE_VENDOR "pit-ray")
set(CPACK_PACKAGE_COPYRIGHT "Copyright (c) 2020-2022 pit-ray")
set(CPACK_PACKAGE_DESCRIPTION "win-vind - Simple Vim Key Binder for Windows (${BIT_TYPE}-bit)")
set(CPACK_PACKAGE_HOMEPAGE_URL "https://pit-ray.github.io/win-vind/")
set(CPACK_PACKAGE_FILE_NAME "setup_${CPACK_PROJECT_NAME}_${CPACK_PROJECT_VERSION}")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "win-vind")
set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}/res/installer/installer512.ico")
set(CPACK_NSIS_MUI_UNIICON "${CMAKE_CURRENT_SOURCE_DIR}/res/installer/uninstaller512.ico")
set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PROJECT_NAME})
set(CPACK_COMPONENT_APPLICATIONS_DISPLAY_NAME "applications (${CPACK_PROJECT_NAME})")
set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL TRUE)
set(CPACK_NSIS_PACKAGE_NAME ${PRODUCT_NAME})
set(CPACK_NSIS_PACKAGE_VERSION ${CPACK_PROJECT_VERSION}.0)
# Register to startmenu
list(APPEND CPACK_NSIS_EXTRA_INSTALL_COMMANDS "CreateShortCut '$SMPROGRAMS\\\\${CPACK_PACKAGE_NAME}\\\\${CPACK_PACKAGE_NAME}.lnk' '$INSTDIR\\\\${CPACK_PACKAGE_NAME}.exe'")
string(REPLACE ";" "\n" CPACK_NSIS_EXTRA_INSTALL_COMMANDS "${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}")
list(APPEND CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "Delete '$SMPROGRAMS\\\\${CPACK_PACKAGE_NAME}\\\\${CPACK_PACKAGE_NAME}.lnk'")
string(REPLACE ";" "\n" CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "${CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS}")
include(CPack)