差分
このページの2つのバージョン間の差分を表示します。
| 次のリビジョン | 前のリビジョン | ||
| wxwidgets:helloworld-cmake [2025/05/23 08:33] – 作成 freemikan | wxwidgets:helloworld-cmake [2025/05/24 07:37] (現在) – [プログラムのソースコード] freemikan | ||
|---|---|---|---|
| 行 1: | 行 1: | ||
| ====== CMakeを使ったHello World ====== | ====== CMakeを使ったHello World ====== | ||
| + | {{: | ||
| - | {{: | ||
| + | ===== 前提 ===== | ||
| + | [[install|インストールのページ]]に従い、wxWidget 3.2がインストール済みであることを前提とします。 | ||
| + | また、CMakeもインストールされている必要があります。 | ||
| - | https://docs.wxwidgets.org/latest/ | + | ===== 作業ディレクトリ ===== |
| + | 作業ディレクトリは $HOME/code/wxwidgets/hello-wxwidgets-cmake とします。 | ||
| - | + | < | |
| - | 作業ディレクトリ | + | 繰り返しになりますが、こういった名前やパスは、何かしら決めておかないと説明がしづらいので提示しているだけです。 |
| + | 同じ名前にする必要は全くありません。 | ||
| + | ご自身の好みの場所に好きな名前で作成してください。 | ||
| + | </ | ||
| <cli> | <cli> | ||
| - | $ cd ~/ | + | $ mkdir -p ~/ |
| - | $ mkdir hello-wxwidgets-cmake | + | $ cd $_ |
| - | $ cd hello-wxwidgets-cmake | + | |
| </ | </ | ||
| - | '' | ||
| - | <code cpp> | + | ===== プログラムのソースコード ===== |
| - | // Start of wxWidgets "Hello World" Program | + | プログラムのソースコードは、[[wxwidgets:helloworld# |
| - | #include < | + | main.cppという名前でコピーを作成しておきます。 |
| - | + | ||
| - | class MyApp : public wxApp | + | |
| - | { | + | |
| - | public: | + | |
| - | bool OnInit() override; | + | |
| - | }; | + | |
| - | + | ||
| - | wxIMPLEMENT_APP(MyApp); | + | |
| - | + | ||
| - | class MyFrame : public wxFrame | + | |
| - | { | + | |
| - | public: | + | |
| - | MyFrame(); | + | |
| - | + | ||
| - | private: | + | |
| - | void OnHello(wxCommandEvent& | + | |
| - | void OnExit(wxCommandEvent& | + | |
| - | void OnAbout(wxCommandEvent& | + | |
| - | }; | + | |
| - | + | ||
| - | enum | + | |
| - | { | + | |
| - | ID_Hello | + | |
| - | }; | + | |
| - | + | ||
| - | bool MyApp:: | + | |
| - | { | + | |
| - | MyFrame *frame | + | |
| - | frame-> | + | |
| - | return true; | + | |
| - | } | + | |
| - | + | ||
| - | MyFrame:: | + | |
| - | : wxFrame(nullptr, | + | |
| - | { | + | |
| - | wxMenu *menuFile | + | |
| - | menuFile-> | + | |
| - | " | + | |
| - | menuFile-> | + | |
| - | menuFile-> | + | |
| - | + | ||
| - | wxMenu *menuHelp | + | |
| - | menuHelp-> | + | |
| - | + | ||
| - | wxMenuBar *menuBar | + | |
| - | | + | |
| - | menuBar-> | + | |
| - | + | ||
| - | SetMenuBar( menuBar ); | + | |
| - | + | ||
| - | CreateStatusBar(); | + | |
| - | SetStatusText(" | + | |
| - | + | ||
| - | Bind(wxEVT_MENU, | + | |
| - | Bind(wxEVT_MENU, | + | |
| - | Bind(wxEVT_MENU, | + | |
| - | } | + | |
| - | + | ||
| - | void MyFrame:: | + | |
| - | { | + | |
| - | Close(true); | + | |
| - | } | + | |
| - | + | ||
| - | void MyFrame:: | + | |
| - | { | + | |
| - | wxMessageBox(" | + | |
| - | "About Hello World", | + | |
| - | } | + | |
| - | + | ||
| - | void MyFrame:: | + | |
| - | { | + | |
| - | wxLogMessage(" | + | |
| - | } | + | |
| - | </ | + | |
| - | '' | + | ===== CMakeLists.txt |
| + | __CMakeLists.txt__ | ||
| <code cmake> | <code cmake> | ||
| - | cmake_minimum_required(VERSION 3.5 FATAL_ERROR) | + | cmake_minimum_required(VERSION 3.10 FATAL_ERROR) |
| project(hello-wxwidgets-cmake LANGUAGES CXX) | project(hello-wxwidgets-cmake LANGUAGES CXX) | ||
| - | # https:// | + | find_package(wxWidgets |
| - | find_package(wxWidgets REQUIRED) | + | |
| include(${wxWidgets_USE_FILE}) | include(${wxWidgets_USE_FILE}) | ||
| 行 111: | 行 43: | ||
| </ | </ | ||
| - | ビルドディレクトリ | + | https:// |
| + | ===== ビルドディレクトリの作成 ===== | ||
| <cli> | <cli> | ||
| $ mkdir build | $ mkdir build | ||
| 行 118: | 行 51: | ||
| </ | </ | ||
| - | CMakeコンフィギュレーション | ||
| + | ===== CMakeコンフィギュレーションの実行 ===== | ||
| <cli> | <cli> | ||
| $ cmake .. | $ cmake .. | ||
| </ | </ | ||
| - | ビルド | ||
| + | ===== ビルドの実行 ===== | ||
| <cli> | <cli> | ||
| $ make | $ make | ||
| </ | </ | ||
| - | ビルド結果の確認 | + | あるいは |
| + | |||
| + | < | ||
| + | $ cmake --build . | ||
| + | </ | ||
| + | ==== 結果の確認 ==== | ||
| <cli> | <cli> | ||
| $ ls -l | $ ls -l | ||
| 行 142: | 行 80: | ||
| </ | </ | ||
| - | 実行 | ||
| + | ===== Hello Worldプログラムの実行 ===== | ||
| <cli> | <cli> | ||
| $ ./ | $ ./ | ||
