forked from TRIQS/cpp2py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
154 lines (129 loc) · 6.73 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# Start configuration
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
project(CPP2PY VERSION 2.0.0 LANGUAGES C CXX)
get_directory_property(IS_SUBPROJECT PARENT_DIRECTORY)
include(CheckIncludeFile)
include(CheckIncludeFileCXX)
# Default to Release build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Type of build" FORCE)
endif()
message(STATUS "-------- BUILD-TYPE: ${CMAKE_BUILD_TYPE} -------------")
# Build static library
set(BUILD_SHARED_LIBS OFF)
# Check CMAKE_INSTALL_PREFIX : must be provided and absolute
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT OR (NOT IS_ABSOLUTE ${CMAKE_INSTALL_PREFIX}))
message(FATAL_ERROR "CMAKE_INSTALL_PREFIX must be specified and must be an absolute path.\n There is no default.\n Current value : ${CMAKE_INSTALL_PREFIX}\n. e.g. ... -DCMAKE_INSTALL_PREFIX=$HOME/triqs_install")
endif()
message(STATUS "Installation directory will be ${CMAKE_INSTALL_PREFIX}")
set(CPP2PY_BINARY_DIR ${PROJECT_BINARY_DIR} CACHE STRING "Binary directory of the Cpp2Py Project")
# add ./cmake to the path for module
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
# log info
message( STATUS "-------- cpp2py version and git hash detection -------------")
find_package(Git)
# Get the Git Hash
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
OUTPUT_VARIABLE CPP2PY_GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message(STATUS "Cpp2py version : ${CPP2PY_VERSION}")
message(STATUS "Git hash : ${CPP2PY_GIT_HASH}")
# LIBCLANG : try to set LIBCLANG_LOCATION and LIBCLANG_CXX_FLAGS automatically
MESSAGE(STATUS "-------- LibClang detection -------------")
find_package(LibClang)
MESSAGE(STATUS "LibClang location: ${LIBCLANG_LOCATION}")
MESSAGE(STATUS "LibClang additional flags: ${LIBCLANG_CXX_FLAGS}")
# allow user to modify
set(LIBCLANG_CXX_FLAGS "${LIBCLANG_CXX_FLAGS}" CACHE STRING "Additional flags to be passed to libclang when parsing with clang")
set(LIBCLANG_LOCATION "${LIBCLANG_LOCATION}" CACHE STRING "Location of the libclang library")
# --- Python ---
find_package(Python)
set(CPP2PY_PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE} CACHE FILEPATH "Python Executable")
set(CPP2PY_PYTHON_LIB_DEST_ROOT ${PYTHON_LIB_DEST_ROOT} CACHE FILEPATH "Python module directory")
add_library(cpp2py::python_and_numpy ALIAS python_and_numpy)
install(TARGETS python_and_numpy EXPORT Cpp2PyTargets)
# find_package(Python3 COMPONENTS Development Interpreter)
# set(PYTHON_VERSION_MAJOR ${Python3_VERSION_MAJOR})
# set(PYTHON_VERSION_MINOR ${Python3_VERSION_MINOR})
# set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
# set(PYTHON_INCLUDE_DIRS ${Python3_INCLUDE_DIRS})
# set(PYTHON_LIBRARY ${Python3_LIBRARIES})
# set(PYTHON_SITE_PKG ${Python3_SITELIB})
# find_package(NumPy)
# if(BUILD_DEBIAN_PACKAGE)
# set(PYTHON_LIB_DEST_DIR dist-packages)
# else()
# set(PYTHON_LIB_DEST_DIR site-packages)
# endif()
# set(PYTHON_LIB_DEST_ROOT lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/${PYTHON_LIB_DEST_DIR} CACHE PATH "Install directory for Python Modules relative to CMAKE_INSTALL_PREFIX")
# message(STATUS "Python modules will be installed in ${CMAKE_INSTALL_PREFIX}/${PYTHON_LIB_DEST_ROOT}")
# subdirs
add_subdirectory(bin) # Executables
add_subdirectory(cmake) # Exported Cpp2Py-Config
add_subdirectory(c++/cpp2py)
# The python modules
add_subdirectory(cpp2py)
add_subdirectory(cpp2rst)
add_subdirectory(cpp2cxx)
#--------------------------------------------------------
# Libclang Warning
#--------------------------------------------------------
if (NOT LIBCLANG_LOCATION)
MESSAGE(STATUS "**************************************************************************************")
MESSAGE(STATUS "************************** WARNING ********************************")
MESSAGE(STATUS " ")
MESSAGE(STATUS " Can not find libclang ")
MESSAGE(STATUS " You can use cpp2py to compile a code, but c++2py, c++2rst, c++2cxx will not work")
MESSAGE(STATUS " ")
MESSAGE(STATUS "************************** WARNING ********************************")
MESSAGE(STATUS "**************************************************************************************")
endif()
#--------------------------------------------------------
# Remind the user how to set up his/her variables
#--------------------------------------------------------
if(NOT IS_SUBPROJECT)
# Configure and install the file to source to setup the environment variables
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cpp2pyvars.sh.in ${CMAKE_CURRENT_BINARY_DIR}/cpp2pyvars.sh @ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cpp2py.modulefile.in ${CMAKE_CURRENT_BINARY_DIR}/cpp2py.modulefile @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cpp2pyvars.sh DESTINATION ${CMAKE_INSTALL_PREFIX}/share)
message(STATUS "***************************************************************")
message(STATUS "* Use : ")
message(STATUS "* source ${CMAKE_INSTALL_PREFIX}/share/cpp2pyvars.sh ")
message(STATUS "* to set up the environment variables ")
if(DEFINED ENV{MODULEPATH})
message(STATUS "* ")
message(STATUS "* Consider adding ${CMAKE_CURRENT_BINARY_DIR}/cpp2py.modulefile")
message(STATUS "* to your environment modules ")
endif()
message(STATUS "***************************************************************")
endif()
# uninstall target
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif()
#--------------------------------------------------------
# Packaging
#--------------------------------------------------------
option(BUILD_DEBIAN_PACKAGE "Build a deb package" OFF)
if(BUILD_DEBIAN_PACKAGE)
if(NOT CMAKE_INSTALL_PREFIX STREQUAL "/usr")
message(FATAL_ERROR "CMAKE_INSTALL_PREFIX must be /usr for packaging")
endif()
set(CPACK_PACKAGE_NAME cpp2py)
set(CPACK_GENERATOR "DEB")
set(CPACK_PACKAGE_VERSION ${CPP2PY_VERSION})
set(CPACK_PACKAGE_CONTACT "https://github.com/TRIQS/cpp2py")
execute_process(COMMAND dpkg --print-architecture OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE OUTPUT_STRIP_TRAILING_WHITESPACE)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "python, python-mako, python-numpy, python-h5py, python-scipy")
set(CPACK_DEBIAN_PACKAGE_CONFLICTS "triqs (>= 2.1)")
SET(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
SET(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS ON)
include(CPack)
endif()