1if(NOT DEFINED NASM)
2  find_program(NASM NAMES nasm yasm DOC "Path to NASM/YASM executable")
3endif()
4message(STATUS "NASM = ${NASM}")
5
6if(SIMD_X86_64)
7  set(NAFLAGS -fwin64 -DWIN64 -D__x86_64__)
8else()
9  if(BORLAND)
10    set(NAFLAGS -fobj -DOBJ32)
11  else()
12    set(NAFLAGS -fwin32 -DWIN32)
13  endif()
14endif()
15set(NAFLAGS ${NAFLAGS} -I${CMAKE_SOURCE_DIR}/win/ -I${CMAKE_CURRENT_SOURCE_DIR}/)
16
17# This only works if building from the command line.  There is currently no way
18# to set a variable's value based on the build type when using the MSVC IDE.
19if(CMAKE_BUILD_TYPE STREQUAL "Debug"
20  OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
21  set(NAFLAGS ${NAFLAGS} -g)
22endif()
23
24if(SIMD_X86_64)
25  set(SIMD_BASENAMES jfdctflt-sse-64 jccolor-sse2-64 jcgray-sse2-64
26    jchuff-sse2-64 jcsample-sse2-64 jdcolor-sse2-64 jdmerge-sse2-64
27    jdsample-sse2-64 jfdctfst-sse2-64 jfdctint-sse2-64 jidctflt-sse2-64
28    jidctfst-sse2-64 jidctint-sse2-64 jidctred-sse2-64 jquantf-sse2-64
29    jquanti-sse2-64)
30  message(STATUS "Building x86_64 SIMD extensions")
31else()
32  set(SIMD_BASENAMES jsimdcpu jfdctflt-3dn jidctflt-3dn jquant-3dn jccolor-mmx
33    jcgray-mmx jcsample-mmx jdcolor-mmx jdmerge-mmx jdsample-mmx jfdctfst-mmx
34    jfdctint-mmx jidctfst-mmx jidctint-mmx jidctred-mmx jquant-mmx jfdctflt-sse
35    jidctflt-sse jquant-sse jccolor-sse2 jcgray-sse2 jchuff-sse2 jcsample-sse2
36    jdcolor-sse2 jdmerge-sse2 jdsample-sse2 jfdctfst-sse2 jfdctint-sse2
37    jidctflt-sse2 jidctfst-sse2 jidctint-sse2 jidctred-sse2 jquantf-sse2
38    jquanti-sse2)
39  message(STATUS "Building i386 SIMD extensions")
40endif()
41
42if(MSVC_IDE)
43  set(OBJDIR "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}")
44else()
45  set(OBJDIR ${CMAKE_CURRENT_BINARY_DIR})
46endif()
47
48file(GLOB INC_FILES *.inc)
49
50foreach(file ${SIMD_BASENAMES})
51  set(DEPFILE "")
52  set(SIMD_SRC ${CMAKE_CURRENT_SOURCE_DIR}/${file}.asm)
53  if(${file} MATCHES jccolor)
54    set(DEPFILE ${file})
55    string(REGEX REPLACE "jccolor" "jccolext" DEPFILE ${DEPFILE})
56    set(DEPFILE ${CMAKE_CURRENT_SOURCE_DIR}/${DEPFILE}.asm)
57  endif()
58  if(${file} MATCHES jcgray)
59    set(DEPFILE ${file})
60    string(REGEX REPLACE "jcgray" "jcgryext" DEPFILE ${DEPFILE})
61    set(DEPFILE ${CMAKE_CURRENT_SOURCE_DIR}/${DEPFILE}.asm)
62  endif()
63  if(${file} MATCHES jdcolor)
64    set(DEPFILE ${file})
65    string(REGEX REPLACE "jdcolor" "jdcolext" DEPFILE ${DEPFILE})
66    set(DEPFILE ${CMAKE_CURRENT_SOURCE_DIR}/${DEPFILE}.asm)
67  endif()
68  if(${file} MATCHES jdmerge)
69    set(DEPFILE ${file})
70    string(REGEX REPLACE "jdmerge" "jdmrgext" DEPFILE ${DEPFILE})
71    set(DEPFILE ${CMAKE_CURRENT_SOURCE_DIR}/${DEPFILE}.asm)
72  endif()
73  set(SIMD_OBJ ${OBJDIR}/${file}.obj)
74  add_custom_command(OUTPUT ${SIMD_OBJ}
75    DEPENDS ${SIMD_SRC} ${DEPFILE} ${INC_FILES}
76    COMMAND ${NASM} ${NAFLAGS} ${SIMD_SRC} -o${SIMD_OBJ})
77  set(SIMD_OBJS ${SIMD_OBJS} ${SIMD_OBJ})
78endforeach()
79
80set(SIMD_OBJS ${SIMD_OBJS} PARENT_SCOPE)
81add_custom_target(simd DEPENDS ${SIMD_OBJS})
82