-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
executable file
·94 lines (79 loc) · 3.6 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
cmake_minimum_required(VERSION 3.13.0 FATAL_ERROR)
project(pressio4py CXX)
# setting where other cmake commands are
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
# include commands for coloring prints
include(colors)
#=====================================================================
# we need c++14
#=====================================================================
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
#=====================================================================
### guard against in-source builds ###
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "In-source builds are not allowed.
Please make a new directory (e.g. build directory) and run CMake from there.")
endif()
### default to release if build type is empty ###
if (NOT CMAKE_BUILD_TYPE)
message(STATUS "${CMAKE_BUILD_TYPE} is not specified, defaulting to Release.")
set(CMAKE_BUILD_TYPE "Release")
endif()
### check if PRESSIO_INCLUDE_DIR is set ###
if (NOT PRESSIO_INCLUDE_DIR)
message(FATAL_ERROR "${PRESSIO_INCLUDE_DIR} is not specified, must be set.")
endif()
#----------------------------------------------------------------
include_directories(${PRESSIO_INCLUDE_DIR})
#find_package(pybind11 REQUIRED PATHS ${PYBIND11_DIR}/share/cmake)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/pybind11)
#----------------------------------------------------------------
# dir where all sources for pressio4py are
set(PRESSIO4PY_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(PRESSIO4PY_APPS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/pressio4pyApps)
#----------------------------------------------------------------
if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
endif()
#----------------------------------------------------------------
# get the working branch
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE PFPY_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE)
# get the commit hash of the pressio4py being used
execute_process(
COMMAND git rev-parse HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE SHORT_HASH_RESULT
OUTPUT_VARIABLE PFPY_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE)
#----------------------------------------------------------------
set(modulename _p4pyimpl)
pybind11_add_module(${modulename} ${PRESSIO4PY_SRC_DIR}/main_binder.cc)
target_compile_definitions(${modulename} PRIVATE MODNAME=${modulename})
if(${CMAKE_BUILD_TYPE} STREQUAL "Release")
# set min log level to info
target_compile_definitions(${modulename} PRIVATE PRESSIO_LOG_ACTIVE_MIN_LEVEL=2)
else()
# set min log level to 0
target_compile_definitions(${modulename} PRIVATE PRESSIO_LOG_ACTIVE_MIN_LEVEL=0)
endif()
### display some info ###
message("${Yellow}----------------------------------${ColourReset}")
message("${Yellow} Pressio4Py config info: ${ColourReset}")
message("${Yellow}----------------------------------${ColourReset}")
message("${Yellow} - C++ standard = ${CMAKE_CXX_STANDARD} ${ColourReset}")
message("${Yellow} - p4py version = ${VERSION_INFO} ${ColourReset}")
message("${Yellow} - p4py branch = ${PFPY_BRANCH} ${ColourReset}")
message("${Yellow} - p4py hash = ${PFPY_HASH} ${ColourReset}")
message("${Yellow} - Build dir = ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} ${ColourReset}")
message("${Yellow} - prefix = ${CMAKE_INSTALL_PREFIX} ${ColourReset}")
# add unit tests
# we have to do this because unit tests
# contain c++ code that is compiled too
add_subdirectory(tests_compiled)
#install(TARGETS pressio4py DESTINATION ${CMAKE_INSTALL_PREFIX})