-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
171 lines (150 loc) · 5.92 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
cmake_minimum_required(VERSION 3.11)
if (${CMAKE_VERSION} VERSION_GREATER "3.20")
cmake_policy(SET CMP0115 NEW)
endif()
project(mynotepad)
set(PROJECT_HOMEPAGE_URL "https://github.com/mooction/MyNotePad")
set(PROJECT_DESCRIPTION "A markdown editor supports exporting HTML.")
set(PROJECT_COPYRIGHT "Copyright (C) 2021")
set(PROJECT_VERSION_MAJOR 1)
set(PROJECT_VERSION_MINOR 0)
set(PROJECT_VERSION_PATCH 7)
message(STATUS "MyNotePad version: ${PROJECT_VERSION_MAJOR}.\
${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG")
if (UNIX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# set(CMAKE_CXX_COMPILER clang++)
# string(CONCAT CMAKE_CXX_FLAGS
# "-stdlib=libstdc++ " # Do not use libc++ as wxWidgets libraries are precompiled
# )
# Set build type and flags
string(CONCAT CMAKE_CXX_FLAGS_DEBUG
"-Wall " # Display all warnings
"-g " # With debug information
"-O0 " # No optimize
)
string(CONCAT CMAKE_CXX_FLAGS_RELEASE
"-O3 " # Enable optimize
)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
endif()
configure_file(
"${PROJECT_SOURCE_DIR}/inc/config.h.in"
"${PROJECT_BINARY_DIR}/inc/config.h"
)
if (UNIX)
configure_file(
"${PROJECT_SOURCE_DIR}/static/mynotepad.desktop.in"
"${PROJECT_SOURCE_DIR}/static/mynotepad.desktop"
)
# find_package(PkgConfig REQUIRED)
# pkg_check_modules(GTK gtk+-3.0 REQUIRED)
# include_directories(${GTK_INCLUDE_DIRS})
# message(STATUS "GTK headers: ${GTK_INCLUDE_DIRS}")
# message(STATUS "GTK libraries: ${GTK_LIBRARIES}")
# set(EXTRA_LIBS ${EXTRA_LIBS} ${GTK_LIBRARIES})
else()
configure_file(
"${PROJECT_SOURCE_DIR}/static/wx.rc.in"
"${PROJECT_SOURCE_DIR}/static/wx.rc"
)
endif()
set(wxWidgets_CONFIGURATION mswu) # or mswud
# Find wxWidgets
find_package(wxWidgets COMPONENTS core base stc REQUIRED)
message(STATUS "wxWidgets version: ${wxWidgets_VERSION_MAJOR}."
"${wxWidgets_VERSION_MINOR}.${wxWidgets_VERSION_PATCH}")
include(${wxWidgets_USE_FILE})
set(EXTRA_LIBS ${EXTRA_LIBS} ${wxWidgets_LIBRARIES})
# Define header directory
include_directories(
"${PROJECT_BINARY_DIR}/inc"
"${PROJECT_SOURCE_DIR}/inc"
"${PROJECT_SOURCE_DIR}/static"
"${PROJECT_SOURCE_DIR}/md2html/inc"
)
# Define source directory
aux_source_directory(src SOURCES)
if (WIN32)
# add resource file for Windows
list(APPEND SOURCES "static/wx.rc")
list(APPEND SOURCES "static/mynotepad.manifest")
endif()
# Target executable file
set(TARGET mynotepad)
add_executable(${TARGET} WIN32 ${SOURCES})
# Markdown to HTML converter
option(USE_EXTERNAL_MD2HTML "Use external library to convert markdown to HTML" OFF)
if (USE_EXTERNAL_MD2HTML)
include(FetchContent)
FetchContent_Declare(maddy
GIT_REPOSITORY https://github.com/progsource/maddy.git
GIT_TAG f3d934d6ec70bd4c077acfb810026d5f15e11001
)
FetchContent_GetProperties(maddy)
if (NOT maddy_POPULATED)
FetchContent_Populate(maddy)
# Do not add_subdirectory() because we only want the header files
include_directories("${maddy_SOURCE_DIR}/include")
endif()
add_definitions("-DUSE_EXTERNAL_MD2HTML")
else()
add_subdirectory(md2html)
set(EXTRA_LIBS ${EXTRA_LIBS} md2html)
endif()
# Link libraries
target_link_libraries(${TARGET} ${EXTRA_LIBS})
if (WIN32)
set(WXVER "${wxWidgets_VERSION_MAJOR}${wxWidgets_VERSION_MINOR}${wxWidgets_VERSION_PATCH}")
# Required DLLs on Windows
set(ALL_DLLS_DEBUG
"${wxWidgets_LIB_DIR}/wxbase${WXVER}ud_vc14x_x64.dll"
"${wxWidgets_LIB_DIR}/wxbase${WXVER}ud_net_vc14x_x64.dll"
"${wxWidgets_LIB_DIR}/wxbase${WXVER}ud_xml_vc14x_x64.dll"
"${wxWidgets_LIB_DIR}/wxmsw${WXVER}ud_core_vc14x_x64.dll"
"${wxWidgets_LIB_DIR}/wxmsw${WXVER}ud_stc_vc14x_x64.dll"
)
set(ALL_DLLS_RELEASE
"${wxWidgets_LIB_DIR}/wxbase${WXVER}u_vc14x_x64.dll"
"${wxWidgets_LIB_DIR}/wxbase${WXVER}u_net_vc14x_x64.dll"
"${wxWidgets_LIB_DIR}/wxbase${WXVER}u_xml_vc14x_x64.dll"
"${wxWidgets_LIB_DIR}/wxmsw${WXVER}u_core_vc14x_x64.dll"
"${wxWidgets_LIB_DIR}/wxmsw${WXVER}u_stc_vc14x_x64.dll"
)
set(ALL_DLLS $<$<CONFIG:Debug>:${ALL_DLLS_DEBUG}>$<$<CONFIG:Release>:${ALL_DLLS_RELEASE}>)
set(STATIC_RESOURCES
"${PROJECT_SOURCE_DIR}/static/highlight.css"
"${PROJECT_SOURCE_DIR}/static/highlight.pack.js"
"${PROJECT_SOURCE_DIR}/static/style.css"
"${PROJECT_SOURCE_DIR}/static/logo.png"
"${PROJECT_SOURCE_DIR}/static/mynotepad.visualelementsmanifest.xml"
)
add_custom_command(TARGET ${TARGET} POST_BUILD
COMMAND_EXPAND_LISTS
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${ALL_DLLS}" "${PROJECT_BINARY_DIR}/"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${STATIC_RESOURCES}" "${PROJECT_BINARY_DIR}/"
COMMENT "Copying DLLs" VERBATIM
)
elseif (UNIX)
# Default path is /usr/local/
message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
# Install the program after build, /usr/local/bin/
install(TARGETS ${TARGET} RUNTIME DESTINATION bin)
# Copy dependent files while installing, default path is /usr/local/share
install(DIRECTORY "${PROJECT_SOURCE_DIR}/static/"
DESTINATION "share/${PROJECT_NAME}"
# Make the files writable
FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ GROUP_WRITE WORLD_READ WORLD_WRITE
FILES_MATCHING PATTERN "*.css" PATTERN "*.js" PATTERN "*.png"
)
# Create desktop icon
install(FILES "${PROJECT_SOURCE_DIR}/static/mynotepad.desktop"
DESTINATION /usr/share/applications
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
)
endif()