11# SimpleMUSA.cmake
22# Minimal MUSA configuration without external dependencies
33
4- # Set MUSA paths
5- set (MUSA_ROOT "/usr/local/musa" CACHE PATH "MUSA toolkit root directory" )
6- set (MUSA_INCLUDE_DIR "${MUSA_ROOT} /include" )
7- set (MUSA_LIBRARY_DIR "${MUSA_ROOT} /lib" )
4+ # Set MUSA paths. MUSA_ROOT points at the runtime toolkit, while
5+ # MUSA_COMPILER_ROOT may point at an alternate mcc compiler install.
6+ set (MUSA_ROOT "/usr/local/musa" CACHE PATH "MUSA runtime toolkit root directory" )
7+ set (MUSA_COMPILER_ROOT "${MUSA_ROOT} " CACHE PATH "MUSA compiler root directory" )
8+ set (MUSA_INCLUDE_DIR "${MUSA_ROOT} /include" CACHE PATH "MUSA runtime include directory" )
9+ set (MUSA_LIBRARY_DIR "${MUSA_ROOT} /lib" CACHE PATH "MUSA runtime library directory" )
10+ set (MUSA_COMPILER_INCLUDE_DIR "${MUSA_COMPILER_ROOT} /include" CACHE PATH "MUSA compiler include directory" )
811
912# Find MUSA compiler (mcc)
1013find_program (MCC_EXECUTABLE
1114 NAMES mcc
12- PATHS "${MUSA_ROOT } /bin"
15+ PATHS "${MUSA_COMPILER_ROOT } /bin"
1316 ENV MUSA_PATH
1417 ENV MUSA_BIN_PATH
1518 PATH_SUFFIXES bin
19+ NO_DEFAULT_PATH
1620)
1721
1822if (NOT MCC_EXECUTABLE)
19- message (FATAL_ERROR "MUSA compiler (mcc) not found. Set MUSA_ROOT or MUSA_PATH." )
23+ find_program (MCC_EXECUTABLE
24+ NAMES mcc
25+ ENV MUSA_PATH
26+ ENV MUSA_BIN_PATH
27+ PATH_SUFFIXES bin
28+ )
29+ endif ()
30+
31+ if (NOT MCC_EXECUTABLE)
32+ message (FATAL_ERROR "MUSA compiler (mcc) not found. Set MUSA_COMPILER_ROOT, MUSA_ROOT, or MUSA_PATH." )
2033endif ()
2134
2235message (STATUS "Found MUSA compiler: ${MCC_EXECUTABLE} " )
36+ message (STATUS "MUSA compiler root: ${MUSA_COMPILER_ROOT} " )
37+ message (STATUS "MUSA runtime root: ${MUSA_ROOT} " )
2338
2439# Set MUSA_FOUND so ThrustCudaConfig.cmake can detect MUSA
2540set (MUSA_FOUND TRUE CACHE INTERNAL "MUSA found" )
@@ -43,6 +58,9 @@ message(STATUS "Found MUSA library: ${MUSA_LIBRARY}")
4358set (CMAKE_CXX_COMPILER "${MCC_EXECUTABLE} " CACHE FILEPATH "C++ compiler" FORCE )
4459
4560# Add MUSA path to compile options globally
61+ if (EXISTS "${MUSA_COMPILER_INCLUDE_DIR} " )
62+ add_compile_options (-isystem ${MUSA_COMPILER_INCLUDE_DIR} )
63+ endif ()
4664add_compile_options (--musa-path=${MUSA_ROOT} )
4765
4866# Set default MUSA architecture if not specified
@@ -122,8 +140,12 @@ function(musa_add_executable target_name)
122140 # Link MUSA runtime (no keyword to match existing code)
123141 target_link_libraries (${target_name} ${MUSA_LIBRARY} )
124142
125- # Include MUSA headers (use include_directories for directory-level)
126- include_directories (${MUSA_INCLUDE_DIR} )
143+ # Prefer compiler-matched headers such as mp_ext_32_intrinsics.h, while
144+ # still taking the runtime API and musart from MUSA_ROOT.
145+ if (EXISTS "${MUSA_COMPILER_INCLUDE_DIR} " )
146+ target_include_directories (${target_name} SYSTEM BEFORE PRIVATE ${MUSA_COMPILER_INCLUDE_DIR} )
147+ endif ()
148+ target_include_directories (${target_name} SYSTEM PRIVATE ${MUSA_INCLUDE_DIR} )
127149endfunction ()
128150
129151# Function to build MUSA libraries
@@ -185,6 +207,10 @@ function(musa_add_library target_name)
185207 # Link MUSA runtime (no keyword to match existing code)
186208 target_link_libraries (${target_name} ${MUSA_LIBRARY} )
187209
188- # Include MUSA headers (use include_directories for directory-level)
189- include_directories (${MUSA_INCLUDE_DIR} )
210+ # Prefer compiler-matched headers such as mp_ext_32_intrinsics.h, while
211+ # still taking the runtime API and musart from MUSA_ROOT.
212+ if (EXISTS "${MUSA_COMPILER_INCLUDE_DIR} " )
213+ target_include_directories (${target_name} SYSTEM BEFORE PRIVATE ${MUSA_COMPILER_INCLUDE_DIR} )
214+ endif ()
215+ target_include_directories (${target_name} SYSTEM PRIVATE ${MUSA_INCLUDE_DIR} )
190216endfunction ()
0 commit comments