Build: Support LLVM/Windows

Since LLVM/Windows emulates Visual Studio, CMake sets
CMAKE_C_SIMULATE_ID="MSVC" but does not set MSVC.  Thus, our build
system needs to enable most (but not all) of the Visual Studio features
when CMAKE_C_SIMLUATE_ID="MSVC".  Support for LLVM/Windows is currently
undocumented because it isn't a standalone build environment.  (It
requires the Visual Studio and Windows SDK headers and link libraries.)

Closes #786
This commit is contained in:
DRC 2024-09-16 12:30:27 -04:00
parent a9f7490cda
commit 2351a2d558
3 changed files with 33 additions and 20 deletions

View File

@ -22,9 +22,16 @@ function(pad_number NUMBER OUTPUT_LEN)
set(${NUMBER} ${NUM} PARENT_SCOPE)
endif()
endfunction()
pad_number(VERSION_MINOR 3)
pad_number(VERSION_REVISION 3)
set(LIBJPEG_TURBO_VERSION_NUMBER ${VERSION_MAJOR}${VERSION_MINOR}${VERSION_REVISION})
set(TMP_VERSION_MINOR ${VERSION_MINOR})
set(TMP_VERSION_REVISION ${VERSION_REVISION})
pad_number(TMP_VERSION_MINOR 3)
pad_number(TMP_VERSION_REVISION 3)
set(LIBJPEG_TURBO_VERSION_NUMBER
${VERSION_MAJOR}${TMP_VERSION_MINOR}${TMP_VERSION_REVISION})
set(MSVC_LIKE 0)
if(MSVC OR CMAKE_C_SIMULATE_ID STREQUAL "MSVC")
set(MSVC_LIKE 1)
endif()
# The libjpeg-turbo build system has never supported and will never support
# being integrated into another build system using add_subdirectory(), because
@ -143,7 +150,7 @@ message(STATUS "${BITS}-bit build (${CPU_TYPE})")
###############################################################################
if(WIN32)
if(MSVC)
if(MSVC_LIKE)
set(CMAKE_INSTALL_DEFAULT_PREFIX "c:/${CMAKE_PROJECT_NAME}")
else()
set(CMAKE_INSTALL_DEFAULT_PREFIX "c:/${CMAKE_PROJECT_NAME}-gcc")
@ -390,7 +397,7 @@ set(TURBOJPEG_SO_VERSION 0.${TURBOJPEG_SO_AGE}.0)
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UC)
if(MSVC)
if(MSVC_LIKE)
option(WITH_CRT_DLL
"Link all ${CMAKE_PROJECT_NAME} libraries and executables with the C run-time DLL (msvcr*.dll) instead of the static C run-time library (libcmt*.lib.) The default is to use the C run-time DLL only with the libraries and executables that need it."
FALSE)
@ -407,7 +414,7 @@ if(MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
endif()
message(STATUS "Visual C++ run-time library: ${CMAKE_MSVC_RUNTIME_LIBRARY} (WITH_CRT_DLL = ${WITH_CRT_DLL})")
else()
elseif(MSVC)
foreach(var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
if(${var} MATCHES "/MD")
@ -459,7 +466,7 @@ if(SIZE_T EQUAL UNSIGNED_LONG)
check_c_source_compiles("int main(int argc, char **argv) { unsigned long a = argc; return __builtin_ctzl(a); }"
HAVE_BUILTIN_CTZL)
endif()
if(MSVC)
if(MSVC_LIKE)
check_include_files("intrin.h" HAVE_INTRIN_H)
endif()
@ -672,7 +679,7 @@ if(ENABLE_STATIC)
add_library(jpeg-static STATIC ${JPEG_SOURCES} ${SIMD_TARGET_OBJECTS}
${SIMD_OBJS} $<TARGET_OBJECTS:jpeg12-static>
$<TARGET_OBJECTS:jpeg16-static>)
if(NOT MSVC)
if(NOT MSVC_LIKE)
set_target_properties(jpeg-static PROPERTIES OUTPUT_NAME jpeg)
endif()
endif()
@ -689,7 +696,7 @@ if(WITH_TURBOJPEG)
include_directories(${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2})
set(TJMAPFILE ${CMAKE_CURRENT_SOURCE_DIR}/src/turbojpeg-mapfile.jni)
endif()
if(MSVC)
if(MSVC_LIKE)
configure_file(${CMAKE_SOURCE_DIR}/win/turbojpeg.rc.in
${CMAKE_BINARY_DIR}/win/turbojpeg.rc)
set(TURBOJPEG_SOURCES ${TURBOJPEG_SOURCES}
@ -765,7 +772,7 @@ if(WITH_TURBOJPEG)
$<TARGET_OBJECTS:turbojpeg16-static>)
set_property(TARGET turbojpeg-static PROPERTY COMPILE_FLAGS
"-DBMP_SUPPORTED -DPPM_SUPPORTED")
if(NOT MSVC)
if(NOT MSVC_LIKE)
set_target_properties(turbojpeg-static PROPERTIES OUTPUT_NAME turbojpeg)
endif()
@ -1955,7 +1962,7 @@ if(WITH_TURBOJPEG)
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT bin)
install(TARGETS tjbench
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT bin)
if(NOT CMAKE_VERSION VERSION_LESS "3.1" AND MSVC AND
if(NOT CMAKE_VERSION VERSION_LESS "3.1" AND MSVC_LIKE AND
CMAKE_C_LINKER_SUPPORTS_PDB)
install(FILES "$<TARGET_PDB_FILE:turbojpeg>"
DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT bin OPTIONAL)

View File

@ -66,7 +66,7 @@ endif() # Linux
if(WIN32)
if(MSVC)
if(MSVC_LIKE)
set(INST_PLATFORM "Visual C++")
set(INST_ID vc)
set(INST_NAME ${CMAKE_PROJECT_NAME}-${VERSION}-${INST_ID})

View File

@ -9,7 +9,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/..)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/..)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/..)
if(MSVC)
if(MSVC_LIKE)
# Build all configurations against shared C library
if(CMAKE_VERSION VERSION_EQUAL "3.15" OR
CMAKE_VERSION VERSION_GREATER "3.15")
@ -21,7 +21,7 @@ if(MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)
endif()
message(STATUS "Visual C++ run-time library for libjpeg API DLL: ${CMAKE_MSVC_RUNTIME_LIBRARY}")
else()
elseif(MSVC)
foreach(var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
if(${var} MATCHES "/MT")
@ -43,7 +43,7 @@ endif()
if(WIN32)
set(DEFFILE ../win/jpeg${SO_MAJOR_VERSION}.def)
endif()
if(MSVC)
if(MSVC_LIKE)
configure_file(${CMAKE_SOURCE_DIR}/win/jpeg.rc.in
${CMAKE_BINARY_DIR}/win/jpeg.rc)
set(JPEG_SRCS ${JPEG_SRCS} ${CMAKE_BINARY_DIR}/win/jpeg.rc)
@ -64,12 +64,18 @@ if(MAPFLAG)
set_target_properties(jpeg PROPERTIES
LINK_FLAGS "${MAPFLAG}${CMAKE_CURRENT_BINARY_DIR}/../libjpeg.map")
endif()
if(MSVC)
if(MSVC_LIKE)
set_target_properties(jpeg PROPERTIES
RUNTIME_OUTPUT_NAME jpeg${SO_MAJOR_VERSION})
# The jsimd_*.c file is built using /MT, so this prevents a linker warning.
set_target_properties(jpeg PROPERTIES LINK_FLAGS
"/NODEFAULTLIB:LIBCMT /NODEFAULTLIB:LIBCMTD")
# The jsimd_*.c file is built to use libcmt or libcmtd, so this prevents a
# linker warning.
if(MSVC)
set_target_properties(jpeg PROPERTIES LINK_FLAGS
"/NODEFAULTLIB:LIBCMT /NODEFAULTLIB:LIBCMTD")
else()
set_target_properties(jpeg PROPERTIES LINK_FLAGS
"-Wl,-nodefaultlib:libcmt -Wl,-nodefaultlib:libcmtd")
endif()
elseif(MINGW)
set_target_properties(jpeg PROPERTIES SUFFIX -${SO_MAJOR_VERSION}.dll)
endif()
@ -126,7 +132,7 @@ install(TARGETS jpeg EXPORT ${CMAKE_PROJECT_NAME}Targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT bin)
install(TARGETS cjpeg djpeg jpegtran
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT bin)
if(NOT CMAKE_VERSION VERSION_LESS "3.1" AND MSVC AND
if(NOT CMAKE_VERSION VERSION_LESS "3.1" AND MSVC_LIKE AND
CMAKE_C_LINKER_SUPPORTS_PDB)
install(FILES "$<TARGET_PDB_FILE:jpeg>"
DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT bin OPTIONAL)