Skip to content

Commit b4bfb56

Browse files
committed
separate GUI and CLI builds in CMake
1 parent b136b43 commit b4bfb56

File tree

8 files changed

+134
-81
lines changed

8 files changed

+134
-81
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
# /buildtools/clang+llvm-*-x86_64-pc-windows-msvc/
1010
# /buildtools/build/
1111
/thirdparty/qt/qt/
12+
/.dep-cache/

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ set(CMAKE_CXX_EXTENSIONS OFF)
1313
## proj src dir is location of this file
1414
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
1515

16+
# # Cache FetchContent downloads outside build directory
17+
# set(FETCHCONTENT_BASE_DIR "${CMAKE_BINARY_DIR}/../.depcache" CACHE PATH "FetchContent cache directory")
18+
1619
include(CompileCommands)
1720
include(DefaultBuildType)
1821
include(DefaultInstallPath)

cesium.code-workspace

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"**/node_modules/**": true,
2222
"**/.cache/**": true,
2323
"**/.git/**": true,
24+
"**/.dep-cache/**": true,
2425
// "thirdparty/qt/qt/**": true,
2526
},
2627
"files.exclude": {
@@ -97,20 +98,4 @@
9798
}
9899
]
99100
},
100-
// "tasks": {
101-
// "version": "2.0.0",
102-
// "tasks": [
103-
// {
104-
// "type": "cmake",
105-
// "label": "CMake: build",
106-
// "command": "build",
107-
// "targets": [ "all" ],
108-
// "group": {
109-
// "isDefault": true,
110-
// "kind": "build"
111-
// },
112-
// "detail": "Builds all targets."
113-
// }
114-
// ]
115-
// }
116101
}

cesium/CMakeLists.txt

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
qt_standard_project_setup()
2-
qt_add_executable(cesium)
3-
set_target_properties(cesium PROPERTIES
4-
WIN32_EXECUTABLE ON
5-
MACOSX_BUNDLE ON
6-
)
7-
8-
# add_executable(cesium) # WIN32)
1+
add_executable(cesium)
92
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT cesium)
103

114
# Set output directory to build/bin
@@ -37,33 +30,20 @@ endif()
3730
# Clang-specific flags
3831
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
3932
target_compile_options(cesium PRIVATE -Wno-unused-parameter)
40-
# Fix lld-link warning about multiple entry points
41-
if(WIN32)
42-
target_link_options(cesium PRIVATE -Xlinker /ENTRY:wWinMainCRTStartup)
43-
endif()
33+
# # Fix lld-link warning about multiple entry points
34+
# if(WIN32)
35+
# target_link_options(cesium PRIVATE -Xlinker /ENTRY:wWinMainCRTStartup)
36+
# endif()
4437
endif()
4538

4639
target_link_libraries(cesium
4740
PRIVATE
4841
${CMAKE_DL_LIBS} # For dlopen/dlsym on Unix systems
49-
Qt6::Core
50-
Qt6::Widgets
5142
yyjson
5243
tree-sitter-core
5344
tree-sitter-cpp
5445
)
5546

