-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
109 lines (99 loc) · 3.88 KB
/
Copy pathCMakeLists.txt
File metadata and controls
109 lines (99 loc) · 3.88 KB
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
cmake_minimum_required(VERSION 3.16)
project(cnh)
set(CNH_BINARY_DEST "bin")
if (WIN32)
# set(CMAKE_INSTALL_PREFIX "c:/program files/")
set(CNH_BINARY_DEST "cnh")
endif (WIN32)
message(STATUS "CNH_BINARY_DEST is set to: ${CNH_BINARY_DEST}")
# set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# Enable compiler warnings to catch potential bugs early
if(MSVC)
# MSVC warning levels
add_compile_options(/W4) # Warning level 4 (highest)
else()
# GCC/Clang warning flags for maximum code quality checks
add_compile_options(-Wall -Wextra -Wpedantic -Wconversion)
# Optionally treat warnings as errors (uncomment to enforce)
# add_compile_options(-Werror)
endif()
set(CONFIG_H ${CMAKE_BINARY_DIR}/config.h)
string(TIMESTAMP CURRENT_TIMESTAMP)
file(WRITE ${CONFIG_H} "/* WARNING: This file is auto-generated by CMake on ${CURRENT_TIMESTAMP}. DO NOT EDIT!!! */\n\n")
include_directories(headers ${CMAKE_BINARY_DIR} )
# Since we have created a config.h add a global define for it
add_definitions("-DHAVE_CONFIG_H")
add_subdirectory(src)
add_subdirectory(tests)
# install(DIRECTORY "extdata/"
# DESTINATION "${CMAKE_INSTALL_PREFIX}/cnh"
# FILES_MATCHING PATTERN *.tpl)
# install(FILES "extdata/InlineComments.txt" "extdata/lang.dat"
# DESTINATION "${CMAKE_INSTALL_PREFIX}/cnh")
# install(DIRECTORY "templates/"
# DESTINATION "${CMAKE_INSTALL_PREFIX}/cnh_templates"
# FILES_MATCHING PATTERN *.tpl)
# install(TARGETS cnh
# DESTINATION ${CNH_BINARY_DEST})
install(DIRECTORY "extdata/"
DESTINATION "share/cnh/cnh"
FILES_MATCHING PATTERN *.tpl)
install(FILES "extdata/InlineComments.txt" "extdata/lang.dat"
DESTINATION "share/cnh/cnh")
install(DIRECTORY "templates/"
DESTINATION "share/cnh/cnh_templates"
FILES_MATCHING PATTERN *.tpl)
install(TARGETS cnh
RUNTIME DESTINATION "bin"
)
message(STATUS "CMAKE_INSTALL_PREFIX is set to: ${CMAKE_INSTALL_PREFIX}")
# Set package metadata
set(CPACK_PACKAGE_NAME "CodeNowHere")
set(CPACK_PACKAGE_VERSION "3.0.0") # Replace with your versioning logic
set(CPACK_PACKAGE_CONTACT "sergiop18@gmail.com")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE")
# Set platform-specific settings
if(WIN32)
set(CPACK_GENERATOR "NSIS") # Use NSIS for Windows
set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "
WriteRegStr HKCU \\\"Environment\\\" \\\"CNH_TEMPLATES\\\" \\\"$INSTDIR\\\\share\\\\cnh\\\\cnh_templates\\\"
")
set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "
DeleteRegValue HKCU \\\"Environment\\\" \\\"CNH_TEMPLATES\\\"
")
set(CPACK_PACKAGE_FILE_NAME "cnh-windows-${CPACK_PACKAGE_VERSION}")
elseif(APPLE)
set(CPACK_GENERATOR "DragNDrop") # Use DragNDrop for macOS
set(CPACK_POSTFLIGHT_SCRIPT "${CMAKE_BINARY_DIR}/postinstall.sh")
file(WRITE ${CMAKE_BINARY_DIR}/postinstall.sh
"#!/bin/sh\n"
"echo 'export CNH_TEMPLATES=\"/Library/Application Support/cnh/cnh_templates\"' >> ~/.bash_profile\n"
)
set(CPACK_PACKAGE_FILE_NAME "cnh-macos-${CPACK_PACKAGE_VERSION}")
else()
set(CPACK_GENERATOR "DEB") # Use DEB for Linux
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_BINARY_DIR}/postinst")
file(WRITE ${CMAKE_BINARY_DIR}/postinst
"#!/bin/sh
set -e
echo 'export CNH_TEMPLATES=/usr/share/cnh/cnh_templates' > /etc/profile.d/cnh.sh
chmod 644 /etc/profile.d/cnh.sh"
)
set(CPACK_PACKAGE_FILE_NAME "cnh-linux-${CPACK_PACKAGE_VERSION}")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Sergio Ortiz Paz") # Required for DEB
endif()
# Enable CPack
include(CPack)
# uninstall target
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
COMMENT "Uninstalling files installed by 'make install'"
)
endif()