-
Notifications
You must be signed in to change notification settings - Fork 25
/
CMakeLists.txt
60 lines (50 loc) · 2.33 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
cmake_minimum_required(VERSION 3.8)
project(path4gmns)
set(VER "" CACHE STRING "specific version number")
set(INIT_FILE "${CMAKE_SOURCE_DIR}/${PROJECT_NAME}/__init__.py")
if (VER STREQUAL "")
set(PIP_INSTALL python -m pip install ${PROJECT_NAME})
else()
set(PIP_INSTALL python -m pip install ${PROJECT_NAME}==${VER})
endif()
function(get_version OUTPUT_VAR)
file(READ "${INIT_FILE}" CONTENT)
string(REGEX MATCH "__version__ = ['\"]([^'\"]*)['\"]" _ ${CONTENT})
set(${OUTPUT_VAR} ${CMAKE_MATCH_1} PARENT_SCOPE)
endfunction()
get_version(LOCAL_VER)
add_custom_target(build
COMMAND ${CMAKE_COMMAND} -E echo "-- building ${PROJECT_NAME}-${LOCAL_VER}..."
COMMAND ${CMAKE_COMMAND} -E env python setup.py sdist bdist_wheel
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
add_custom_target(dev_install ALL
COMMAND ${CMAKE_COMMAND} -E echo "-- development install: ${PROJECT_NAME}-${LOCAL_VER}..."
COMMAND ${CMAKE_COMMAND} -E env python -m pip install -e ${CMAKE_SOURCE_DIR}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
add_custom_target(pypi_install
COMMAND ${CMAKE_COMMAND} -E echo "-- PyPI install: ${PROJECT_NAME}..."
COMMAND ${CMAKE_COMMAND} -E env python -m pip uninstall ${PROJECT_NAME}
COMMAND ${CMAKE_COMMAND} -E env ${PIP_INSTALL}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
add_custom_target(regular_install
COMMAND ${CMAKE_COMMAND} -E echo "-- regular install: ${PROJECT_NAME}-${LOCAL_VER}..."
COMMAND ${CMAKE_COMMAND} -E env python -m pip uninstall ${PROJECT_NAME}
COMMAND ${CMAKE_COMMAND} -E env python -m pip install ${CMAKE_SOURCE_DIR}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
add_custom_target(upgrade
COMMAND ${CMAKE_COMMAND} -E echo "-- upgrade ${PROJECT_NAME} to the lastest from PyPI..."
COMMAND ${CMAKE_COMMAND} -E env python -m pip install --upgrade ${PROJECT_NAME}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
add_custom_target(clean_cache
COMMAND ${CMAKE_COMMAND} -E echo "-- cleaning up CMake temporary dir and files..."
COMMAND ${CMAKE_COMMAND} -E remove_directory "${CMAKE_BINARY_DIR}/CMakeFiles"
COMMAND ${CMAKE_COMMAND} -E remove "${CMAKE_BINARY_DIR}/CMakeCache.txt"
COMMAND ${CMAKE_COMMAND} -E remove "${CMAKE_BINARY_DIR}/cmake_install.cmake"
COMMAND ${CMAKE_COMMAND} -E remove "${CMAKE_BINARY_DIR}/MakeFile"
COMMAND ${CMAKE_COMMAND} -E echo "-- clean complete."
)