Skip to content

Commit f9397bc

Browse files
authored
Windows related changes in CMakeLists.txt (#5186)
Upstreaming some of our Windows related changes assuming that there is interest in this triton-lang/triton#5094 (comment) and hoping that it will not make it much more difficult to support this CMake file. --------- Signed-off-by: Anatoly Myachev <[email protected]>
1 parent 09fcc52 commit f9397bc

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

CMakeLists.txt

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
1515
project(triton CXX C)
1616
include(CTest)
1717

18-
if(NOT WIN32)
19-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
20-
endif()
21-
22-
18+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
2319

2420
# Options
2521
option(TRITON_BUILD_TUTORIALS "Build C++ Triton tutorials" ON)
@@ -56,10 +52,19 @@ endif()
5652
# used conditionally in this file and by lit tests
5753

5854
# Customized release build type with assertions: TritonRelBuildWithAsserts
59-
set(CMAKE_C_FLAGS_TRITONRELBUILDWITHASSERTS "-O2 -g")
60-
set(CMAKE_CXX_FLAGS_TRITONRELBUILDWITHASSERTS "-O2 -g")
61-
set(CMAKE_C_FLAGS_TRITONBUILDWITHO1 "-O1")
62-
set(CMAKE_CXX_FLAGS_TRITONBUILDWITHO1 "-O1")
55+
if(NOT MSVC)
56+
set(CMAKE_C_FLAGS_TRITONRELBUILDWITHASSERTS "-O2 -g")
57+
set(CMAKE_CXX_FLAGS_TRITONRELBUILDWITHASSERTS "-O2 -g")
58+
set(CMAKE_C_FLAGS_TRITONBUILDWITHO1 "-O1")
59+
set(CMAKE_CXX_FLAGS_TRITONBUILDWITHO1 "-O1")
60+
else()
61+
set(CMAKE_C_FLAGS_TRITONRELBUILDWITHASSERTS "/Zi /RTC1 /bigobj /Zc:preprocessor")
62+
set(CMAKE_CXX_FLAGS_TRITONRELBUILDWITHASSERTS "/Zi /RTC1 /bigobj /Zc:preprocessor")
63+
set(CMAKE_EXE_LINKER_FLAGS_TRITONRELBUILDWITHASSERTS "/debug:fastlink /INCREMENTAL")
64+
set(CMAKE_MODULE_LINKER_FLAGS_TRITONRELBUILDWITHASSERTS "/debug:fastlink /INCREMENTAL")
65+
set(CMAKE_SHARED_LINKER_FLAGS_TRITONRELBUILDWITHASSERTS "/debug:fastlink /INCREMENTAL")
66+
set(CMAKE_STATIC_LINKER_FLAGS_TRITONRELBUILDWITHASSERTS "/debug:fastlink /INCREMENTAL")
67+
endif()
6368

6469
# Default build type
6570
if(NOT CMAKE_BUILD_TYPE)
@@ -77,7 +82,11 @@ endif()
7782

7883
# Compiler flags
7984
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
80-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_FORMAT_MACROS -fPIC -std=gnu++17")
85+
if(NOT MSVC)
86+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_FORMAT_MACROS -fPIC -std=gnu++17")
87+
else()
88+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_FORMAT_MACROS")
89+
endif()
8190

8291

8392
# #########
@@ -131,7 +140,11 @@ endfunction()
131140

132141

133142
# Disable warnings that show up in external code (gtest;pybind11)
134-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wno-covered-switch-default -fvisibility=hidden")
143+
if(NOT MSVC)
144+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wno-covered-switch-default -fvisibility=hidden")
145+
else()
146+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX- /wd4244 /wd4624 /wd4715 /wd4530")
147+
endif()
135148

136149
include_directories(".")
137150
include_directories(${MLIR_INCLUDE_DIRS})
@@ -254,7 +267,7 @@ if(TRITON_BUILD_PYTHON_MODULE)
254267
LLVMAArch64CodeGen
255268
LLVMAArch64AsmParser
256269
)
257-
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
270+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64")
258271
list(APPEND TRITON_LIBRARIES
259272
LLVMX86CodeGen
260273
LLVMX86AsmParser
@@ -289,6 +302,8 @@ if(TRITON_BUILD_PYTHON_MODULE)
289302
target_link_libraries(triton PUBLIC ${TRITON_LIBRARIES})
290303
if(WIN32)
291304
target_link_libraries(triton PRIVATE ${CMAKE_DL_LIBS})
305+
set_target_properties(triton PROPERTIES SUFFIX ".pyd")
306+
set_target_properties(triton PROPERTIES PREFIX "lib")
292307
else()
293308
target_link_libraries(triton PRIVATE z)
294309
endif()
@@ -317,6 +332,8 @@ if(NOT TRITON_BUILD_PYTHON_MODULE)
317332
add_subdirectory(third_party/proton/dialect)
318333
endif()
319334

335+
find_package(Threads REQUIRED)
336+
320337
add_subdirectory(third_party/f2reduce)
321338
add_subdirectory(bin)
322339
add_subdirectory(test)

0 commit comments

Comments
 (0)