-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
142 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,87 @@ | ||
cmake_minimum_required(VERSION 3.15) | ||
project(${SKBUILD_PROJECT_NAME} LANGUAGES CXX) | ||
message(STATUS "") | ||
message(STATUS "------------------------------------------------------------------------") | ||
message(STATUS " Project Cytnx (core), A Cross-section of Python & C++,Tensor network library ") | ||
message(STATUS "------------------------------------------------------------------------") | ||
message(STATUS "") | ||
|
||
# ##################################################################### | ||
# ## CMAKE and CXX VERSION | ||
# ##################################################################### | ||
cmake_minimum_required(VERSION 3.20) | ||
|
||
include(cmake/target_sources_local.cmake) | ||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
|
||
message(STATUS " Generator: ${CMAKE_GENERATOR}") | ||
message(STATUS " Build Target: ${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}") | ||
message(STATUS " Installation Prefix: ${CMAKE_INSTALL_PREFIX}") | ||
set(CMAKE_POSITION_INDEPENDENT_CODE ON) | ||
|
||
# ##################################################################### | ||
# Version information | ||
# ##################################################################### | ||
include(version.cmake) | ||
set(CYTNX_CORE_VERSION | ||
${CYTNX_CORE_VERSION_MAJOR}.${CYTNX_CORE_VERSION_MINOR}.${CYTNX_CORE_VERSION_PATCH} | ||
) | ||
|
||
## Project: | ||
project(CYTNX_CORE VERSION ${CYTNX_CORE_VERSION} LANGUAGES CXX C) | ||
add_library(cytnx_core STATIC) | ||
set_property(TARGET cytnx_core PROPERTY C_VISIBILITY_PRESET hidden) | ||
set_property(TARGET cytnx_core PROPERTY VISIBILITY_INLINES_HIDDEN ON) | ||
|
||
message(STATUS " Current source dir: ${CMAKE_CURRENT_SOURCE_DIR}") | ||
target_include_directories(cytnx_core | ||
PRIVATE | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/src | ||
PUBLIC | ||
$<INSTALL_INTERFACE:include> | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/include> | ||
) | ||
# cpp source directory | ||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/src) | ||
target_compile_definitions(cytnx_core PUBLIC _LIBCPP_DISABLE_AVAILABILITY) | ||
target_compile_definitions(cytnx_core PUBLIC _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION) | ||
target_compile_options(cytnx_core PUBLIC -Wformat=0 -w -fsized-deallocation) | ||
target_compile_features(cytnx_core PUBLIC cxx_std_17) | ||
|
||
|
||
## install | ||
include(GNUInstallDirs) | ||
|
||
message(STATUS " install libdir: ${CMAKE_INSTALL_LIBDIR}") | ||
message(STATUS " install includedir: ${CMAKE_INSTALL_INCLUDEDIR}") | ||
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/cytnx_core) | ||
INSTALL(TARGETS cytnx_core EXPORT cytnx_targets | ||
LIBRARY | ||
DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
COMPONENT libraries | ||
ARCHIVE | ||
DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
COMPONENT libraries | ||
PUBLIC_HEADER | ||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} | ||
COMPONENT Development | ||
) | ||
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/include/ | ||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} | ||
COMPONENT headers | ||
FILES_MATCHING PATTERN "*.h*") | ||
|
||
export(EXPORT cytnx_targets FILE ${CMAKE_CURRENT_BINARY_DIR}/CytnxTargets.cmake NAMESPACE cytnx_core::) | ||
export(PACKAGE cytnx_core) | ||
|
||
# ##################################################################### | ||
# Pybind | ||
# ##################################################################### | ||
set(PYBIND11_FINDPYTHON ON) | ||
find_package(pybind11 CONFIG REQUIRED) | ||
|
||
pybind11_add_module(_core MODULE src/main.cpp) | ||
install(TARGETS _core DESTINATION ${SKBUILD_PROJECT_NAME}) | ||
pybind11_add_module(pycytnx MODULE src/cpp/pybind/main.cpp) | ||
target_link_libraries(pycytnx PUBLIC cytnx_core) | ||
#install(TARGETS pycytnx DESTINATION ${SKBUILD_PROJECT_NAME}) | ||
install(TARGETS pycytnx DESTINATION ${CMAKE_INSTALL_PREFIX}/cytnx_core) | ||
message(STATUS " skbuild Installation Prefix: ${SKBUILD_PROJECT_NAME}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# NOTE: This helper function assumes no generator expressions are used | ||
# for the source files | ||
function(target_sources_local target) | ||
if(POLICY CMP0076) | ||
# New behavior is available, so just forward to it by ensuring | ||
# that we have the policy set to request the new behavior, but | ||
# don't change the policy setting for the calling scope | ||
cmake_policy(PUSH) | ||
cmake_policy(SET CMP0076 NEW) | ||
target_sources(${target} ${ARGN}) | ||
cmake_policy(POP) | ||
return() | ||
endif() | ||
|
||
# Must be using CMake 3.12 or earlier, so simulate the new behavior | ||
unset(_srcList) | ||
get_target_property(_targetSourceDir ${target} SOURCE_DIR) | ||
|
||
foreach(src ${ARGN}) | ||
if(NOT src STREQUAL "PRIVATE" AND | ||
NOT src STREQUAL "PUBLIC" AND | ||
NOT src STREQUAL "INTERFACE" AND | ||
NOT IS_ABSOLUTE "${src}") | ||
# Relative path to source, prepend relative to where target was defined | ||
file(RELATIVE_PATH src "${_targetSourceDir}" "${CMAKE_CURRENT_LIST_DIR}/${src}") | ||
endif() | ||
list(APPEND _srcList ${src}) | ||
endforeach() | ||
target_sources(${target} ${_srcList}) | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
|
||
#include <cstring> | ||
|
||
namespace cytnx_core { | ||
|
||
void test(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
target_sources_local(cytnx_core | ||
PRIVATE | ||
|
||
# put cpp files here | ||
test.cpp | ||
|
||
) | ||
|
||
#add_subdirectory(storage) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#include "test.hpp" | ||
#include <iostream> | ||
|
||
void test() { std::cout << "Hello from test" << std::endl; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from cytnx_core._core import hello_from_bin | ||
from cytnx_core.pycytnx import hello_from_bin | ||
|
||
|
||
def hello() -> str: | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
uv sync --default-index https://pypi.org/simple |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
set(CYTNX_CORE_VERSION_MAJOR 0) | ||
set(CYTNX_CORE_VERSION_MINOR 1) | ||
set(CYTNX_CORE_VERSION_PATCH 0) |