Skip to content

Commit

Permalink
CMake Packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
rerdavies committed Jan 27, 2025
1 parent 0e4cefc commit 7706a12
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 91 deletions.
38 changes: 34 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
cmake_minimum_required(VERSION 3.16.0)
project(monitor_gpu
project(nwindows
VERSION 0.0.1
DESCRIPTION "Monitor CPU and GPU clock speeds."
DESCRIPTION "Modern Text User Interface Library for C++."
HOMEPAGE_URL "https://rerdavies.github.io/nwindows/"
LANGUAGES CXX
)

set(CMAKE_CXX_STANDARD 20)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(NWINDOWS_BUILD_DOCUMENTATION ON CACHE BOOL "Build the Vite Documentation website?")
set(NWINDOWS_BUILD_EXAMPLES ON CACHE BOOL "Build the exmaple projects?")
# Set to ON if you wish to set compler options froma parent CMakeList.txt file.
set(NWINDOWS_DEFAULT_COMPILER_OPTIONS OFF CACHE BOOL "Use default compiler options?")



if (NOT NWINDOWS_DEFAULT_COMPILER_OPTIONS)

set(CMAKE_CXX_STANDARD 20)

#if CLANG Compiler
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(
"-Werror" "-Wall" "-Wpedantic" "-Wuninitialized"
)
endif()
# if GNU compiler
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(
"-Werror" "-Wall" "-Wpedantic" "-Wuninitialized"
)
endif()
endif()


add_subdirectory("src")

Expand All @@ -22,3 +45,10 @@ endif()
if(NOT DEFINED ENV{GITHUB_ACTIONS})
add_subdirectory("docs")
endif()

#debian packaging
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Robin E. R. Davies <[email protected]>")
set(CPACK_DEBIAN_FILE_NAME 'nwindows$CMAKE_PACKAGE_MAJOR-$ARCH.deb')
set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "Modern Text User Interface Library for C++")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "xclip, libicu-dev")
include(CPack)
46 changes: 24 additions & 22 deletions docs/src/pages/InstallingNWindows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,25 @@ function InstallingNWindows() {
return (
<DocsPage route={route}>
<div>
<h1>{DocsTitle(route)}</h1> <h2>Prerequisites</h2> <p>
<Name>NWindows</Name> requires the following
development libraries to be installed. </p> <p>
<ul> <li>ncursesw development headers and
libraries.</li> <li>Optionally, <M>xclip</M>.
NWindows uses the <M>xclip</M> program to copy
and paste text to and from the Linux clipboard.
If not installed, clipboard operations will work,
but will not be able to copy and paste text to
and from other applications. </li> <li>Headers
and binaries for the ICU unicode libraries.</li>
</ul> </p> <p>On Debian-based systems (including
Ubuntu), you can install the dependencies using
the following commands:</p> <Code text={ `sudo
apt install libncursesw5-dev xclip libicu-dev
` }
/>
<h1>{DocsTitle(route)}</h1> <h2>Prerequisites</h2>
<p>
<Name>NWindows</Name> requires the following
development libraries to be installed. </p>
<ul> <li>ncursesw development headers and
libraries.</li>
<li>Optionally, <M>xclip</M>.
NWindows uses the <M>xclip</M> program to copy
and paste text to and from the Linux clipboard.
If not installed, clipboard operations will work,
but will not be able to copy and paste text to
and from other applications. </li>
<li>Headers
and binaries for the ICU unicode libraries.</li>
</ul>
<p>On Debian-based systems (including
Ubuntu), you can install the dependencies using
the following commands:</p>
<Code text={`sudo apt install libncursesw5-dev xclip libicu-dev`} />
<p>If you intend to build the NWindows documentation set, you will have to install Node.js and npm.</p>
<Code text={`sudo apt install nodejs npm`} />
<p>Then execute the following commands to install documentation pre-requisites</p>
Expand Down Expand Up @@ -79,7 +81,7 @@ npm install`} />
</li>
<li>
Issue the following command to install NWindows as a submodule of your project:
<Code style={{ marginTop: 16,marginBottom: 16 }} text={
<Code style={{ marginTop: 16, marginBottom: 16 }} text={
`git submodule add https:://github.com/rerdavies/nwindows.git`
}
/>
Expand Down Expand Up @@ -132,11 +134,11 @@ git clone https://github.com/rerdavies/nwindows.git`
<p>To debug the documentation, and run a development web server, </p>
<Code text={`cd docs
./debug.sh`} />
<p>You will want to install React developer tools in your browser. Debug the documentation using Chrome developer tools within the browser.</p>
<p>If you are using CMake, and building NWindows as a submodule, you can disable the documentation build by setting the <M>NWINDOWS_BUILD_DOCUMENTATION</M> variable to <M>OFF</M> in your top-level <M>CMakeLists.txt</M> file.</p>
<Code text={`set(NWINDOWS_BUILD_DOCUMENTATION OFF)`} />
<p>You will want to install React developer tools in your browser. Debug the documentation using Chrome developer tools within the browser.</p>
<p>If you are using CMake, and building NWindows as a submodule, you can disable the documentation build by setting the <M>NWINDOWS_BUILD_DOCUMENTATION</M> variable to <M>OFF</M> in your top-level <M>CMakeLists.txt</M> file.</p>
<Code text={`set(NWINDOWS_BUILD_DOCUMENTATION OFF)`} />
</div>


</DocsPage>
);
Expand Down
3 changes: 0 additions & 3 deletions examples/context_edit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
cmake_minimum_required(VERSION 3.16.0)