56-
# Deploy Qt libraries after build (for debug/development)
57-
if(WIN32)
58-
find_program(WINDEPLOYQT_EXECUTABLE windeployqt HINTS ${QT6_INSTALL_PREFIX}/bin)
59-
if(WINDEPLOYQT_EXECUTABLE)
60-
add_custom_command(TARGET cesium POST_BUILD
61-
COMMAND ${WINDEPLOYQT_EXECUTABLE} --debug --no-translations --no-system-d3d-compiler $<TARGET_FILE:cesium>
62-
COMMENT "Deploying Qt libraries"
63-
)
64-
endif()
65-
endif()
66-
6747
# Installation rules
6848
install(TARGETS cesium
6949
RUNTIME DESTINATION bin
@@ -73,3 +53,4 @@ install(TARGETS cesium
7353

7454
add_subdirectory(src)
7555
add_subdirectory(include)
56+
add_subdirectory(gui)

cesium/gui/CMakeLists.txt

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
qt_standard_project_setup()
2+
qt_add_executable(cesium-gui gui.cpp)
3+
set_target_properties(cesium-gui PROPERTIES
4+
WIN32_EXECUTABLE ON
5+
MACOSX_BUNDLE ON
6+
)
7+
# set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT cesium-gui)
8+
9+
# Set output directory to build/bin
10+
set_target_properties(cesium-gui PROPERTIES
11+
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
12+
# RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/bin"
13+
# RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/bin"
14+
)
15+
16+
# Compiler warnings (all platforms)
17+
target_compile_options(cesium-gui PRIVATE -Wall -Wextra -Wpedantic)
18+
19+
# Platform-specific settings
20+
if(WIN32)
21+
target_compile_definitions(cesium-gui PRIVATE
22+
_WIN32_WINNT=0x0601
23+
WIN32_LEAN_AND_MEAN
24+
)
25+
elseif(APPLE)
26+
# macOS-specific settings
27+
elseif(UNIX)
28+
# Linux-specific settings
29+
endif()
30+
31+
# Clang-specific flags
32+
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
33+
target_compile_options(cesium-gui PRIVATE -Wno-unused-parameter)
34+
# Fix lld-link warning about multiple entry points
35+
if(WIN32)
36+
target_link_options(cesium-gui PRIVATE -Xlinker /ENTRY:wWinMainCRTStartup)
37+
endif()
38+
endif()
39+
40+
target_link_libraries(cesium-gui
41+
PRIVATE
42+
${CMAKE_DL_LIBS} # For dlopen/dlsym on Unix systems
43+
Qt6::Core
44+
Qt6::Widgets
45+
)
46+
47+
# Deploy Qt libraries after build (for debug/development)
48+
if(WIN32)
49+
set(TMP_DEPLOY_TOOL windeployqt)
50+
elseif(APPLE)
51+
set(TMP_DEPLOY_TOOL macdeployqt)
52+
endif()
53+
set(DEPLOY_TOOL "$<TARGET_NAME_IF_EXISTS:Qt6::${TMP_DEPLOY_TOOL}>")
54+
set(DEPLOY_TOOL_FALLBACK ${TMP_DEPLOY_TOOL})
55+
56+
if(WIN32 OR APPLE)
57+
add_custom_command(TARGET cesium-gui POST_BUILD
58+
COMMAND $<IF:$<BOOL:${DEPLOY_TOOL}>,$<TARGET_FILE:${DEPLOY_TOOL}>,${DEPLOY_TOOL_FALLBACK}>
59+
--debug --no-translations $<TARGET_FILE:cesium-gui>
60+
COMMENT "Deploying Qt application"
61+
)
62+
endif()
63+
64+
# Installation rules
65+
install(TARGETS cesium-gui
66+
RUNTIME DESTINATION bin
67+
LIBRARY DESTINATION lib
68+
ARCHIVE DESTINATION lib
69+
)
70+
71+
# add_subdirectory(src)
72+
# add_subdirectory(include)

cesium/gui/gui.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include <QApplication>
2+
#include <QWidget>
3+
#include <QVBoxLayout>
4+
#include <QLabel>
5+
#include <QPushButton>
6+
#include <QMessageBox>
7+
#include <iostream>
8+
9+
int main(int argc, char *argv[])
10+
{
11+
std::cout << "Hello from Cesium!" << std::endl;
12+
// return 0;
13+
14+
QApplication app(argc, argv);
15+
16+
// Create main window
17+
QWidget window;
18+
window.setWindowTitle("Cesium Qt Hello World");
19+
window.resize(300, 200);
20+
21+
// Create layout and widgets
22+
QVBoxLayout *layout = new QVBoxLayout;
23+
24+
QLabel *label = new QLabel("Hello from Cesium with Qt!");
25+
label->setAlignment(Qt::AlignCenter);
26+
27+
QPushButton *button = new QPushButton("Click me!");
28+
29+
// Connect button click to show message
30+
QObject::connect(button, &QPushButton::clicked, [&]() {
31+
QMessageBox::information(&window, "Hello", "Button clicked in Cesium Qt app!");
32+
});
33+
34+
// Add widgets to layout
35+
layout->addWidget(label);
36+
layout->addWidget(button);
37+
38+
// Set layout to window
39+
window.setLayout(layout);
40+
41+
// Show window
42+
window.show();
43+
44+
return app.exec();
45+
}

cesium/src/main.cpp

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,7 @@
1-
#include <QApplication>
2-
#include <QWidget>
3-
#include <QVBoxLayout>
4-
#include <QLabel>
5-
#include <QPushButton>
6-
#include <QMessageBox>
71
#include <iostream>
82

93
int main(int argc, char *argv[])
104
{
115
std::cout << "Hello from Cesium!" << std::endl;
12-
// return 0;
13-
14-
QApplication app(argc, argv);
15-
16-
// Create main window
17-
QWidget window;
18-
window.setWindowTitle("Cesium Qt Hello World");
19-
window.resize(300, 200);
20-
21-
// Create layout and widgets
22-
QVBoxLayout *layout = new QVBoxLayout;
23-
24-
QLabel *label = new QLabel("Hello from Cesium with Qt!");
25-
label->setAlignment(Qt::AlignCenter);
26-
27-
QPushButton *button = new QPushButton("Click me!");
28-
29-
// Connect button click to show message
30-
QObject::connect(button, &QPushButton::clicked, [&]() {
31-
QMessageBox::information(&window, "Hello", "Button clicked in Cesium Qt app!");
32-
});
33-
34-
// Add widgets to layout
35-
layout->addWidget(label);
36-
layout->addWidget(button);
37-
38-
// Set layout to window
39-
window.setLayout(layout);
40-
41-
// Show window
42-
window.show();
43-
44-
return app.exec();
6+
return 0;
457
}

cmake/ConfigFetchContent.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
set(FETCHCONTENT_QUIET FALSE CACHE BOOL "Suppress output from FetchContent" FORCE)
2+
3+
# Cache FetchContent downloads outside build directory
4+
set(FETCHCONTENT_BASE_DIR "${CMAKE_BINARY_DIR}/../.dep-cache" CACHE PATH "FetchContent cache directory")
5+
16
# Include FetchContent for external dependencies
27
include(FetchContent)
3-
set(FETCHCONTENT_QUIET FALSE CACHE BOOL "Suppress output from FetchContent" FORCE)

0 commit comments

Comments
 (0)