-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
82 lines (66 loc) · 3.83 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
cmake_minimum_required(VERSION 2.8.9)
project(binarytree)
#Bring the headers, such as Student.h into the project
#include_directories("${CMAKE_SOURCE_DIR}/include/")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
#However, the file(GLOB...) allows for wildcard additions:
file(GLOB SOURCES "binarytree/*.c")
##########################################################################
# Debug options
# Build options to determine what level of debugging we are using
set(binarytreeDEBUG "OFF")
set(BUILD_DEBUG_LEVEL "0" CACHE STRING "0: None 1: -g 2: -g + _DEBUG")
# Determine if we are using some debugging
if(BUILD_DEBUG_LEVEL LESS 0 OR BUILD_DEBUG_LEVEL GREATER 2)
message(FATAL_ERROR "BUILD_DEBUG_LEVEL parameter must be an integer value of the range 0 to 2, inclusive.")
elseif(BUILD_DEBUG_LEVEL EQUAL 1)
add_definitions(-g)
elseif(BUILD_DEBUG_LEVEL EQUAL 2)
add_definitions(-D_DEBUG -g )
set(binarytreeDEBUG "ON")
endif(BUILD_DEBUG_LEVEL LESS 0 OR BUILD_DEBUG_LEVEL GREATER 2)
##########################################################################
# Executable
list(FILTER SOURCES EXCLUDE REGEX ".*binarytree/main.c$")
add_library(binarytree_obj OBJECT ${SOURCES})
add_library(binarytree_static STATIC $<TARGET_OBJECTS:binarytree_obj>)
add_executable(${PROJECT_NAME} "binarytree/main.c")
target_link_libraries(${PROJECT_NAME} binarytree_static)
################################################################################################
# These are for creating binarytree shared library for use with Python interface.
# Tested only on gcc for now.
##########################################################################
option(MAKE_SHARED_LIBRARY "Create an binarytree shared library to allow interfacing with python" OFF)
if(MAKE_SHARED_LIBRARY)
## Create binarytree library
#list(APPEND LIBRARY_SOURCES ${SOURCES})
#list(REMOVE_ITEM LIBRARY_SOURCES "main.c")
add_definitions(-fPIC) # Position independence required for use with Python
add_library(binarytree_shared SHARED $<TARGET_OBJECTS:binarytree_obj>)
set(PROJECT_PYTHON_DIR ${PROJECT_SOURCE_DIR}/pybinarytree/)
set(pybuildfile "${PROJECT_PYTHON_DIR}/build_options.py")
file(WRITE ${pybuildfile} "#!/usr/bin/env python\n")
file(APPEND ${pybuildfile} "\"\"\"\nCMAKE generated critical python file to enforce compatibility\n")
file(APPEND ${pybuildfile} "between C binarytree library structures and python class definitions.\n\"\"\"\n")
file(APPEND ${pybuildfile} "\nfrom ctypes import cdll\n")
file(APPEND ${pybuildfile} "\nfrom define_h import ON, OFF\n")
file(APPEND ${pybuildfile} "\n__all__ = [\n")
file(APPEND ${pybuildfile} " 'pybtlib',\n")
#file(APPEND ${pybuildfile} " 'pybintree_path',\n")
#file(APPEND ${pybuildfile} " 'libbintree_path',\n")
file(APPEND ${pybuildfile} " 'BUILD_DEBUG_LEVEL',\n")
file(APPEND ${pybuildfile} " '_DEBUG',\n")
file(APPEND ${pybuildfile} " 'ON',\n")
file(APPEND ${pybuildfile} " 'OFF',\n")
file(APPEND ${pybuildfile} " ]\n")
file(APPEND ${pybuildfile} "\npybintree_path = '${PROJECT_SOURCE_DIR}'\n")
file(APPEND ${pybuildfile} "libbintree_path = '${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libbinarytree_shared.so'\n")
file(APPEND ${pybuildfile} "\nBUILD_DEBUG_LEVEL = ${BUILD_DEBUG_LEVEL}\n")
file(APPEND ${pybuildfile} "_DEBUG = ${binarytreeDEBUG}\n")
file(APPEND ${pybuildfile} "\npybtlib = cdll.LoadLibrary(libbintree_path)\n")
file(APPEND ${pybuildfile} "\n\nif (__name__ == '__main__'):\n")
file(APPEND ${pybuildfile} " print '_DEBUG =', _DEBUG\n")
endif(MAKE_SHARED_LIBRARY)
################################################################################################