0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Windows で Cocos2d-x 4.0 (CMake) + CLion の開発環境を構築したときのメモ

Last updated at Posted at 2025-05-26

Cocos2d-x での開発は既にトレンドアウトしていますが C++ を使用したゲーム開発を手軽に開始することができる点は今なお魅力的であり、他に選択肢の少ない状況だと思います。
さらに Cocos2d-x v4.0 においては Visual Studio のサポートが打ち切られているので、CMake を使った開発環境を構築するほうがベターです。

前提

Cocos2d-x v4.0
Visual Studio 2022 Community
CLion 2025.1.11 (2025/5~ 個人開発者であれば無料で使えてお得)

※参考
IDE に Visual Studio 2022 の CMake サポートを使用する場合の手順はこちらにあります。

環境構築

金子邦彦先生の書かれた手順書が非常にわかりやすいため、参考にさせていただきます。
手順書の「Cocos2d-x 3.17.2」の部分を「4.0」に適宜読み替えて進めれば基本的には問題ないはず。

CLion の操作手順

1. cocos new コマンドで作成した新規プロジェクトのフォルダを CLion で開きます

手順書の「Cocos2d-x でプロジェクトの作成」の3までをやる。

2. ルートディレクトリに CMakePresets.json というファイルを作ります

image.png
中身は以下をコピペ。

{
  "version": 3,
  "cmakeMinimumRequired": {
    "major": 3,
    "minor": 21
  },
  "configurePresets": [
    {
      "name": "win32-v143",
      "displayName": "VS 2022 - Win32 - v143 Toolset",
      "description": "Visual Studio 17 2022 with Win32 arch and v143 toolset",
      "generator": "Visual Studio 17 2022",
      "architecture": "Win32",
      "toolset": "v143",
      "binaryDir": "${sourceDir}/win32-build",
      "cacheVariables": {
        "CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
        "CMAKE_VERBOSE_MAKEFILE": "ON"
      },
      "environment": {
        "VERBOSE": "1"
      }
    }
  ],
  "buildPresets": [
    {
      "name": "win32-v143-debug",
      "configurePreset": "win32-v143",
      "configuration": "Debug",
      "verbose": true
    },
    {
      "name": "win32-v143-release",
      "configurePreset": "win32-v143",
      "configuration": "Release",
      "verbose": true
    }
  ]
}
補足

"CMAKE_VERBOSE_MAKEFILE": "ON" "VERBOSE": "1" "verbose": true
ビルドの出力情報を増やしてエラー対処しやすくしています

3. ウィンドウ右上の CMake プロファイルの編集 をクリック

image.png

4. 以下の画像の通りに2つのプロファイルを有効化する

・win32-v143 - win32-v143-debug
・win32-v143 - win32-v143-release
image.png

5. 先ほど有効化したプロファイルのいずれかを選択し、▷ボダンを押す

image.png

以下の表示が出たら成功です!
{65EE32DD-DBC0-4BDE-8ECD-EB1311A273A0}.png

もちろんデバッグ機能も使えるので、色々試してみましょう。
image.png

その他

Error: could not load cache が出たときは

image.png

ファイル → CMake プロジェクトの再ロード をクリックしてみてください。
image.png

ビルドコンソールが盛大に文字化けする件 [TODO]

{28E09B70-37D9-4EE9-805E-45DC9829CF0E}.png
MSBuild が Shift-JIS で出力され、CLion のビルドコンソールが UTF-8 であるため発生しているようです。Cocos2d-x が UTF-8 なので、これを英語にできると良いんですけど方法が分かりません。。。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?