I'm attempting to add assimp to a cmake build. I need for the library to build statically, statically linking msvc (/MT for release and /MTd for debug). There does not appear to be a specific cmake option to enable/disable this for assimp itself. I have tried the following to force the library to statically link msvc:
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
if(MSVC)
add_compile_options(
$<$<CONFIG:>:/MT> #---------|
$<$<CONFIG:Debug>:/MTd> #---|-- Statically link the runtime libraries
$<$<CONFIG:Release>:/MT> #--|
)
endif()
Neither of which seem to have any effect, as the library continues to build as /MD or /MDd. Is there a specific flag for assimp to enable or disable static linking msvc that i just cannot find? If not how could I go about accomplishing this? Below is the relevent section of my CMakeLists.txt
file:
# SETUP ASSIMP
set(libAssimp assimp)
ExternalProject_Add(${libAssimp}
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/_deps/${libAssimp}
GIT_REPOSITORY https://github.com/assimp/assimp.git
GIT_TAG v5.0.1
GIT_SHALLOW ON
UPDATE_COMMAND ""
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/_deps/installs/${libAssimp}
-DASSIMP_BUILD_ALL_IMPORTERS_BY_DEFAULT:BOOL=OFF
-DASSIMP_BUILD_ALL_EXPORTERS_BY_DEFAULT:BOOL=OFF
-DASSIMP_BUILD_ASSIMP_TOOLS:BOOL=OFF
-DASSIMP_BUILD_TESTS:BOOL=OFF
-DASSIMP_BUILD_FBX_IMPORTER:BOOL=ON
-DASSIMP_BUILD_OBJ_IMPORTER:BOOL=ON
-DASSIMP_BUILD_OBJ_EXPORTER:BOOL=ON
-DASSIMP_BUILD_ZLIB:BOOL=ON
-DASSIMP_LIBRARY_SUFFIX:STRING=
-DLIBRARY_SUFFIX:STRING=
-DCMAKE_DEBUG_POSTFIX:STRING=
-DASSIMP_INJECT_DEBUG_POSTFIX:BOOL=OFF
-DBUILD_SHARED_LIBS:BOOL=OFF
)
set(ASSIMP_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/_deps/installs/${libAssimp})
add_library(ASSIMP_LIBRARY STATIC IMPORTED)
set_target_properties(ASSIMP_LIBRARY PROPERTIES IMPORTED_LOCATION ${ASSIMP_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}assimp${CMAKE_STATIC_LIBRARY_SUFFIX})
add_library(IRRXML_LIBRARY STATIC IMPORTED)
set_target_properties(IRRXML_LIBRARY PROPERTIES IMPORTED_LOCATION ${ASSIMP_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}IrrXML${CMAKE_STATIC_LIBRARY_SUFFIX})
add_library(ZLIB_LIBRARY STATIC IMPORTED)
set_target_properties(
ZLIB_LIBRARY
PROPERTIES
IMPORTED_LOCATION_RELEASE ${ASSIMP_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}zlibstatic${CMAKE_STATIC_LIBRARY_SUFFIX}
IMPORTED_LOCATION_MINSIZEREL ${ASSIMP_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}zlibstatic${CMAKE_STATIC_LIBRARY_SUFFIX}
IMPORTED_LOCATION_RELWITHDEBINFO ${ASSIMP_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}zlibstatic${CMAKE_STATIC_LIBRARY_SUFFIX}
IMPORTED_LOCATION_DEBUG ${ASSIMP_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}zlibstaticd${CMAKE_STATIC_LIBRARY_SUFFIX}
)
UPDATE
I believe I may have figured this out. Although I had tried adding CMAKE_MSVC_RUNTIME_LIBRARY
and MSVC_RUNTIME_LIBRARY
to CMAKE_FLAGS
previously to no avail...I'm thinking cmake may have been caching the original values as I just tried downloading assimp independently of my superbuild, insured the cache was cleared and built using the above flags, and VS is showing as /MT
. Will report back once I have confirmed this is working in my superbuild with ExternalProject_Add
.
UPDATE002
Alright, IDK how I had this working in my above explanation, but I'm unable to duplicate it going through the same process as before. Cleared cmake cache, used all the same options, stuck on /MD again.