|
1 | 1 | cmake_minimum_required(VERSION 3.16) |
2 | 2 |
|
3 | | -# Project name |
4 | | -set(TARGET_NAME CodeAstraApp) |
5 | | -set(EXECUTABLE_NAME CodeAstra) |
| 3 | +project(CodeAstra VERSION 0.1.0 DESCRIPTION "Code Editor written in modern C++ using Qt6") |
6 | 4 |
|
7 | | -set(QT_MAJOR_VERSION 6) |
8 | | - |
9 | | -project(${TARGET_NAME} VERSION 0.1.0 DESCRIPTION "Code Editor written in C++ using Qt6") |
10 | | - |
11 | | -# Enable automatic MOC (Meta-Object Compiler) handling for Qt |
12 | | -set(CMAKE_AUTOMOC ON) |
13 | | - |
14 | | -# Set the CXX standard |
15 | 5 | set(CMAKE_CXX_STANDARD 20) |
16 | 6 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
17 | 7 |
|
18 | | -# Set default build output directories |
19 | | -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}) |
20 | | -set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}) |
| 8 | +# Use cmake/ for custom modules |
| 9 | +list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") |
21 | 10 |
|
22 | | -# Detect operating system |
23 | | -if(WIN32) |
24 | | - set(OS_NAME "Windows") |
25 | | -elseif(APPLE) |
26 | | - set(OS_NAME "macOS") |
27 | | -else() |
28 | | - set(OS_NAME "Linux") |
29 | | -endif() |
| 11 | +# Set output directories |
| 12 | +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) |
| 13 | +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 14 | +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
30 | 15 |
|
31 | | -message(STATUS "Building for ${OS_NAME}") |
| 16 | +# Enable Qt tools |
| 17 | +set(CMAKE_AUTOMOC ON) |
32 | 18 |
|
33 | | -# Locate Qt installation |
34 | | -if(DEFINED ENV{Qt${QT_MAJOR_VERSION}_HOME}) |
35 | | - set(Qt_DIR "$ENV{Qt${QT_MAJOR_VERSION}_HOME}") |
36 | | - message(STATUS "Using Qt from: ${Qt_DIR}") |
37 | | -else() |
38 | | - if(WIN32) |
39 | | - set(Qt_DIR "C:/Qt/${QT_MAJOR_VERSION}/msvc2022_64/lib/cmake/Qt${QT_MAJOR_VERSION}") |
40 | | - elseif(APPLE) |
41 | | - set(Qt_DIR "/usr/local/opt/qt/lib/cmake/Qt${QT_MAJOR_VERSION}") |
42 | | - else() |
43 | | - set(Qt_DIR "/usr/lib/cmake/Qt${QT_MAJOR_VERSION}") |
44 | | - endif() |
45 | | - message(STATUS "Using default Qt path: ${Qt_DIR}") |
46 | | -endif() |
| 19 | +# Define target names |
| 20 | +set(TARGET_NAME CodeAstra) |
| 21 | +set(EXECUTABLE_NAME ${TARGET_NAME}App) |
47 | 22 |
|
48 | | -# Set Qt path for find_package |
49 | | -set(CMAKE_PREFIX_PATH ${Qt_DIR}) |
| 23 | +# Set Qt version |
| 24 | +set(QT_MAJOR_VERSION 6) |
50 | 25 |
|
51 | | -# Find Qt components |
| 26 | +# Find Qt |
52 | 27 | find_package(Qt${QT_MAJOR_VERSION} REQUIRED COMPONENTS Core Widgets Test) |
53 | 28 |
|
54 | | -# Locate yaml-cpp |
55 | | -if(APPLE) |
56 | | - set(yaml-cpp_DIR "/opt/homebrew/Cellar/yaml-cpp/0.8.0/lib/cmake/yaml-cpp") |
57 | | -endif() |
| 29 | +# yaml-cpp |
58 | 30 | find_package(yaml-cpp REQUIRED CONFIG) |
59 | 31 |
|
60 | | -# Copy YAML files to the build directory (non-macOS case) |
61 | | -set(YAML_SOURCE_DIR ${CMAKE_SOURCE_DIR}/config) |
62 | | -set(YAML_DEST_DIR ${CMAKE_BINARY_DIR}/config) |
63 | | -file(MAKE_DIRECTORY ${YAML_DEST_DIR}) |
64 | | -file(GLOB YAML_FILES "${YAML_SOURCE_DIR}/*.yaml") |
65 | | - |
66 | | -foreach(YAML_FILE ${YAML_FILES}) |
67 | | - file(COPY ${YAML_FILE} DESTINATION ${YAML_DEST_DIR}) |
68 | | -endforeach() |
69 | | - |
70 | | -# Create the CodeAstra library |
71 | | -add_library(${TARGET_NAME} |
72 | | - src/MainWindow.cpp |
73 | | - src/CodeEditor.cpp |
74 | | - src/Tree.cpp |
75 | | - src/FileManager.cpp |
76 | | - src/Syntax.cpp |
77 | | - src/SyntaxManager.cpp |
78 | | - include/MainWindow.h |
79 | | - include/CodeEditor.h |
80 | | - include/Tree.h |
81 | | - include/LineNumberArea.h |
82 | | - include/FileManager.h |
83 | | - include/SyntaxManager.h |
84 | | - include/Syntax.h |
85 | | -) |
86 | | - |
87 | | -# Link YAML-CPP to the CodeAstra library |
88 | | -target_link_libraries(${TARGET_NAME} PRIVATE yaml-cpp) |
89 | | - |
90 | | -# Create the executable for the application |
91 | | -add_executable(${EXECUTABLE_NAME} src/main.cpp) |
92 | | - |
93 | | -# Link the main executable with the CodeAstra library and Qt libraries |
94 | | -target_link_libraries(${EXECUTABLE_NAME} PRIVATE ${TARGET_NAME} Qt${QT_MAJOR_VERSION}::Core Qt${QT_MAJOR_VERSION}::Widgets) |
95 | | - |
96 | | -# Add the tests subdirectory |
| 32 | +# Add subdirectories |
| 33 | +add_subdirectory(src) |
97 | 34 | add_subdirectory(tests) |
98 | 35 |
|
99 | | -# Qt resource files |
100 | | -qt_add_resources(APP_RESOURCES resources.qrc) |
101 | | -target_sources(${EXECUTABLE_NAME} PRIVATE ${APP_RESOURCES}) |
102 | | - |
103 | | -# Compiler flags per OS |
104 | | -if(MSVC) |
105 | | - target_compile_options(${EXECUTABLE_NAME} PRIVATE /W4 /WX /analyze /sdl /guard:cf) |
106 | | -elseif(APPLE) |
107 | | - target_compile_options(${EXECUTABLE_NAME} PRIVATE -Wall -Wextra -Wpedantic -Werror -Wshadow -Wconversion -Wsign-conversion -fsanitize=address,undefined -fstack-protector) |
108 | | - target_link_libraries(${EXECUTABLE_NAME} PRIVATE -fsanitize=address,undefined) |
109 | | - # set_target_properties(${EXECUTABLE_NAME} PROPERTIES MACOSX_BUNDLE TRUE) |
110 | | -else() |
111 | | - target_compile_options(${EXECUTABLE_NAME} PRIVATE -Wall -Wextra -Wpedantic -Werror -Wshadow -Wconversion -Wsign-conversion -fsanitize=address,undefined -fstack-protector) |
112 | | - target_link_libraries(${EXECUTABLE_NAME} PRIVATE -fsanitize=address,undefined) |
113 | | -endif() |
114 | | - |
115 | | -# Include directories |
116 | | -target_include_directories(${EXECUTABLE_NAME} PRIVATE ${Qt${QT_MAJOR_VERSION}_INCLUDE_DIRS}) |
117 | | -target_include_directories(${EXECUTABLE_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/include) |
118 | | -target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/include) |
119 | | - |
120 | | -# Set output names properly for Debug and Release |
121 | | -set_target_properties(${EXECUTABLE_NAME} PROPERTIES |
122 | | - RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}" |
123 | | - DEBUG_OUTPUT_NAME "${EXECUTABLE_NAME}d" |
124 | | - RELEASE_OUTPUT_NAME ${EXECUTABLE_NAME} |
125 | | -) |
126 | | - |
127 | | -# Link necessary Qt libraries to CodeAstra library |
128 | | -target_link_libraries(${TARGET_NAME} PRIVATE Qt${QT_MAJOR_VERSION}::Core Qt${QT_MAJOR_VERSION}::Widgets) |
129 | | - |
130 | | -# Ensure correct linking of yaml-cpp (macOS) |
131 | | -if(APPLE) |
132 | | - target_include_directories(${EXECUTABLE_NAME} PRIVATE /opt/homebrew/include) |
133 | | - target_link_directories(${EXECUTABLE_NAME} PRIVATE /opt/homebrew/lib) |
134 | | -endif() |
0 commit comments