Skip to content

Commit

Permalink
Simplify CMakeLists.txt even more
Browse files Browse the repository at this point in the history
  • Loading branch information
basnijholt committed Nov 20, 2023
1 parent 423b8ed commit e333c2e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 59 deletions.
20 changes: 10 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,29 @@ if(APPLE)
project(qsim LANGUAGES CXX)
find_package(OpenMP REQUIRED) # Automatically happens for Linux
else()
execute_process(COMMAND which nvcc OUTPUT_VARIABLE has_nvcc)
if(has_nvcc STREQUAL "")
execute_process(COMMAND which hipcc OUTPUT_VARIABLE has_hipcc)
if(has_hipcc STREQUAL "")
project(qsim LANGUAGES CXX)
else()
execute_process(COMMAND which nvcc OUTPUT_VARIABLE has_nvcc OUTPUT_STRIP_TRAILING_WHITESPACE)
if(has_nvcc)
project(qsim LANGUAGES CXX CUDA)
else()
execute_process(COMMAND which hipcc OUTPUT_VARIABLE has_hipcc OUTPUT_STRIP_TRAILING_WHITESPACE)
if(has_hipcc)
project(qsim LANGUAGES CXX HIP)
else()
project(qsim LANGUAGES CXX)
endif()
else()
project(qsim LANGUAGES CXX CUDA)
endif()
endif()

# Add subdirectories based on the architecture or available compilers
ADD_SUBDIRECTORY(pybind_interface/basic)
ADD_SUBDIRECTORY(pybind_interface/decide)
if(NOT APPLE_ARM)
if(NOT has_nvcc STREQUAL "")
if(has_nvcc)
ADD_SUBDIRECTORY(pybind_interface/cuda)
if(DEFINED ENV{CUQUANTUM_ROOT})
ADD_SUBDIRECTORY(pybind_interface/custatevec)
endif()
elseif(NOT has_hipcc STREQUAL "")
elseif(has_hipcc)
ADD_SUBDIRECTORY(pybind_interface/hip)
endif()

Expand Down
71 changes: 22 additions & 49 deletions pybind_interface/decide/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,73 +1,46 @@
cmake_minimum_required(VERSION 3.11)

if(APPLE_ARM)
project(qsim LANGUAGES CXX)
else()
execute_process(COMMAND which nvcc OUTPUT_VARIABLE has_nvcc)
if(has_nvcc STREQUAL "")
execute_process(COMMAND which hipcc OUTPUT_VARIABLE has_hipcc)
if(has_hipcc STREQUAL "")
project(qsim)
else()
project(qsim LANGUAGES CXX HIP)
endif()
else()
project(qsim LANGUAGES CXX CUDA)
endif()
endif()

IF (WIN32)
if(WIN32)
set(CMAKE_CXX_FLAGS "/O2 /openmp")
ELSE()
else()
set(CMAKE_CXX_FLAGS "-O3 -fopenmp")
ENDIF()
endif()

if(APPLE AND NOT APPLE_ARM)
set(CMAKE_CXX_STANDARD 14)
include_directories("/usr/local/include" "/usr/local/opt/llvm/include")
link_directories("/usr/local/lib" "/usr/local/opt/llvm/lib")
endif()

INCLUDE(../GetPybind11.cmake)
include(../GetPybind11.cmake)

# Configure based on the detected platform
if(APPLE_ARM)
pybind11_add_module(qsim_decide decide.cpp)
elseif(has_nvcc STREQUAL "")
if(has_hipcc STREQUAL "")
pybind11_add_module(qsim_decide decide.cpp)
else()
list(APPEND CMAKE_MODULE_PATH "/opt/rocm/lib/cmake/hip")
find_package(HIP REQUIRED)
find_package(Python3 3.7 REQUIRED COMPONENTS Interpreter Development)

include_directories(${PYTHON_INCLUDE_DIRS} ${pybind11_SOURCE_DIR}/include)

hip_add_library(qsim_decide MODULE decide.cpp)

set_target_properties(qsim_decide PROPERTIES
PREFIX "${PYTHON_MODULE_PREFIX}"
SUFFIX "${PYTHON_MODULE_EXTENSION}"
)
set_source_files_properties(decide.cpp PROPERTIES LANGUAGE HIP)
endif()
else()
find_package(Python3 3.7 REQUIRED COMPONENTS Interpreter Development)
if(has_nvcc)
find_package(CUDA REQUIRED)

include_directories(${PYTHON_INCLUDE_DIRS} ${pybind11_SOURCE_DIR}/include)

cuda_add_library(qsim_decide MODULE decide.cpp)

if(DEFINED ENV{CUQUANTUM_ROOT})
target_compile_options(qsim_decide PRIVATE
$<$<COMPILE_LANGUAGE:CUDA>:-D__CUSTATEVEC__>
)
endif()

find_package(Python3 3.7 REQUIRED COMPONENTS Interpreter Development)
include_directories(${PYTHON_INCLUDE_DIRS} ${pybind11_SOURCE_DIR}/include)
set_target_properties(qsim_decide PROPERTIES
PREFIX "${PYTHON_MODULE_PREFIX}"
SUFFIX "${PYTHON_MODULE_EXTENSION}"
PREFIX "${PYTHON_MODULE_PREFIX}"
SUFFIX "${PYTHON_MODULE_EXTENSION}"
)
set_source_files_properties(decide.cpp PROPERTIES LANGUAGE CUDA)
elseif(has_hipcc)
list(APPEND CMAKE_MODULE_PATH "/opt/rocm/lib/cmake/hip")
find_package(HIP REQUIRED)
hip_add_library(qsim_decide MODULE decide.cpp)
set_source_files_properties(decide.cpp PROPERTIES LANGUAGE HIP)
find_package(Python3 3.7 REQUIRED COMPONENTS Interpreter Development)
include_directories(${PYTHON_INCLUDE_DIRS} ${pybind11_SOURCE_DIR}/include)
set_target_properties(qsim_decide PROPERTIES
PREFIX "${PYTHON_MODULE_PREFIX}"
SUFFIX "${PYTHON_MODULE_EXTENSION}"
)
else()
pybind11_add_module(qsim_decide decide.cpp)
endif()

0 comments on commit e333c2e

Please sign in to comment.