11cmake_minimum_required (VERSION  3.16)
22
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" )
64
7- set (QT_MAJOR_VERSION 6)
8- 
9- project (${TARGET_NAME}  VERSION  0.0.1 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 
155set (CMAKE_CXX_STANDARD 20)
166set (CMAKE_CXX_STANDARD_REQUIRED ON )
177
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" )
2110
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)
3015
31- message (STATUS  "Building for ${OS_NAME} " )
16+ # Enable Qt tools 
17+ set (CMAKE_AUTOMOC  ON )
3218
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)
4722
48- # Set Qt path for find_package  
49- set (CMAKE_PREFIX_PATH   ${Qt_DIR} )
23+ # Set Qt version  
24+ set (QT_MAJOR_VERSION 6 )
5025
51- # Find Qt components  
26+ # Find Qt 
5227find_package (Qt${QT_MAJOR_VERSION}  REQUIRED COMPONENTS Core Widgets Test )
5328
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 
5830find_package (yaml-cpp REQUIRED CONFIG)
5931
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- # Ensure YAML config files are copied into macOS app bundle 
94- # if(APPLE) 
95- #     add_custom_command(TARGET ${EXECUTABLE_NAME} POST_BUILD 
96- #         COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_BUNDLE_DIR:${EXECUTABLE_NAME}>/Contents/Resources/config" 
97- #         COMMAND ${CMAKE_COMMAND} -E copy_directory "${YAML_SOURCE_DIR}" "$<TARGET_BUNDLE_DIR:${EXECUTABLE_NAME}>/Contents/Resources/config" 
98- #         COMMENT "Copying YAML config files into macOS app bundle..." 
99- #     ) 
100- # endif() 
101- 
102- # Link the main executable with the CodeAstra library and Qt libraries 
103- target_link_libraries (${EXECUTABLE_NAME}  PRIVATE  ${TARGET_NAME}  Qt${QT_MAJOR_VERSION} ::Core Qt${QT_MAJOR_VERSION} ::Widgets)
104- 
105- # Add the tests subdirectory 
32+ # Add subdirectories 
33+ add_subdirectory (src)
10634add_subdirectory (tests)
10735
108- # Qt resource files 
109- qt_add_resources(APP_RESOURCES resources.qrc)
110- target_sources (${EXECUTABLE_NAME}  PRIVATE  ${APP_RESOURCES} )
111- 
112- # Compiler flags per OS 
113- if (MSVC )
114-     target_compile_options (${EXECUTABLE_NAME}  PRIVATE  /W4 /WX)
115- elseif (APPLE )
116-     target_compile_options (${EXECUTABLE_NAME}  PRIVATE  -Wall -Wextra -pedantic -Werror)
117-     # set_target_properties(${EXECUTABLE_NAME} PROPERTIES MACOSX_BUNDLE TRUE) 
118- else ()
119-     target_compile_options (${EXECUTABLE_NAME}  PRIVATE  -Wall -Wextra -pedantic -Werror)
120- endif ()
121- 
122- # Include directories 
123- target_include_directories (${EXECUTABLE_NAME}  PRIVATE  ${Qt${QT_MAJOR_VERSION} _INCLUDE_DIRS})
124- target_include_directories (${EXECUTABLE_NAME}  PRIVATE  ${CMAKE_SOURCE_DIR} /include )
125- target_include_directories (${TARGET_NAME}  PRIVATE  ${CMAKE_SOURCE_DIR} /include )
126- 
127- # Set output names properly for Debug and Release 
128- set_target_properties (${EXECUTABLE_NAME}  PROPERTIES 
129-     RUNTIME_OUTPUT_DIRECTORY  "${CMAKE_SOURCE_DIR} "  
130-     DEBUG_OUTPUT_NAME  "${EXECUTABLE_NAME} d"  
131-     RELEASE_OUTPUT_NAME  ${EXECUTABLE_NAME} 
132- )
133- 
134- # Link necessary Qt libraries to CodeAstra library 
135- target_link_libraries (${TARGET_NAME}  PRIVATE  Qt${QT_MAJOR_VERSION} ::Core Qt${QT_MAJOR_VERSION} ::Widgets)
136- 
137- # Ensure correct linking of yaml-cpp (macOS) 
138- if (APPLE )
139-     target_include_directories (${EXECUTABLE_NAME}  PRIVATE  /opt/homebrew/include )
140-     target_link_directories (${EXECUTABLE_NAME}  PRIVATE  /opt/homebrew/lib)
141- endif ()
0 commit comments