Skip to content

Instantly share code, notes, and snippets.

@Cannedfood
Last active June 4, 2025 03:09
Show Gist options
  • Save Cannedfood/a71652022f066c8032f5a1c01919c55d to your computer and use it in GitHub Desktop.
Save Cannedfood/a71652022f066c8032f5a1c01919c55d to your computer and use it in GitHub Desktop.
A premake5 script for building assimp
-- How to use:
-- 0. Get assimp from https://github.com/assimp/assimp
-- 1. Place this file next to the cloned assimp repository like this:
--
-- assimp.lua
-- assimp/
--
-- 2. Set up configuration headers
--
-- 2.1 Create a folder for configuration headers, I usually name it _config_headers/
--
-- _config_headers/assimp/ <- config.h will be included as "assimp/config.h" so the assimp/ part is important
-- assimp.lua
-- assimp
--
-- 2.2 Generate config.h and revision.h from assimp/code/config.h.in and assimp/revision.h.in and put them into _config_headers/assimp. (You can also just edit and rename them, that's what I usually end up doing.)
--
-- _config_headers/
-- assimp/
-- config.h
-- revision.h
-- assimp.lua
-- assimp
--
-- 3. Edit the 'files { ... }' and 'defines { ... }' depending on which importers/exporters you need. By default I enabled COLLADA, OBJ, FBX and ASSBIN (assimp binary, good for caching)
project '*'
includedirs {
'_config_headers/',
'_config_headers/assimp/', -- Location of assimp's config.h, for a template see include/assimp/config.h.in
'assimp/include/',
}
project 'assimp'
kind 'SharedLib'
warnings 'Off'
optimize 'Speed'
includedirs {
'_config_headers/',
'_config_headers/assimp/',
'assimp/',
'assimp/contrib/',
'assimp/contrib/irrXML/',
'assimp/contrib/unzip/',
'assimp/contrib/rapidjson/include/',
'assimp/contrib/pugixml/src/',
'assimp/contrib/zlib/',
'assimp/contrib/utf8cpp/source',
'assimp/code',
'assimp/include',
}
files {
-- Dependencies
'assimp/contrib/unzip/**',
'assimp/contrib/irrXML/**',
'assimp/contrib/zlib/*',
-- Common
'assimp/code/Common/**',
'assimp/code/PostProcessing/**',
'assimp/code/Material/**',
'assimp/code/CApi/**',
'assimp/code/Geometry/**',
-- Importers
'assimp/code/AssetLib/IQM/**',
'assimp/code/AssetLib/Assbin/**',
'assimp/code/AssetLib/Collada/**',
'assimp/code/AssetLib/Obj/**',
-- 'assimp/code/AssetLib/Blender/**', 'assimp/contrib/poly2tri/poly2tri/**',
'assimp/code/AssetLib/FBX/**',
-- 'assimp/code/glTF2/**',
-- 'assimp/code/glTF/**',
'assimp/code/Assbin/**' -- Very fast format to parse/write, useful for caching
}
-- Importers
defines {
'ASSIMP_BUILD_NO_3D_IMPORTER',
'ASSIMP_BUILD_NO_3DS_IMPORTER',
'ASSIMP_BUILD_NO_3MF_IMPORTER',
'ASSIMP_BUILD_NO_AC_IMPORTER',
'ASSIMP_BUILD_NO_AMF_IMPORTER',
'ASSIMP_BUILD_NO_ASE_IMPORTER',
-- 'ASSIMP_BUILD_NO_ASSBIN_IMPORTER'
'ASSIMP_BUILD_NO_B3D_IMPORTER',
'ASSIMP_BUILD_NO_BLEND_IMPORTER',
'ASSIMP_BUILD_NO_BVH_IMPORTER',
'ASSIMP_BUILD_NO_C4D_IMPORTER',
'ASSIMP_BUILD_NO_COB_IMPORTER',
-- 'ASSIMP_BUILD_NO_COLLADA_IMPORTER',
'ASSIMP_BUILD_NO_CSM_IMPORTER',
'ASSIMP_BUILD_NO_DXF_IMPORTER',
-- 'ASSIMP_BUILD_NO_FBX_IMPORTER',
'ASSIMP_BUILD_NO_GLTF_IMPORTER',
'ASSIMP_BUILD_NO_HMP_IMPORTER',
'ASSIMP_BUILD_NO_IFC_IMPORTER',
'ASSIMP_BUILD_NO_IRR_IMPORTER',
'ASSIMP_BUILD_NO_IRRMESH_IMPORTER',
'ASSIMP_BUILD_NO_LWO_IMPORTER',
'ASSIMP_BUILD_NO_LWS_IMPORTER',
'ASSIMP_BUILD_NO_M3D_IMPORTER',
'ASSIMP_BUILD_NO_MD2_IMPORTER',
'ASSIMP_BUILD_NO_MD3_IMPORTER',
'ASSIMP_BUILD_NO_MD5_IMPORTER',
'ASSIMP_BUILD_NO_MDC_IMPORTER',
'ASSIMP_BUILD_NO_MDL_IMPORTER',
'ASSIMP_BUILD_NO_MMD_IMPORTER',
'ASSIMP_BUILD_NO_MS3D_IMPORTER',
'ASSIMP_BUILD_NO_NDO_IMPORTER',
'ASSIMP_BUILD_NO_NFF_IMPORTER',
-- 'ASSIMP_BUILD_NO_OBJ_IMPORTER',
'ASSIMP_BUILD_NO_OFF_IMPORTER',
'ASSIMP_BUILD_NO_OGRE_IMPORTER',
'ASSIMP_BUILD_NO_OPENGEX_IMPORTER',
'ASSIMP_BUILD_NO_PLY_IMPORTER',
'ASSIMP_BUILD_NO_Q3BSP_IMPORTER',
'ASSIMP_BUILD_NO_Q3D_IMPORTER',
'ASSIMP_BUILD_NO_RAW_IMPORTER',
'ASSIMP_BUILD_NO_SIB_IMPORTER',
'ASSIMP_BUILD_NO_SMD_IMPORTER',
'ASSIMP_BUILD_NO_STEP_IMPORTER',
'ASSIMP_BUILD_NO_STL_IMPORTER',
'ASSIMP_BUILD_NO_TERRAGEN_IMPORTER',
'ASSIMP_BUILD_NO_X_IMPORTER',
'ASSIMP_BUILD_NO_X3D_IMPORTER',
'ASSIMP_BUILD_NO_XGL_IMPORTER'
}
-- Exporters
defines {
'ASSIMP_BUILD_NO_COLLADA_EXPORTER',
'ASSIMP_BUILD_NO_X_EXPORTER',
'ASSIMP_BUILD_NO_STEP_EXPORTER',
'ASSIMP_BUILD_NO_OBJ_EXPORTER',
'ASSIMP_BUILD_NO_STL_EXPORTER',
'ASSIMP_BUILD_NO_PLY_EXPORTER',
'ASSIMP_BUILD_NO_3DS_EXPORTER',
'ASSIMP_BUILD_NO_GLTF_EXPORTER',
-- 'ASSIMP_BUILD_NO_ASSBIN_EXPORTER',
'ASSIMP_BUILD_NO_ASSXML_EXPORTER',
'ASSIMP_BUILD_NO_X3D_EXPORTER',
'ASSIMP_BUILD_NO_FBX_EXPORTER',
'ASSIMP_BUILD_NO_M3D_EXPORTER',
'ASSIMP_BUILD_NO_3MF_EXPORTER',
'ASSIMP_BUILD_NO_ASSJSON_EXPORTER'
}
@harshit2608
Copy link

I used this script and after some modification the only error i get is that it can't find config.h inside defs.h line 55

Assimp premake
assimp

@Root3287
Copy link

Root3287 commented Jul 22, 2021

@harshit2608 if you're still interested. Assimp uses autoconf to generate config.h an other include file. Try to find the .h.in, then use premake-autoconf to generate the necessary symbols.

@Cannedfood
Copy link
Author

I added some instructions to make this gist easier to use

@silvertakana
Copy link

try using the command cmake . before linking with premake.

@silvertakana
Copy link

I have some linking errors when using this.
image
Does anyone know why and how to fix it?

Here's the bin of the errors. https://pastebin.pl/view/70a9aacd

@Cannedfood
Copy link
Author

@silvertakana Looks to me like either

  • zlib isn't compiled correctly or
  • The assimp project moved the 'assimp/contrib/unzip/' folder somewhere else

I'm not working on any game engines that use assimp right now (I switched everything to gltf), so I am not keeping this file up to date very much.
If you manage to get it to work, feel free to post your updated version.

@Karamu98
Copy link

Karamu98 commented Mar 20, 2024

First of all, thank you @Cannedfood for making this much easier for me!

I've updated it to work with latest pull assimp, files have just been moved basically and new dependencies added. Only tested it working with FBX and Obj currently, use the above but replace files and includedirs with the following

files {
	-- Dependencies
	'assimp/contrib/unzip/**',
	'assimp/contrib/irrXML/**',
	'assimp/contrib/zlib/*',
	-- Common
	'assimp/code/Common/**',
	'assimp/code/PostProcessing/**',
	'assimp/code/Material/**',
	'assimp/code/CApi/**',
	'assimp/code/Geometry/**',
	-- Importers
	'assimp/code/AssetLib/IQM/**',
	'assimp/code/AssetLib/Assbin/**',

	'assimp/code/AssetLib/Collada/**',
	'assimp/code/AssetLib/Obj/**',
	-- 'assimp/code/AssetLib/Blender/**', 'assimp/contrib/poly2tri/poly2tri/**',
	'assimp/code/AssetLib/FBX/**',
	-- 'assimp/code/glTF2/**',
	-- 'assimp/code/glTF/**',
	'assimp/code/Assbin/**' -- For caching
}

includedirs {
	'_config_headers/',
	'_config_headers/assimp/',
	'assimp/',
	'assimp/contrib/',
	'assimp/contrib/irrXML/',
	'assimp/contrib/unzip/',
	'assimp/contrib/rapidjson/include/',
	'assimp/contrib/pugixml/src/',
	'assimp/contrib/zlib/',
	'assimp/contrib/utf8cpp/source',
	'assimp/code',
	'assimp/include',
}

@Cannedfood
Copy link
Author

Thank you very much @Karamu98! I updated the gist accordingly.

@Ben-Bingham
Copy link

Thanks for making this file, it simplifies the work alot.

I did have to make a few changes to work with the latest version of ASSIMP (as of this comment being left) that were pretty minor, it seems like they have added two new file types USD and pbrt so I just added the lines:

'ASSIMP_BUILD_NO_USD_IMPORTER',
'ASSIMP_BUILD_NO_PBRT_IMPORTER'

and

'ASSIMP_BUILD_NO_USD_EXPORTER',
'ASSIMP_BUILD_NO_PBRT_EXPORTER'

In there respective places

@KismetPartisan
Copy link

KismetPartisan commented Aug 8, 2024

I used this file and everything worked except when I tried to turn on the gltf importer. I did eventually get it to work though, I had to change these lines

'assimp/code/glTF/**',
'assimp/code/glTF2/**',

to

'assimp/code/AssetLib/glTF/**',
'assimp/code/AssetLib/glTF2/**',

I also had to set the cpp dialect to c++17 at the top of the file so that inline variables could compile

cppdialect "C++17"

And I also had to add this to the list of defines to fix errors created by glTFAssetWriter.inl

'RAPIDJSON_HAS_STDSTRING=1'

Thank you for creating this script, it would have taken much longer if I had to create it from scratch

@Narsell
Copy link

Narsell commented Jun 4, 2025

Heyo, just wanted to add this here in case anyone trying to build with gcc stumbles upon this

For gcc, just add this define and it should work.

	filter "system:linux"
		defines
		{
			"HAVE_UNISTD_H"
		}  

The final Lua script that worked for me, just in case:

project "assimp"
    kind "StaticLib"
    language "C++"
    cppdialect "C++17"

    targetdir ("../../../Binaries/" .. OutputDir .. "/%{prj.name}")
    objdir ("../../../Intermediates/" .. OutputDir .. "/%{prj.name}")

    includedirs
    {
		"_config_headers/",
		"_config_headers/assimp/",
		".",
		"contrib/",
		"contrib/irrXML/",
		"contrib/unzip/",
		"contrib/rapidjson/include/",
		"contrib/pugixml/src/",
		"contrib/zlib/",
		"contrib/utf8cpp/source",
		"code",
		"include",
    }

    files
    {
		-- Dependencies
		"contrib/unzip/**",
		"contrib/irrXML/**",
		"contrib/zlib/*",
		-- Common
		"code/Common/**",
		"code/PostProcessing/**",
		"code/Material/**",
		"code/CApi/**",
		"code/Geometry/**",
		-- Importers
		"code/AssetLib/IQM/**",
		"code/AssetLib/Assbin/**",

		"code/AssetLib/Collada/**",
		"code/AssetLib/Obj/**",
		"code/AssetLib/FBX/**",

		"code/Assbin/**"
    }

    removefiles
	{
        "code/Exporter/**",
        "code/*Exporter.*",
        "code/*Export.*",
    }

    defines
    {
        "_CRT_SECURE_NO_WARNINGS",
        "RAPIDJSON_HAS_STDSTRING=1",
        "ASSIMP_STATIC",
        "ASSIMP_BUILD_NO_EXPORT",
        "ASSIMP_BUILD_NO_USD_IMPORTER",
        "ASSIMP_BUILD_NO_PBRT_IMPORTER",
        "ASSIMP_BUILD_NO_3D_IMPORTER",
		"ASSIMP_BUILD_NO_3DS_IMPORTER",
		"ASSIMP_BUILD_NO_3MF_IMPORTER",
		"ASSIMP_BUILD_NO_AC_IMPORTER",
		"ASSIMP_BUILD_NO_AMF_IMPORTER",
		"ASSIMP_BUILD_NO_ASE_IMPORTER",
		-- "ASSIMP_BUILD_NO_ASSBIN_IMPORTER"
		"ASSIMP_BUILD_NO_B3D_IMPORTER",
		"ASSIMP_BUILD_NO_BLEND_IMPORTER",
		"ASSIMP_BUILD_NO_BVH_IMPORTER",
		"ASSIMP_BUILD_NO_C4D_IMPORTER",
		"ASSIMP_BUILD_NO_COB_IMPORTER",
		-- "ASSIMP_BUILD_NO_COLLADA_IMPORTER",
		"ASSIMP_BUILD_NO_CSM_IMPORTER",
		"ASSIMP_BUILD_NO_DXF_IMPORTER",
		-- "ASSIMP_BUILD_NO_FBX_IMPORTER",
		"ASSIMP_BUILD_NO_GLTF_IMPORTER",
		"ASSIMP_BUILD_NO_HMP_IMPORTER",
		"ASSIMP_BUILD_NO_IFC_IMPORTER",
		"ASSIMP_BUILD_NO_IRR_IMPORTER",
		"ASSIMP_BUILD_NO_IRRMESH_IMPORTER",
		"ASSIMP_BUILD_NO_LWO_IMPORTER",
		"ASSIMP_BUILD_NO_LWS_IMPORTER",
		"ASSIMP_BUILD_NO_M3D_IMPORTER",
		"ASSIMP_BUILD_NO_MD2_IMPORTER",
		"ASSIMP_BUILD_NO_MD3_IMPORTER",
		"ASSIMP_BUILD_NO_MD5_IMPORTER",
		"ASSIMP_BUILD_NO_MDC_IMPORTER",
		"ASSIMP_BUILD_NO_MDL_IMPORTER",
		"ASSIMP_BUILD_NO_MMD_IMPORTER",
		"ASSIMP_BUILD_NO_MS3D_IMPORTER",
		"ASSIMP_BUILD_NO_NDO_IMPORTER",
		"ASSIMP_BUILD_NO_NFF_IMPORTER",
		-- "ASSIMP_BUILD_NO_OBJ_IMPORTER",
		"ASSIMP_BUILD_NO_OFF_IMPORTER",
		"ASSIMP_BUILD_NO_OGRE_IMPORTER",
		"ASSIMP_BUILD_NO_OPENGEX_IMPORTER",
		"ASSIMP_BUILD_NO_PLY_IMPORTER",
		"ASSIMP_BUILD_NO_Q3BSP_IMPORTER",
		"ASSIMP_BUILD_NO_Q3D_IMPORTER",
		"ASSIMP_BUILD_NO_RAW_IMPORTER",
		"ASSIMP_BUILD_NO_SIB_IMPORTER",
		"ASSIMP_BUILD_NO_SMD_IMPORTER",
		"ASSIMP_BUILD_NO_STEP_IMPORTER",
		"ASSIMP_BUILD_NO_STL_IMPORTER",
		"ASSIMP_BUILD_NO_TERRAGEN_IMPORTER",
		"ASSIMP_BUILD_NO_X_IMPORTER",
		"ASSIMP_BUILD_NO_X3D_IMPORTER",
		"ASSIMP_BUILD_NO_XGL_IMPORTER"
    }

	filter "system:linux"
		defines
		{
			"HAVE_UNISTD_H"
		}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment