インストールディレクトリが現在のディレクトリ内またはその下にない場合、 SConsインストールメソッドのドキュメントでコメントされているように、SConsは期待どおりに動作しません。
ただし、ファイルのインストールは、ファイルの「ビルド」の一種と見なされることに注意してください。これは、SConsのデフォルトの動作が、現在のディレクトリ内またはその下にファイルをビルドすることであることを覚えている場合に重要です。上記の例のように、最上位のSConstructファイルのディレクトリツリーの外部のディレクトリにファイルをインストールする場合、そこに何かをインストールするには、そのディレクトリ(または/などの上位ディレクトリ)を指定する必要があります。
つまり、SP3_env['SP3_lib_dir']
インストールを実行するには、(この場合は)インストールディレクトリをターゲットとしてSConsを呼び出す必要があります。これを単純化するために、以下のように使用env.Alias()
します。
SConsを呼び出すときは、少なくとも静的ライブラリと共有ライブラリの両方がローカルプロジェクトディレクトリに構築されていることを確認する必要があります。ただし、SConsはそれらをインストールしないと思います。これが私がUbuntuで作った例です。
env = Environment()
sourceFiles = 'ExampleClass.cc'
sharedLib = env.SharedLibrary(target='example', source=sourceFiles)
staticLib = env.StaticLibrary(target='example', source=sourceFiles)
# Notice that installDir is outside of the local project dir
installDir = '/home/notroot/projects/sandbox'
sharedInstall = env.Install(installDir, sharedLib)
staticInstall = env.Install(installDir, staticLib)
env.Alias('install', installDir)
ターゲットなしでsconsを実行すると、次のようになります。
# scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o ExampleClass.o -c ExampleClass.cc
g++ -o ExampleClass.os -c -fPIC ExampleClass.cc
ar rc libexample.a ExampleClass.o
ranlib libexample.a
g++ -o libexample.so -shared ExampleClass.os
scons: done building targets.
次に、次のように、インストールターゲットでsconsを実行してインストールできます。
# scons install
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
Install file: "libexample.a" as "/home/notroot/projects/sandbox/libexample.a"
Install file: "libexample.so" as "/home/notroot/projects/sandbox/libexample.so"
scons: done building targets.
または、1つのコマンドですべてを実行し、最初にすべてをクリーンアップすることもできます
# scons -c install
次に、1つのコマンドですべてを実行します。
# scons install
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o ExampleClass.o -c ExampleClass.cc
g++ -o ExampleClass.os -c -fPIC ExampleClass.cc
ar rc libexample.a ExampleClass.o
ranlib libexample.a
g++ -o libexample.so -shared ExampleClass.os
Install file: "libexample.a" as "/home/notroot/projects/sandbox/libexample.a"
Install file: "libexample.so" as "/home/notroot/projects/sandbox/libexample.so"
scons: done building targets.