FindASSIMP.cmake 4.85 KB
Newer Older
Bastian Krayer's avatar
Bastian Krayer committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#
# Try to find Assimp library and include path.
# Once done this will define
#
# ASSIMP_FOUND
# ASSIMP_INCLUDE_PATH
# ASSIMP_LIBRARIES
# ASSIMP_BINARIES
# 
# It will add the assimp DLL for windows builds to PROJECT_RUNTIME_LIBRARIES
IF(DEFINED ENV{ASSIMP_ROOT})
	file(TO_CMAKE_PATH $ENV{ASSIMP_ROOT} ASSIMP_ROOT_ENV)
ENDIF()
# For older cmake versions use root variable as additional search directory explicitly
IF(${CMAKE_VERSION} VERSION_LESS_EQUAL "3.12.0") 
	SET(ASSIMP_ADDITIONAL_SEARCH_DIRS ${ASSIMP_ROOT_ENV})
ENDIF()
IF(APPLE)
    set(ASSIMP_ROOT_ENV $ENV{CVK_DEPENDENCIES_OSX}/assimp/)
ENDIF(APPLE)


if (WIN32)

	IF (MINGW)

		SET(ASSIMP_SEARCH_PATH_SUFFIX mingw)
		SET(ASSIMP_LIB_NAME libassimp)
   
	ELSEIF (MSVC)
	
		# MSVC toolset suffix
		# Checks for version
		SET(ASSIMP_MSCV_LIB_POSTFIX "")
		IF(MSVC_TOOLSET_VERSION EQUAL 140 OR MSVC_VERSION EQUAL 1900)
		
			SET(ASSIMP_SEARCH_PATH_SUFFIX "msvc140")
			SET(ASSIMP_MSCV_LIB_POSTFIX "-vc140-mt")
		ELSEIF(MSVC_TOOLSET_VERSION EQUAL 141 OR 
		(MSVC_VERSION GREATER_EQUAL 1910 AND MSVC_VERSION LESS_EQUAL 1919) )
			SET(ASSIMP_SEARCH_PATH_SUFFIX "msvc141")
			SET(ASSIMP_MSCV_LIB_POSTFIX "-vc140-mt")
		ELSE()
			SET(ASSIMP_SEARCH_PATH_SUFFIX "msvc141")
			SET(ASSIMP_MSCV_LIB_POSTFIX "-vc140-mt") # good luck
		ENDIF()

		SET(ASSIMP_LIB_NAME "assimp${ASSIMP_MSCV_LIB_POSTFIX}")
		

	ENDIF()
	
	find_library(ASSIMP_LIBRARY_RELEASE 
		NAMES ${ASSIMP_LIB_NAME}
		PATHS
		${ASSIMP_ADDITIONAL_SEARCH_DIRS}
		PATH_SUFFIXES ${ASSIMP_SEARCH_PATH_SUFFIX}/lib
	)
	find_library(ASSIMP_LIBRARY_DEBUG 
		NAMES "${ASSIMP_LIB_NAME}d"
		PATHS
		${ASSIMP_ADDITIONAL_SEARCH_DIRS}
		PATH_SUFFIXES ${ASSIMP_SEARCH_PATH_SUFFIX}/lib
	) 

	
	FIND_PATH(ASSIMP_INCLUDE_DIR assimp/ai_assert.h
		PATHS
		${ASSIMP_ADDITIONAL_SEARCH_DIRS}
		PATH_SUFFIXES ${ASSIMP_SEARCH_PATH_SUFFIX}/include
    )
	
	include(SelectLibraryConfigurations)
	select_library_configurations(ASSIMP)
	
		# Determine if 64 Bit build
	if("${CMAKE_GENERATOR}" MATCHES "(Win64|IA64)" OR "${CMAKE_SIZEOF_VOID_P}" STREQUAL "8" OR CMAKE_CL_64)
		SET(ASSIMP_BINARY_SEARCH_POSTFIX "64")
	endif()

	FILE(GLOB ASSIMP_BINARIES "${ASSIMP_INCLUDE_DIR}/../bin${ASSIMP_BINARY_SEARCH_POSTFIX}/*.dll")	

	if(NOT ASSIMP_LIBRARY_RELEASE)
        set(ASSIMP_LIBRARY_RELEASE "ASSIMP_LIBRARY_RELEASE-NOTFOUND" CACHE FILEPATH "Path to a library.")
    endif()
    if(NOT ASSIMP_LIBRARY_DEBUG)
        set(ASSIMP_LIBRARY_DEBUG "ASSIMP_LIBRARY_DEBUG-NOTFOUND" CACHE FILEPATH "Path to a library.")
    endif()
	
    get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
    if( ASSIMP_LIBRARY_DEBUG AND ASSIMP_LIBRARY_RELEASE AND
           NOT ASSIMP_LIBRARY_DEBUG STREQUAL ASSIMP_LIBRARY_RELEASE AND
           ( _isMultiConfig OR CMAKE_BUILD_TYPE ) )
        # if the generator is multi-config or if CMAKE_BUILD_TYPE is set for
        # single-config generators, set optimized and debug libraries
        set( ASSIMP_INTERFACE_LIBRARY "" )
        foreach( _libname IN LISTS ASSIMP_LIBRARY_RELEASE )
           list( APPEND ASSIMP_INTERFACE_LIBRARY $<$<CONFIG:RelWithDebInfo>:${_libname}>  )
           list( APPEND ASSIMP_INTERFACE_LIBRARY $<$<CONFIG:Release>:${_libname}>  )
           list( APPEND ASSIMP_INTERFACE_LIBRARY $<$<CONFIG:MinSizeRel>:${_libname}>  )
            #list( APPEND GLFW3_LIBRARY ${_libname} )
        endforeach()
        foreach( _libname IN LISTS ASSIMP_LIBRARY_DEBUG )
            list( APPEND ASSIMP_INTERFACE_LIBRARY $<$<CONFIG:Debug>:${_libname}> )
        endforeach()
    elseif( ASSIMP_LIBRARY_RELEASE )
        set( ASSIMP_INTERFACE_LIBRARY ${ASSIMP_LIBRARY_RELEASE} )
    elseif( ASSIMP_LIBRARY_DEBUG )
        set( ASSIMP_INTERFACE_LIBRARY ${ASSIMP_LIBRARY_DEBUG} )
    else()
        set( ASSIMP_INTERFACE_LIBRARY "ASSIMP_LIBRARY-NOTFOUND")
    endif()
	
	

