Skip to content

Instantly share code, notes, and snippets.

@MaxClerkwell
Last active May 14, 2023 13:26
Show Gist options
  • Save MaxClerkwell/487d71c4bef28b98dc0556bb67421f9f to your computer and use it in GitHub Desktop.
Save MaxClerkwell/487d71c4bef28b98dc0556bb67421f9f to your computer and use it in GitHub Desktop.
This is example 1 of the Copperspice-Journal at https://journal.copperspice.com/
#!/bin/bash
cspath="$1/lib/cmake/CopperSpice"
mkdir -p build
cd build
cmake -G "Ninja" \
-DCMAKE_PREFIX_PATH="$cspath" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=../deploy \
..
ninja install
cmake_minimum_required(VERSION 3.16)
project(example_1)
include(CheckCXXCompilerFlag)
include(CheckCXXSourceCompiles)
include(CheckIncludeFile)
include(CheckIncludeFiles)
find_package(CopperSpice REQUIRED)
# file locations for installing
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
include(GNUInstallDirs)
# where libraries are located relative to the executable
set(CMAKE_INSTALL_RPATH "@executable_path/../Resources")
elseif(CMAKE_SYSTEM_NAME MATCHES "(Linux|OpenBSD|FreeBSD)")
include(GNUInstallDirs)
set(CMAKE_INSTALL_RPATH "\$ORIGIN")
elseif(MSVC)
# use defaults
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION .)
include(${CopperSpice_DIR}/InstallMinGW.cmake)
endif()
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_INCLUDE_DIRECTORIES_BEFORE ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 17)
# location for building binary files
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
list(APPEND PROJECT_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
)
add_executable(${PROJECT_NAME} ${PROJECT_SOURCES})
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
target_link_libraries(${PROJECT_NAME}
PRIVATE
netapi32
mpr
-mwindows
)
endif()
target_link_libraries(${PROJECT_NAME}
PRIVATE
CopperSpice::CsCore
CopperSpice::CsGui
)
install(TARGETS ${PROJECT_NAME} DESTINATION .)
cs_copy_library(CsCore)
cs_copy_library(CsGui)
# installs the platform Gui plugin
cs_copy_plugins(CsGui)
#include <QtCore>
#include <QtGui>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget *mainWindow = new QWidget();
mainWindow->setMinimumSize(700, 350);
QPushButton *pb = new QPushButton();
pb->setText("Close");
QHBoxLayout *layout = new QHBoxLayout(mainWindow);
layout->addWidget(pb);
QObject::connect(pb, &QPushButton::clicked,
mainWindow, &QWidget::close);
mainWindow->show();
return app.exec();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment