このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。
カスタムの CMake ツールチェーン定義の作成
CMake は、サードパーティが提供するオープンソースのビルド プロセス管理ツールです。Simulink® モデルから生成されたコードをビルドするために、このソフトウェアには、[ツールチェーン] ドロップダウン リストから選択できる CMake ツールチェーン定義が用意されています。target
名前空間を使用して、カスタムの CMake ツールチェーン定義を作成することもできます。カスタムの CMake ツールチェーン定義を内部データベースに追加すると、そのツールチェーンを使用して生成コードをビルドできるようになります。この例では、Ninja ジェネレーターを使用して CMake ツールチェーン定義を作成する方法を示します。ツールチェーン定義は、以下のオペレーティング システムのコンピューターで使用できます。
Windows® (MATLAB® Support for MinGW®-w64 C/C++ Compiler がインストールされている場合)。
Linux®
Mac
target.Toolchain
オブジェクトを作成します。
tc = target.create('Toolchain', 'Name', 'Example Custom CMake Toolchain');
Builder
プロパティおよび target.CMakeBuilder
オブジェクトを使用して、CMake で生成コードをビルドする方法を構成します。
tc.Builder = target.create('CMakeBuilder'); tc.Builder.Generator = 'Ninja'; tc.Builder.ToolchainFile = fullfile(pwd, 'ExampleCMakeToolchain.cmake'); tc.Builder.SupportedBuildTypes(end+1) = ... target.create('CMakeBuildType', ... 'Name', 'FastMath', ... 'GeneratesDebugSymbols', false, ... 'DebugBuildType', 'FastMathWithDebug'); tc.Builder.SupportedBuildTypes(end+1) = ... target.create('CMakeBuildType', ... 'Name', 'FastMathWithDebug', ... 'GeneratesDebugSymbols', true);
エディターを使用して、以下の行が含まれたファイル ExampleCMakeToolchain.cmake
を作成します。
# Example CMake toolchain # Configure to use GCC if(WIN32) list(APPEND CMAKE_PROGRAM_PATH "$ENV{MW_MINGW64_LOC}") endif() set(CMAKE_C_COMPILER "gcc") set(CMAKE_CXX_COMPILER "g++") # Add some custom build configurations: FastMath, and FastMathWithDebug set(CMAKE_C_FLAGS_FASTMATH "-Ofast") set(CMAKE_CXX_FLAGS_FASTMATH "-Ofast") set(CMAKE_C_FLAGS_FASTMATHWITHDEBUG "-Ofast -g") set(CMAKE_CXX_FLAGS_FASTMATHWITHDEBUG "-Ofast -g")
EnvironmentConfiguration
プロパティの 1 番目の要素を使用して、Windows オペレーティング システム用のシステム環境設定コマンドおよびパスを指定します。
tc.EnvironmentConfiguration(1).HostOperatingSystemSupport.Linux = false; tc.EnvironmentConfiguration(1).HostOperatingSystemSupport.Windows = true; tc.EnvironmentConfiguration(1).HostOperatingSystemSupport.Mac = false; tc.EnvironmentConfiguration(1).SystemPaths = ... {'$(MW_MINGW64_LOC)/bin', '$(MATLAB_ROOT)/toolbox/shared/coder/ninja/$(ARCH)'};
EnvironmentConfiguration
プロパティの 2 番目の要素を使用して、Linux および Mac オペレーティング システム用のシステム環境設定コマンドおよびパスを指定します。
tc.EnvironmentConfiguration(2) = target.create('EnvironmentConfiguration'); tc.EnvironmentConfiguration(2).HostOperatingSystemSupport.Linux = true; tc.EnvironmentConfiguration(2).HostOperatingSystemSupport.Windows = false; tc.EnvironmentConfiguration(2).HostOperatingSystemSupport.Mac = true; tc.EnvironmentConfiguration(2).SystemPaths = ... {'$(MATLAB_ROOT)/toolbox/shared/coder/ninja/$(ARCH)'};
既定では、このソフトウェアは MATLAB に付属の CMake 実行可能ファイルを使用します。別のバージョンの CMake を指定するために、必要なパスを提供するオブジェクトを作成できます。
オプションで、ツールチェーン定義をターゲット デバイスに関連付けます。たとえば、以下のようにします。
windowsProc = target.get('Processor', 'Intel-x86-64 (Windows64)'); tc.SupportedHardware(end+1) = ... target.create('HardwareComponentSupport', 'Component', windowsProc); linuxProc = target.get('Processor', 'Intel-x86-64 (Linux 64)'); tc.SupportedHardware(end+1) = ... target.create('HardwareComponentSupport', 'Component', linuxProc); macProc = target.get('Processor', 'Intel-x86-64 (Mac OS X)'); tc.SupportedHardware(end+1) = ... target.create('HardwareComponentSupport', 'Component', macProc);
ツールチェーン定義を内部データベースに追加します。
target.add(tc);
生成コードをビルドするためにカスタムのツールチェーン定義を使用するには、[コンフィギュレーション パラメーター] ダイアログ ボックスで以下のようにします。
[ハードウェア実行] ペインで [デバイス ベンダー] を
[Intel]
、[デバイス タイプ] を[x86-64 (Windows64)]
に設定してターゲット デバイスを選択します。[コード生成] ペインで、[ツールチェーン] リストから
[Example Custom CMake Toolchain]
を選択します。[ビルド構成] リストには以下の値が含まれています。Release
Debug
RelWithDebInfo
MinSizeRel
FastMath
FastMathWithDebug
Specify
[詳細設定パラメーター] で [ツールチェーンの検証] をクリックします。これにより、検証レポートが生成されます。
たとえば、関数 slbuild
やソフトウェアインザループ (SIL) シミュレーションを実行する場合、ビルド プロセスはカスタムのツールチェーンを使用して生成コードをビルドします。
カスタムのツールチェーン定義を内部データベースから削除する場合は、以下を実行します。
customToolChainDef = target.get('Toolchain', 'Example Custom CMake Toolchain'); target.remove(customToolChainDef);
target.remove summary: Objects removed from internal database: target.Toolchain "Example Custom CMake Toolchain"
参考
target.create
| target.Toolchain
| target.CMake
| target.CMakeBuilder
| target.CMakeBuildType
| target.CMakeCacheEntry
| target.EnvironmentConfiguration
| target.HardwareComponentSupport