@@ -493,19 +493,19 @@ else()
493
493
set (mi_install_cmakedir "${CMAKE_INSTALL_LIBDIR} /cmake/mimalloc-${mi_version} " ) # for cmake package info
494
494
endif ()
495
495
496
- set (mi_basename "mimalloc" )
496
+ set (mi_libname "mimalloc" )
497
497
if (MI_SECURE)
498
- set (mi_basename "${mi_basename } -secure" )
498
+ set (mi_libname "${mi_libname } -secure" )
499
499
endif ()
500
500
if (MI_TRACK_VALGRIND)
501
- set (mi_basename "${mi_basename } -valgrind" )
501
+ set (mi_libname "${mi_libname } -valgrind" )
502
502
endif ()
503
503
if (MI_TRACK_ASAN)
504
- set (mi_basename "${mi_basename } -asan" )
504
+ set (mi_libname "${mi_libname } -asan" )
505
505
endif ()
506
506
string (TOLOWER "${CMAKE_BUILD_TYPE} " CMAKE_BUILD_TYPE_LC)
507
507
if (NOT (CMAKE_BUILD_TYPE_LC MATCHES "^(release|relwithdebinfo|minsizerel|none)$" ))
508
- set (mi_basename "${mi_basename } -${CMAKE_BUILD_TYPE_LC} " ) #append build type (e.g. -debug) if not a release version
508
+ set (mi_libname "${mi_libname } -${CMAKE_BUILD_TYPE_LC} " ) #append build type (e.g. -debug) if not a release version
509
509
endif ()
510
510
511
511
if (MI_BUILD_SHARED)
@@ -522,7 +522,7 @@ if(MI_BUILD_TESTS)
522
522
endif ()
523
523
524
524
message (STATUS "" )
525
- message (STATUS "Library base name: ${mi_basename } " )
525
+ message (STATUS "Library name : ${mi_libname } " )
526
526
message (STATUS "Version : ${mi_version} .${mi_version_patch} " )
527
527
message (STATUS "Build type : ${CMAKE_BUILD_TYPE_LC} " )
528
528
if (MI_USE_CXX)
@@ -543,52 +543,52 @@ message(STATUS "")
543
543
# shared library
544
544
if (MI_BUILD_SHARED)
545
545
add_library (mimalloc SHARED ${mi_sources} )
546
- set_target_properties (mimalloc PROPERTIES VERSION ${mi_version} SOVERSION ${mi_version_major} OUTPUT_NAME ${mi_basename } )
546
+ set_target_properties (mimalloc PROPERTIES VERSION ${mi_version} SOVERSION ${mi_version_major} OUTPUT_NAME ${mi_libname } )
547
547
target_compile_definitions (mimalloc PRIVATE ${mi_defines} MI_SHARED_LIB MI_SHARED_LIB_EXPORT)
548
548
target_compile_options (mimalloc PRIVATE ${mi_cflags} ${mi_cflags_dynamic} )
549
549
target_link_libraries (mimalloc PRIVATE ${mi_libraries} )
550
550
target_include_directories (mimalloc PUBLIC
551
551
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR} /include >
552
552
$<INSTALL_INTERFACE:${mi_install_incdir} >
553
553
)
554
+ install (TARGETS mimalloc EXPORT mimalloc ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} )
555
+ install (EXPORT mimalloc DESTINATION ${mi_install_cmakedir} )
556
+
557
+ if (WIN32 )
558
+ # On windows, the import library name for the dll would clash with the static mimalloc.lib
559
+ # so we postfix the dll import library with `.dll.lib`.
560
+ set_property (TARGET mimalloc PROPERTY ARCHIVE_OUTPUT_NAME "${mi_libname} .dll" )
561
+ install (FILES "$<TARGET_FILE_DIR:mimalloc>/${mi_libname} .dll.lib" DESTINATION ${CMAKE_INSTALL_LIBDIR} )
562
+ endif ()
554
563
if (WIN32 AND MI_WIN_REDIRECT)
555
564
# On windows, link and copy the mimalloc redirection dll too.
556
565
if (CMAKE_GENERATOR_PLATFORM STREQUAL "arm64ec" )
557
566
set (MIMALLOC_REDIRECT_SUFFIX "-arm64ec" )
558
567
elseif (MI_ARCH STREQUAL "x64" )
559
568
set (MIMALLOC_REDIRECT_SUFFIX "" )
560
569
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "ARM64" )
561
- message (STATUS "Note: x64 code emulated on Windows for arm64 should use an arm64ec build of 'mimalloc-override .dll'" )
562
- message (STATUS " with 'mimalloc-redirect-arm64ec.dll'. See the 'bin\\ readme.md' for more information." )
570
+ message (STATUS "Note: x64 code emulated on Windows for arm64 should use an arm64ec build of 'mimalloc.dll'" )
571
+ message (STATUS " together with 'mimalloc-redirect-arm64ec.dll'. See the 'bin\\ readme.md' for more information." )
563
572
endif ()
564
573
elseif (MI_ARCH STREQUAL "x86" )
565
574
set (MIMALLOC_REDIRECT_SUFFIX "32" )
566
575
else ()
567
576
set (MIMALLOC_REDIRECT_SUFFIX "-${MI_ARCH} " ) # -arm64 etc.
568
577
endif ()
569
578
570
- target_link_libraries (mimalloc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} /bin/mimalloc-redirect${MIMALLOC_REDIRECT_SUFFIX} .lib)
579
+ target_link_libraries (mimalloc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} /bin/mimalloc-redirect${MIMALLOC_REDIRECT_SUFFIX} .lib) # the DLL import library
571
580
add_custom_command (TARGET mimalloc POST_BUILD
572
581
COMMAND "${CMAKE_COMMAND} " -E copy "${CMAKE_CURRENT_SOURCE_DIR} /bin/mimalloc-redirect${MIMALLOC_REDIRECT_SUFFIX} .dll" $<TARGET_FILE_DIR:mimalloc>
573
582
COMMENT "Copy mimalloc-redirect${MIMALLOC_REDIRECT_SUFFIX} .dll to output directory" )
574
583
install (FILES "$<TARGET_FILE_DIR:mimalloc>/mimalloc-redirect${MIMALLOC_REDIRECT_SUFFIX} .dll" DESTINATION ${CMAKE_INSTALL_BINDIR} )
575
584
endif ()
576
-
577
- install (TARGETS mimalloc EXPORT mimalloc ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} )
578
- install (EXPORT mimalloc DESTINATION ${mi_install_cmakedir} )
579
585
endif ()
580
586
587
+
581
588
# static library
582
589
if (MI_BUILD_STATIC)
583
- if (WIN32 )
584
- # When building both static and shared libraries on Windows, a static library should use a
585
- # different output name to avoid the conflict with the import library of a shared one.
586
- string (REPLACE "mimalloc" "mimalloc-static" mi_static_libname ${mi_basename} )
587
- else ()
588
- set (mi_static_libname "${mi_basename} " )
589
- endif ()
590
590
add_library (mimalloc-static STATIC ${mi_sources} )
591
- set_target_properties ( mimalloc-static PROPERTIES OUTPUT_NAME ${mi_static_libname } )
591
+ set_property ( TARGET mimalloc-static PROPERTY OUTPUT_NAME ${mi_libname } )
592
592
set_property (TARGET mimalloc-static PROPERTY POSITION_INDEPENDENT_CODE ON )
593
593
target_compile_definitions (mimalloc-static PRIVATE ${mi_defines} MI_STATIC_LIB)
594
594
target_compile_options (mimalloc-static PRIVATE ${mi_cflags} ${mi_cflags_static} )
@@ -621,12 +621,15 @@ if (MI_BUILD_OBJECT)
621
621
)
622
622
623
623
# Copy the generated object file (`static.o`) to the output directory (as `mimalloc.o`)
624
- if (NOT WIN32 )
624
+ if (WIN32 )
625
+ set (mimalloc-obj-static "${CMAKE_CURRENT_BINARY_DIR} /mimalloc-obj.dir/$<CONFIG>/static${CMAKE_C_OUTPUT_EXTENSION} " )
626
+ else ()
625
627
set (mimalloc-obj-static "${CMAKE_CURRENT_BINARY_DIR} /CMakeFiles/mimalloc-obj.dir/src/static.c${CMAKE_C_OUTPUT_EXTENSION} " )
626
- set (mimalloc-obj-out "${CMAKE_CURRENT_BINARY_DIR} /${mi_basename}${CMAKE_C_OUTPUT_EXTENSION} " )
627
- add_custom_command (OUTPUT ${mimalloc-obj-out} DEPENDS mimalloc-obj COMMAND "${CMAKE_COMMAND} " -E copy "${mimalloc-obj-static}" "${mimalloc-obj-out}" )
628
- add_custom_target (mimalloc-obj-target ALL DEPENDS ${mimalloc-obj-out})
629
628
endif ()
629
+ set (mimalloc-obj-out "${CMAKE_CURRENT_BINARY_DIR} /${mi_libname}${CMAKE_C_OUTPUT_EXTENSION} " )
630
+ add_custom_command (OUTPUT ${mimalloc-obj-out} DEPENDS mimalloc-obj COMMAND "${CMAKE_COMMAND} " -E copy "${mimalloc-obj-static}" "${mimalloc-obj-out}" )
631
+ add_custom_target (mimalloc-obj-target ALL DEPENDS ${mimalloc-obj-out})
632
+
630
633
631
634
# the following seems to lead to cmake warnings/errors on some systems, disable for now :-(
632
635
# install(TARGETS mimalloc-obj EXPORT mimalloc DESTINATION ${mi_install_objdir})
@@ -635,9 +638,10 @@ if (MI_BUILD_OBJECT)
635
638
# but that fails cmake versions less than 3.10 so we leave it as is for now
636
639
install (FILES ${mimalloc-obj-static }
637
640
DESTINATION ${mi_install_objdir}
638
- RENAME ${mi_basename }${CMAKE_C_OUTPUT_EXTENSION} )
641
+ RENAME ${mi_libname }${CMAKE_C_OUTPUT_EXTENSION} )
639
642
endif ()
640
643
644
+
641
645
# pkg-config file support
642
646
set (mi_pc_libraries "" )
643
647
foreach (item IN LISTS mi_libraries)
@@ -648,12 +652,6 @@ foreach(item IN LISTS mi_libraries)
648
652
endif ()
649
653
endforeach ()
650
654
651
- if (MI_BUILD_STATIC) # prefer static linking with pkg-config
652
- set (mi_pc_libname "${mi_static_libname} " )
653
- else ()
654
- set (mi_pc_libname "${mi_basename} " )
655
- endif ()
656
-
657
655
include ("cmake/JoinPaths.cmake" )
658
656
join_paths(mi_pc_includedir "\$ {prefix}" "${CMAKE_INSTALL_INCLUDEDIR} " )
659
657
join_paths(mi_pc_libdir "\$ {prefix}" "${CMAKE_INSTALL_LIBDIR} " )
0 commit comments