add_compile_options(
"-Werror" "-Wall" "-Wpedantic" "-Wuninitialized"
)

add_executable(context_edit
context_edit.cpp
Expand Down
2 changes: 1 addition & 1 deletion examples/context_edit/context_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ContextEditElement : public NTextEditElement {
}

// Show the context menu on right click.
virtual bool handle_clicked(NMouseButton button, NClickedEventArgs& event_args)
virtual bool handle_clicked(NMouseButton button, NClickedEventArgs& event_args) override
{
if (button == NMouseButton::Right) // Right click!
{
Expand Down
4 changes: 0 additions & 4 deletions examples/hello_world/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ cmake_minimum_required(VERSION 3.16.0)

set(CMAKE_CXX_STANDARD 20)

add_compile_options(
"-Werror" "-Wall" "-Wpedantic" "-Wuninitialized"
)

add_executable(hello_world
hello_world.cpp
)
Expand Down
3 changes: 0 additions & 3 deletions examples/hello_world2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ cmake_minimum_required(VERSION 3.16.0)

set(CMAKE_CXX_STANDARD 20)

add_compile_options(
"-Werror" "-Wall" "-Wpedantic" "-Wuninitialized"
)

add_executable(hello_world2
hello_world2.cpp
Expand Down
6 changes: 0 additions & 6 deletions examples/nwindows_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
cmake_minimum_required(VERSION 3.16.0)

set(CMAKE_CXX_STANDARD 20)

add_compile_options(
"-Werror" "-Wall" "-Wpedantic" "-Wuninitialized"
)

add_executable(nwindows_test
test_main.cpp
tests.hpp
Expand Down
7 changes: 1 addition & 6 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
#!/usr/bin/sudo bash
# copy files to installation directories
cmake --install build --prefix /usr --config Release -v
# Done as an install action by the debian package.
sudo /usr/bin/pipedalconfig --install
# copy pipedalPluginProfile as well.
sudo cp build/src/pipedalProfilePlugin /usr/bin/pipedalProfilePlugin
chmod +X /usr/bin/pipedalProfilePlugin
cmake --install build --config Release -v
3 changes: 3 additions & 0 deletions makePackage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cd build
cpack -G DEB -C Release -config CPackConfig.cmake
cd ..
18 changes: 12 additions & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ set(CMAKE_CXX_STANDARD 20)
# add_compile_definitions(_GLIBCXX_DEBUG)


add_compile_options(
"-Werror" "-Wall" "-Wpedantic" "-Wuninitialized"
)


add_library(nwindows
include/NWindows/NClipboard.hpp
Expand All @@ -24,6 +20,12 @@ add_library(nwindows
NUtf8.cpp
NClipboard.cpp
)
set_target_properties(
nwindows
PROPERTIES
PUBLIC_HEADER
"include/NWindows/NClipboard.hpp;include/NWindows/NWindows.hpp;include/NWindows/NUtf8.hpp;include/NWindows/NEvent.hpp;include/NWindows/NUnicodeServices.hpp"
)

set_property(TARGET nwindows PROPERTY POSITION_INDEPENDENT_CODE ON) # -fPic on GCC.

Expand All @@ -41,11 +43,11 @@ target_link_libraries(
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_definitions(nwindows PUBLIC DEBUG DEBUG_NELEMENT_LIFECYCLE)

add_compile_definitions(_GLIBCXX_DEBUG)
#add_compile_definitions(_GLIBCXX_DEBUG)


if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_definitions(nwindows PUBLIC _GLIBCXX_DEBUG)
#target_compile_definitions(nwindows PUBLIC _GLIBCXX_DEBUG)
endif()

endif()
Expand All @@ -63,5 +65,9 @@ target_link_libraries(
nwindows
)

INSTALL(TARGETS nwindows
LIBRARY DESTINATION lib
PUBLIC_HEADER DESTINATION include/NWindows
)


2 changes: 1 addition & 1 deletion src/NClipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ namespace nwindows
pclose(pipe);
return true;
}
std::string get_text() {
std::string get_text() override {
try {
auto output = sysExecForOutput("xclip", "-selection clipboard -o");
if (output.exitCode != EXIT_SUCCESS)
Expand Down
24 changes: 12 additions & 12 deletions src/NUnicodeServices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,16 @@ class DynamicIcuLoader
public:
using ptr = std::shared_ptr<DynamicIcuLoader>;
// Function pointer types
using ucol_open_t = typeof(&ucol_open);
using ucol_close_t = typeof(&ucol_close);
using ucol_strcoll_t = typeof(&ucol_strcoll);
using ucol_strcollUTF8_t = typeof(&ucol_strcollUTF8);
using ucol_setStrength_t = typeof(&ucol_setStrength);
using ucol_getLocaleByType_t = typeof(&ucol_getLocaleByType);
using u_errorName_t = typeof(&u_errorName);
using unorm2_composePair_t = typeof(&unorm2_composePair);
using unorm2_getInstance_t = typeof(&unorm2_getInstance);
using unorm2_normalize_t = typeof(&unorm2_normalize);
using ucol_open_t = decltype(&ucol_open);
using ucol_close_t = decltype(&ucol_close);
using ucol_strcoll_t = decltype(&ucol_strcoll);
using ucol_strcollUTF8_t = decltype(&ucol_strcollUTF8);
using ucol_setStrength_t = decltype(&ucol_setStrength);
using ucol_getLocaleByType_t = decltype(&ucol_getLocaleByType);
using u_errorName_t = decltype(&u_errorName);
using unorm2_composePair_t = decltype(&unorm2_composePair);
using unorm2_getInstance_t = decltype(&unorm2_getInstance);
using unorm2_normalize_t = decltype(&unorm2_normalize);



Expand Down Expand Up @@ -500,7 +500,7 @@ namespace {
virtual std::string Decompose(const std::string&str) const override;
virtual std::u16string Normalize(const std::u16string&str) const override;
virtual std::u16string Decompose(const std::u16string&str) const override;

NormalizerType Type() const { return normalizerType; }
private:
std::shared_ptr<LocaleImpl> localeImpl;
NormalizerType normalizerType;
Expand Down Expand Up @@ -779,7 +779,7 @@ class LocaleImpl : public UnicodeServices, public std::enable_shared_from_this<L
public:
LocaleImpl();
LocaleImpl(const std::string& locale);
virtual const std::string& CurrentLocale() const;
virtual const std::string& CurrentLocale() const override;
virtual Collator::ptr MakeCollator() override;
virtual UnicodeNormalizer::ptr MakeNormalizer(NormalizerType normalizerType) override;

Expand Down
23 changes: 8 additions & 15 deletions src/NWindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -816,23 +816,18 @@ NRect NWindow::calculate_window_position(int max_width, int max_height)
{
// autosize the window.
NSize available = { width(),height() };
if (available.width < 0 || available.height < 0)
{
available = measure(available);

}
bounds.width = available.width;
bounds.height = available.height;
available = measure(available);
measured_.width = std::max(0,available.width);
measured_.height = std::max(0,available.height);
}
else {
measured_.width = width();
measured_.height = height();
}
}
else {
bounds.width = measured_.width;
bounds.height = measured_.height;
}
bounds.width = measured_.width;
bounds.height = measured_.height;

if (bounds.x == AUTO_SIZE)
{
bounds.x = (max_width - bounds.width) / 2;
Expand Down Expand Up @@ -931,7 +926,7 @@ bool NWindow::update_window_size()
{
changed |= childWindow->update_window_size();
}
return false;
return changed;

}

Expand Down Expand Up @@ -2793,7 +2788,7 @@ bool NElement::simulate_keyboard_click(NElement* source, NMouseButton button)

this->keyboard_clicking_timer_ = this->window()->post(
std::chrono::milliseconds(150),
[thisPointer, source, button]()mutable {
[thisPointer, button]()mutable {
auto element = thisPointer.lock();
if (!element) return;
element->keyboard_clicking_timer_ = 0;
Expand Down Expand Up @@ -3112,7 +3107,6 @@ void NRadioGroupElement::update_child_layout() {
auto unchecked_text = this->unchecked_text();


int totalWidth = 0;
int checkedTextLength = utf8_wc_length(checked_text);

int maxWidth = 0;
Expand All @@ -3124,7 +3118,6 @@ void NRadioGroupElement::update_child_layout() {
{
maxWidth = w;
}
totalWidth += w;
}

if (orientation_ == NOrientation::Vertical)
Expand Down
2 changes: 1 addition & 1 deletion src/PrivateElements.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ namespace nwindows::private_elements

static ptr create() { return std::shared_ptr<self>(new self()); }
protected:
virtual NColorPair get_color();
virtual NColorPair get_color() override;

virtual void render() override;
virtual NSize measure(const NSize& available) override;
Expand Down
Loading

0 comments on commit 7706a12

Please sign in to comment.