-
Notifications
You must be signed in to change notification settings - Fork 169
/
CMakeLists.txt
134 lines (119 loc) · 4.42 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
CMAKE_MINIMUM_REQUIRED(VERSION 3.0 FATAL_ERROR)
PROJECT( HashDeepLearning )
SET( CMAKE_CXX_STANDARD 11 )
# cross-platform OpenMP find
IF(APPLE)
# MESSAGE (STATUS "${OpenMP_LIBRARIES}")
IF ("${OpenMP_LIBRARIES}" STREQUAL "")
FIND_LIBRARY(OpenMP_LIBRARY
NAMES omp
)
FIND_PATH(OpenMP_INCLUDE_DIR
omp.h
)
MARK_AS_ADVANCED(OpenMP_LIBRARY OpenMP_INCLUDE_DIR)
INCLUDE(FINDPACKAGEHANDLESTANDARDARGS)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenMP DEFAULT_MSG
OpenMP_LIBRARY OpenMP_INCLUDE_DIR)
IF (OpenMP_FOUND)
# MESSAGE (STATUS "OpenMP FOUND")
SET(OpenMP_LIBRARIES ${OpenMP_LIBRARY} CACHE STRING "Cache OpenMP Lib" FORCE)
SET(OpenMP_INCLUDE_DIRS ${OpenMP_INCLUDE_DIR} CACHE STRING "Cache OpenMP Include" FORCE)
SET(OpenMP_COMPILE_OPTIONS -XPREPROCESSOR -FOpenMP -LOMP)
ADD_LIBRARY(OpenMP::OpenMP SHARED IMPORTED)
SET_TARGET_PROPERTIES(OpenMP::OpenMP PROPERTIES
IMPORTED_LOCATION ${OpenMP_LIBRARIES}
INTERFACE_INCLUDE_DIRECTORIES "${OpenMP_INCLUDE_DIRS}"
INTERFACE_COMPILE_OPTIONS "${OpenMP_COMPILE_OPTIONS}"
)
ADD_DEFINITIONS(-D_OPENMP="${OpenMP_CXX_VERSION}")
SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}" )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
ENDIF()
ENDIF()
ELSE()
FIND_PACKAGE(OpenMP REQUIRED)
SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}" )
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}" )
ENDIF()
# build dependencies
INCLUDE( ExternalProject )
FIND_PACKAGE( Git REQUIRED )
OPTION( USE_GIT_PROTOCOL "If behind a firewall turn this off to use https instead." OFF )
function(functionInstallExternalCMakeProject ep_name)
ExternalProject_Get_Property(${ep_name} binary_dir)
install(SCRIPT ${binary_dir}/cmake_install.cmake)
endfunction()
ExternalProject_Add(
ZLIB
DEPENDS ""
GIT_REPOSITORY https://github.com/madler/zlib.git
GIT_TAG v1.2.11
SOURCE_DIR ZLIB-source
BINARY_DIR ZLIB-build
UPDATE_COMMAND ""
PATCH_COMMAND ""
# INSTALL_COMMAND ""
CMAKE_GENERATOR ${gen}
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX:STRING=${PROJECT_BINARY_DIR}/ep
-DINSTALL_BIN_DIR:STRING=${PROJECT_BINARY_DIR}/ep/bin
-DINSTALL_INC_DIR:STRING=${PROJECT_BINARY_DIR}/ep/include
-DINSTALL_LIB_DIR:STRING=${PROJECT_BINARY_DIR}/ep/lib
-DINSTALL_MAN_DIR:STRING=${PROJECT_BINARY_DIR}/ep/share/man
-DINSTALL_PKGCONFIG_DIR:STRING=${PROJECT_BINARY_DIR}/ep/share/pkgconfig
-DCMAKE_BUILD_TYPE:STRING=Release
)
functionInstallExternalCMakeProject(ZLIB)
# set the expected zlib libraries
IF( WIN32 )
SET( ZLIB_LIB_DEBUG ${PROJECT_BINARY_DIR}/ep/lib/zlibstaticd.lib )
SET( ZLIB_LIB_RELEASE ${PROJECT_BINARY_DIR}/ep/lib/zlibstatic.lib )
ELSE()
SET( ZLIB_LIB_DEBUG ${PROJECT_BINARY_DIR}/ep/lib/libz.a )
SET( ZLIB_LIB_RELEASE ${PROJECT_BINARY_DIR}/ep/lib/libz.a )
ENDIF()
ExternalProject_Add(
CNPY
DEPENDS ZLIB
GIT_REPOSITORY https://github.com/sarthakpati/cnpy.git
# GIT_TAG v1.2.11
SOURCE_DIR CNPY-source
BINARY_DIR CNPY-build
UPDATE_COMMAND ""
PATCH_COMMAND ""
# INSTALL_COMMAND ""
CMAKE_GENERATOR ${gen}
CMAKE_ARGS
-DZLIB_INCLUDE_DIR:STRING=${PROJECT_BINARY_DIR}/ep/include
-DZLIB_LIBRARY_DEBUG:STRING=${ZLIB_LIB_DEBUG}
-DZLIB_LIBRARY_RELEASE:STRING=${ZLIB_LIB_RELEASE}
-DCMAKE_INSTALL_PREFIX:STRING=${PROJECT_BINARY_DIR}/ep
-DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS}
-DCMAKE_BUILD_TYPE:STRING=Release
)
functionInstallExternalCMakeProject(CNPY)
INCLUDE_DIRECTORIES( ${PROJECT_BINARY_DIR}/ep/include )
# set CNPY lib path
IF( WIN32 )
SET( CNPY_LIB ${PROJECT_BINARY_DIR}/ep/lib/cnpy.lib )
ELSE()
SET( CNPY_LIB ${PROJECT_BINARY_DIR}/ep/lib/libcnpy.a )
ENDIF()
# now build SLIDE
FILE( GLOB_RECURSE SLIDE_SOURCES "${PROJECT_SOURCE_DIR}/SLIDE/*.cpp" )
FILE( GLOB_RECURSE SLIDE_HEADERS "${PROJECT_SOURCE_DIR}/SLIDE/*.h" )
# add library to decouple compilation
ADD_LIBRARY( SLIDE_LIB ${SLIDE_HEADERS} ${SLIDE_SOURCES} )
ADD_DEPENDENCIES( SLIDE_LIB CNPY )
TARGET_LINK_LIBRARIES( SLIDE_LIB ${CNPY_LIB} )
# add executable
SET( SLIDE_EXE_NAME runme )
ADD_EXECUTABLE( ${SLIDE_EXE_NAME} ${PROJECT_SOURCE_DIR}/SLIDE/main.cpp )
ADD_DEPENDENCIES( ${SLIDE_EXE_NAME} SLIDE_LIB )
TARGET_LINK_LIBRARIES(
${SLIDE_EXE_NAME}
SLIDE_LIB
${CNPY_LIB}
${ZLIB_LIB_RELEASE} ) # TBD: this should be changed to use ${ZLIB_LIBRARIES} for debug portability on Windows
INSTALL( TARGETS ${SLIDE_EXE_NAME} DESTINATION bin )