ELSEIF(APPLE)

    FIND_PATH(ASSIMP_INCLUDE_PATH assimp/defs.h
	PATHS
		${ASSIMP_ADDITIONAL_SEARCH_DIRS}
    ${ASSIMP_ROOT_ENV}/include)
    
    FIND_LIBRARY( ASSIMP_LIBRARY
        NAMES libassimp.a libassimp.dylib
        PATHS 
		${ASSIMP_ROOT_ENV}/lib
		${ASSIMP_ADDITIONAL_SEARCH_DIRS})
    SET(ASSIMP_LIBRARY z ${ASSIMP_LIBRARY})

ELSE()

    FIND_PATH(ASSIMP_INCLUDE_PATH assimp/defs.h
	PATHS ${ASSIMP_ADDITIONAL_SEARCH_DIRS}
		)
    FIND_LIBRARY(ASSIMP_LIBRARY
        NAMES assimp
		PATHS
		${ASSIMP_ADDITIONAL_SEARCH_DIRS}
    PATH_SUFFIXES dynamic)

ENDIF ()



include(FindPackageHandleStandardArgs)
	find_package_handle_standard_args(ASSIMP
                                  REQUIRED_VARS ASSIMP_INCLUDE_DIR ASSIMP_LIBRARY)
set(ASSIMP_INCLUDE_DIRS ${ASSIMP_INCLUDE_DIR})


if(ASSIMP_FOUND AND NOT TARGET Assimp::Assimp)
    add_library(Assimp::Assimp INTERFACE IMPORTED)
	IF(NOT ASSIMP_INTERFACE_LIBRARY)
		SET(ASSIMP_INTERFACE_LIBRARY ${ASSIMP_LIBRARIES})
	ENDIF()
    set_target_properties(Assimp::Assimp PROPERTIES
        INTERFACE_INCLUDE_DIRECTORIES "${ASSIMP_INCLUDE_DIR}"
		INTERFACE_LINK_LIBRARIES "${ASSIMP_INTERFACE_LIBRARY}"
    )
endif()