forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathCMakeLists.txt
631 lines (547 loc) · 23.3 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
# This file is a part of pandas. See LICENSE for details about reuse and
# copyright holders
#
# Assembled from BSD/MIT/Apache-licensed code from a variety of copyright
# holders, including at least
#
# Copyright 2012-25 Cloudera, Inc.
# Copyright (C) 2011-15 DyND Developers
# Copyright (C) 2012-15 Continuum Analytics, Inc.
cmake_minimum_required(VERSION 2.7)
project(pandas)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake_modules")
include(CMakeParseArguments)
set(BUILD_SUPPORT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build-support)
set(THIRDPARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty)
# Allow "make install" to not depend on all targets.
#
# Must be declared in the top-level CMakeLists.txt.
set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY true)
# For thirdparty libs: googletest
# include(toolchain)
set(CMAKE_MACOSX_RPATH 1)
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.9)
############################################################
# Compiler flags
############################################################
# compiler flags that are common across debug/release builds
# - msse4.2: Enable sse4.2 compiler intrinsics.
# - Wall: Enable all warnings.
# - Wno-sign-compare: suppress warnings for comparison between signed and unsigned
# integers
# -Wno-deprecated: some of the gutil code includes old things like ext/hash_set, ignore that
# - pthread: enable multithreaded malloc
# - -D__STDC_FORMAT_MACROS: for PRI* print format macros
# -fno-strict-aliasing
# Assume programs do not follow strict aliasing rules.
# GCC cannot always verify whether strict aliasing rules are indeed followed due to
# fundamental limitations in escape analysis, which can result in subtle bad code generation.
# This has a small perf hit but worth it to avoid hard to debug crashes.
set(CXX_COMMON_FLAGS "-std=c++11 -fno-strict-aliasing -msse4.2 -Wall -Wno-sign-compare -Wno-deprecated -pthread -D__STDC_FORMAT_MACROS")
# compiler flags for different build types (run 'cmake -DCMAKE_BUILD_TYPE=<type> .')
# For all builds:
# For CMAKE_BUILD_TYPE=Debug
# -ggdb: Enable gdb debugging
# For CMAKE_BUILD_TYPE=FastDebug
# Same as DEBUG, except with some optimizations on.
# For CMAKE_BUILD_TYPE=Release
# -O3: Enable all compiler optimizations
# -g: Enable symbols for profiler tools (TODO: remove for shipping)
# -DNDEBUG: Turn off dchecks/asserts/debug only code.
# -fno-omit-frame-pointer
# use frame pointers to allow simple stack frame walking for backtraces.
# This has a small perf hit but worth it for the ability to profile in production
# For profile guided optimization (PGO) builds, in addition to the flags for release builds:
# 1. Build first with CMAKE_BUILD_TYPE_PROFILE_GEN:
# -fprofile-generate: Indicates compiler should insert profile guided optimization events
# 2. Run the benchmarks (generates *.gcda profiling data).
# 3. Build again with CMAKE_BUILD_TYPE_PROFILE_BUILD
# -fprofile-use: Compiler will use the profile outputs for optimizations
set(CXX_FLAGS_DEBUG "-ggdb")
set(CXX_FLAGS_FASTDEBUG "-ggdb -O1 -fno-omit-frame-pointer")
set(CXX_FLAGS_RELEASE "-O3 -g -DNDEBUG -fno-omit-frame-pointer")
set(CXX_FLAGS_PROFILE_GEN "${CXX_FLAGS_RELEASE} -fprofile-generate")
set(CXX_FLAGS_PROFILE_BUILD "${CXX_FLAGS_RELEASE} -fprofile-use")
# if no build build type is specified, default to debug builds
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif(NOT CMAKE_BUILD_TYPE)
string (TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE)
# Alias RELEASE as RELWITHDEBINFO and MINSIZEREL. These are common CMake
# release type names and this provides compatibility with the CLion IDE.
if ("${CMAKE_BUILD_TYPE}" STREQUAL "RELWITHDEBINFO" OR "${CMAKE_BUILD_TYPE}" STREQUAL "MINSIZEREL")
set(CMAKE_BUILD_TYPE RELEASE)
endif ()
# Set compile flags based on the build type.
message("Configured for ${CMAKE_BUILD_TYPE} build (set with cmake -DCMAKE_BUILD_TYPE={release,debug,...})")
if ("${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG")
set(CMAKE_CXX_FLAGS ${CXX_FLAGS_DEBUG})
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "FASTDEBUG")
set(CMAKE_CXX_FLAGS ${CXX_FLAGS_FASTDEBUG})
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "RELEASE")
set(CMAKE_CXX_FLAGS ${CXX_FLAGS_RELEASE})
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "PROFILE_GEN")
set(CMAKE_CXX_FLAGS ${CXX_FLAGS_PROFILE_GEN})
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "PROFILE_BUILD")
set(CMAKE_CXX_FLAGS ${CXX_FLAGS_PROFILE_BUILD})
else()
message(FATAL_ERROR "Unknown build type: ${CMAKE_BUILD_TYPE}")
endif ()
# Add common flags
set(CMAKE_CXX_FLAGS "${CXX_COMMON_FLAGS} ${CMAKE_CXX_FLAGS}")
# Determine compiler version
include(CompilerInfo)
if ("${COMPILER_FAMILY}" STREQUAL "clang")
# Using Clang with ccache causes a bunch of spurious warnings that are
# purportedly fixed in the next version of ccache. See the following for details:
#
# http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html
# http://petereisentraut.blogspot.com/2011/09/ccache-and-clang-part-2.html
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -Wno-unused-function -Wno-error")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
# Sanity check linking option.
if (NOT PANDAS_LINK)
set(PANDAS_LINK "a")
elseif(NOT ("auto" MATCHES "^${PANDAS_LINK}" OR
"dynamic" MATCHES "^${PANDAS_LINK}" OR
"static" MATCHES "^${PANDAS_LINK}"))
message(FATAL_ERROR "Unknown value for PANDAS_LINK, must be auto|dynamic|static")
else()
# Remove all but the first letter.
string(SUBSTRING "${PANDAS_LINK}" 0 1 PANDAS_LINK)
endif()
# For any C code, use the same flags.
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS}")
# Code coverage
if ("${PANDAS_GENERATE_COVERAGE}")
if("${CMAKE_CXX_COMPILER}" MATCHES ".*clang.*")
# There appears to be some bugs in clang 3.3 which cause code coverage
# to have link errors, not locating the llvm_gcda_* symbols.
# This should be fixed in llvm 3.4 with http://llvm.org/viewvc/llvm-project?view=revision&revision=184666
message(SEND_ERROR "Cannot currently generate coverage with clang")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -DCOVERAGE_BUILD")
# For coverage to work properly, we need to use static linkage. Otherwise,
# __gcov_flush() doesn't properly flush coverage from every module.
# See http://stackoverflow.com/questions/28164543/using-gcov-flush-within-a-library-doesnt-force-the-other-modules-to-yield-gc
if("${PANDAS_LINK}" STREQUAL "a")
message("Using static linking for coverage build")
set(PANDAS_LINK "s")
elseif("${PANDAS_LINK}" STREQUAL "d")
message(SEND_ERROR "Cannot use coverage with static linking")
endif()
endif()
# If we still don't know what kind of linking to perform, choose based on
# build type (developers like fast builds).
if ("${PANDAS_LINK}" STREQUAL "a")
if ("${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG" OR
"${CMAKE_BUILD_TYPE}" STREQUAL "FASTDEBUG")
message("Using dynamic linking for ${CMAKE_BUILD_TYPE} builds")
set(PANDAS_LINK "d")
else()
message("Using static linking for ${CMAKE_BUILD_TYPE} builds")
set(PANDAS_LINK "s")
endif()
endif()
# Are we using the gold linker? It doesn't work with dynamic linking as
# weak symbols aren't properly overridden, causing tcmalloc to be omitted.
# Let's flag this as an error in RELEASE builds (we shouldn't release a
# product like this).
#
# See https://sourceware.org/bugzilla/show_bug.cgi?id=16979 for details.
#
# The gold linker is only for ELF binaries, which OSX doesn't use. We can
# just skip.
if (NOT APPLE)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -Wl,--version OUTPUT_VARIABLE LINKER_OUTPUT)
endif ()
if (LINKER_OUTPUT MATCHES "gold")
if ("${PANDAS_LINK}" STREQUAL "d" AND
"${CMAKE_BUILD_TYPE}" STREQUAL "RELEASE")
message(SEND_ERROR "Cannot use gold with dynamic linking in a RELEASE build "
"as it would cause tcmalloc symbols to get dropped")
else()
message("Using gold linker")
endif()
set(PANDAS_USING_GOLD 1)
else()
message("Using ld linker")
endif()
# Having set PANDAS_LINK due to build type and/or sanitizer, it's now safe to
# act on its value.
if ("${PANDAS_LINK}" STREQUAL "d")
set(BUILD_SHARED_LIBS ON)
# Position independent code is only necessary when producing shared objects.
add_definitions(-fPIC)
endif()
# set compile output directory
string (TOLOWER ${CMAKE_BUILD_TYPE} BUILD_SUBDIR_NAME)
# If build in-source, create the latest symlink. If build out-of-source, which is
# preferred, simply output the binaries in the build folder
if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
set(BUILD_OUTPUT_ROOT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/build/${BUILD_SUBDIR_NAME}/")
# Link build/latest to the current build directory, to avoid developers
# accidentally running the latest debug build when in fact they're building
# release builds.
FILE(MAKE_DIRECTORY ${BUILD_OUTPUT_ROOT_DIRECTORY})
if (NOT APPLE)
set(MORE_ARGS "-T")
endif()
EXECUTE_PROCESS(COMMAND ln ${MORE_ARGS} -sf ${BUILD_OUTPUT_ROOT_DIRECTORY}
${CMAKE_CURRENT_BINARY_DIR}/build/latest)
else()
# set(BUILD_OUTPUT_ROOT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${BUILD_SUBDIR_NAME}/")
set(BUILD_OUTPUT_ROOT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
endif()
# where to put generated archives (.a files)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${BUILD_OUTPUT_ROOT_DIRECTORY}")
set(ARCHIVE_OUTPUT_DIRECTORY "${BUILD_OUTPUT_ROOT_DIRECTORY}")
# where to put generated libraries (.so files)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${BUILD_OUTPUT_ROOT_DIRECTORY}")
set(LIBRARY_OUTPUT_DIRECTORY "${BUILD_OUTPUT_ROOT_DIRECTORY}")
# where to put generated binaries
set(EXECUTABLE_OUTPUT_PATH "${BUILD_OUTPUT_ROOT_DIRECTORY}")
############################################################
# Visibility
############################################################
# For generate_export_header() and add_compiler_export_flags().
include(GenerateExportHeader)
# add_library() wrapper that adds a second variant of the library for use in the
# exported Kudu C++ client. This variant is suffixed with "_exported" and is
# compiled with special visibility flags to hide all symbols except those that
# are part of the public ABI.
#
# There are two different kinds of exported libraries: internal and leaf.
# Internal libraries are static archives while leaf libraries are shared
# objects built from internal libraries. In practice there is only one leaf
# library: the Kudu C++ client itself.
#
# Arguments:
#
# LIB_NAME is the name of the library. It must come first. Required.
#
# SRCS is the list of source files to compile into the library. Required.
#
# DEPS is the list of targets that both library variants depend on. Required.
#
# NONLINK_DEPS is the list of (non-linked) targets that both library variants
# depend on. Optional.
#
# COMPILE_FLAGS is a string containing any additional compilation flags that
# should be added to both library variants. Optional.
#
# EXPORTED_SHARED is a toggle that, if set, indicates that the exported variant
# is a "leaf" library. Otherwise it is an "internal" library. Optional.
#
# EXPORTED_OUTPUT_NAME is a string describing a different file name for the
# exported library variant. If not set, defaults to LIB_NAME. Optional.
#
# EXPORTED_OUTPUT_DIRECTORY is a string describing a different directory where
# the exported library variant should be written. If not set, defaults to the
# directory where this function was called. Optional.
#
# EXPORTED_DEPS is a list of targets that the exported library variant depends
# on. If not set, defaults to DEPS. Optional.
function(ADD_EXPORTABLE_LIBRARY LIB_NAME)
# Parse the arguments.
set(options EXPORTED_SHARED)
set(one_value_args COMPILE_FLAGS EXPORTED_OUTPUT_NAME EXPORTED_OUTPUT_DIRECTORY)
set(multi_value_args SRCS DEPS EXPORTED_DEPS NONLINK_DEPS)
cmake_parse_arguments(ARG "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN})
if(ARG_UNPARSED_ARGUMENTS)
message(SEND_ERROR "Error: unrecognized arguments: ${ARG_UNPARSED_ARGUMENTS}")
endif()
# First add the regular version of the library. It uses
# whatever linkage was defined globally.
add_library(${LIB_NAME} ${ARG_SRCS})
if(ARG_COMPILE_FLAGS)
set_target_properties(${LIB_NAME}
PROPERTIES COMPILE_FLAGS ${ARG_COMPILE_FLAGS})
endif()
target_link_libraries(${LIB_NAME} ${ARG_DEPS})
if(ARG_NONLINK_DEPS)
add_dependencies(${LIB_NAME} ${ARG_NONLINK_DEPS})
endif()
# Now start setting up the exported variant.
set(EXPORTED_LIB_NAME ${LIB_NAME}_exported)
if(ARG_EXPORTED_SHARED)
# Leaf library.
set(EXPORTED_LINKAGE "SHARED")
set(EXPORTED_LINK_PRIVATE "LINK_PRIVATE")
else()
# Internal library.
set(EXPORTED_LINKAGE "STATIC")
set(EXPORTED_LINK_PRIVATE)
endif()
add_library(${EXPORTED_LIB_NAME} ${EXPORTED_LINKAGE} ${ARG_SRCS})
# Compile with visibility flags:
# - default for classes annotated with PANDAS_EXPORT.
# - hidden for classes annotated with PANDAS_NO_EXPORT.
# - hidden for everything else.
add_compiler_export_flags(EXPORTED_FLAGS)
# Exported variants are either static archives that will be linked to a shared
# object, or shared objects. Either way, -fPIC is needed.
if("${PANDAS_LINK}" STREQUAL "s")
set(EXPORTED_FLAGS "${EXPORTED_FLAGS} -fPIC")
endif()
# We need to remove some definitions previously added at directory scope.
# There doesn't appear to be a good way to do this in cmake, so we do it via
# the compiler with -U (e.g. "-UFOO" means "undefine the FOO definition").
# Adding insult to injury, the COMPILE_DEFINITIONS property adds a -D prefix
# to anything passed into it, so we're forced to handle the removal via
# COMPILE_FLAGS, which, lucky for us, is emitted on the command line after
# COMPILE_DEFINITIONS.
# Exported variants need PANDAS_EXPORT definitions to take effect.
set(EXPORTED_FLAGS "${EXPORTED_FLAGS} -UPANDAS_STATIC_DEFINE")
# Exported variants may not use tcmalloc.
set(EXPORTED_FLAGS "${EXPORTED_FLAGS} -UTCMALLOC_ENABLED")
set_target_properties(${EXPORTED_LIB_NAME}
PROPERTIES COMPILE_FLAGS "${ARG_COMPILE_FLAGS} ${EXPORTED_FLAGS}")
# Handle EXPORTED_OUTPUT_NAME and EXPORTED_OUTPUT_DIRECTORY.
if(ARG_EXPORTED_OUTPUT_NAME)
set_target_properties(${EXPORTED_LIB_NAME}
PROPERTIES LIBRARY_OUTPUT_NAME ${ARG_EXPORTED_OUTPUT_NAME})
endif()
if(ARG_EXPORTED_OUTPUT_DIRECTORY)
set_target_properties(${EXPORTED_LIB_NAME}
PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${ARG_EXPORTED_OUTPUT_DIRECTORY})
endif()
# Set up exported variant dependent targets.
#
# Every linked dependency is suffixed with "_exported". This is fine; the
# exported target graph is expected to be complete, and ADD_THIRDPARTY_LIB
# will provide an "exported variant" for each third party target.
if(ARG_EXPORTED_DEPS)
set(EXPORTED_DEPS ${ARG_EXPORTED_DEPS})
else()
set(EXPORTED_DEPS ${ARG_DEPS})
endif()
foreach(DEP ${EXPORTED_DEPS})
list(APPEND EXPORTED_SUFFIXED_DEPS "${DEP}_exported")
endforeach()
target_link_libraries(${EXPORTED_LIB_NAME} ${EXPORTED_LINK_PRIVATE} ${EXPORTED_SUFFIXED_DEPS})
if(ARG_NONLINK_DEPS)
add_dependencies(${EXPORTED_LIB_NAME} ${ARG_NONLINK_DEPS})
endif()
endfunction()
############################################################
# Testing
############################################################
# Add a new test case, with or without an executable that should be built.
#
# REL_TEST_NAME is the name of the test. It may be a single component
# (e.g. monotime-test) or contain additional components (e.g.
# net/net_util-test). Either way, the last component must be a globally
# unique name.
#
# Arguments after the test name will be passed to set_tests_properties().
function(ADD_PANDAS_TEST REL_TEST_NAME)
if(NO_TESTS)
return()
endif()
get_filename_component(TEST_NAME ${REL_TEST_NAME} NAME_WE)
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${REL_TEST_NAME}.cc)
# This test has a corresponding .cc file, set it up as an executable.
set(TEST_PATH "${EXECUTABLE_OUTPUT_PATH}/${TEST_NAME}")
add_executable(${TEST_NAME} "${REL_TEST_NAME}.cc")
target_link_libraries(${TEST_NAME} ${PANDAS_TEST_LINK_LIBS})
else()
# No executable, just invoke the test (probably a script) directly.
set(TEST_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${REL_TEST_NAME})
endif()
add_test(${TEST_NAME}
${BUILD_SUPPORT_DIR}/run-test.sh ${TEST_PATH})
if(ARGN)
set_tests_properties(${TEST_NAME} PROPERTIES ${ARGN})
endif()
endfunction()
# A wrapper for add_dependencies() that is compatible with NO_TESTS.
function(ADD_PANDAS_TEST_DEPENDENCIES REL_TEST_NAME)
if(NO_TESTS)
return()
endif()
get_filename_component(TEST_NAME ${REL_TEST_NAME} NAME_WE)
add_dependencies(${TEST_NAME} ${ARGN})
endfunction()
enable_testing()
############################################################
# Dependencies
############################################################
function(ADD_THIRDPARTY_LIB LIB_NAME)
set(options)
set(one_value_args SHARED_LIB STATIC_LIB)
set(multi_value_args DEPS)
cmake_parse_arguments(ARG "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN})
if(ARG_UNPARSED_ARGUMENTS)
message(SEND_ERROR "Error: unrecognized arguments: ${ARG_UNPARSED_ARGUMENTS}")
endif()
if(("${PANDAS_LINK}" STREQUAL "s" AND ARG_STATIC_LIB) OR (NOT ARG_SHARED_LIB))
if(NOT ARG_STATIC_LIB)
message(FATAL_ERROR "No static or shared library provided for ${LIB_NAME}")
endif()
add_library(${LIB_NAME} STATIC IMPORTED)
set_target_properties(${LIB_NAME}
PROPERTIES IMPORTED_LOCATION "${ARG_STATIC_LIB}")
message("Added static library dependency ${LIB_NAME}: ${ARG_STATIC_LIB}")
else()
add_library(${LIB_NAME} SHARED IMPORTED)
set_target_properties(${LIB_NAME}
PROPERTIES IMPORTED_LOCATION "${ARG_SHARED_LIB}")
message("Added shared library dependency ${LIB_NAME}: ${ARG_SHARED_LIB}")
endif()
if(ARG_DEPS)
set_target_properties(${LIB_NAME}
PROPERTIES IMPORTED_LINK_INTERFACE_LIBRARIES "${ARG_DEPS}")
endif()
# Set up an "exported variant" for this thirdparty library (see "Visibility"
# above). It's the same as the real target, just with an "_exported" suffix.
# We prefer the static archive if it exists (as it's akin to an "internal"
# library), but we'll settle for the shared object if we must.
#
# A shared object exported variant will force any "leaf" library that
# transitively depends on it to also depend on it at runtime; this is
# desirable for some libraries (e.g. cyrus_sasl).
set(LIB_NAME_EXPORTED ${LIB_NAME}_exported)
if(ARG_STATIC_LIB)
add_library(${LIB_NAME_EXPORTED} STATIC IMPORTED)
set_target_properties(${LIB_NAME_EXPORTED}
PROPERTIES IMPORTED_LOCATION "${ARG_STATIC_LIB}")
else()
add_library(${LIB_NAME_EXPORTED} SHARED IMPORTED)
set_target_properties(${LIB_NAME_EXPORTED}
PROPERTIES IMPORTED_LOCATION "${ARG_SHARED_LIB}")
endif()
if(ARG_DEPS)
set_target_properties(${LIB_NAME_EXPORTED}
PROPERTIES IMPORTED_LINK_INTERFACE_LIBRARIES "${ARG_DEPS}")
endif()
endfunction()
## Python and libraries
find_package(PythonInterp REQUIRED)
find_package(PythonLibsNew REQUIRED)
find_package(NumPy REQUIRED)
include(UseCython)
message(STATUS "Found Python dynamic library: ${PYTHON_LIBRARIES}")
include_directories(SYSTEM
${NUMPY_INCLUDE_DIRS}
${PYTHON_INCLUDE_DIRS}
pandas/
thirdparty/
src)
############################################################
# "make ctags" target
############################################################
if (UNIX)
add_custom_target(ctags ctags -R --languages=c++,c)
endif (UNIX)
############################################################
# "make etags" target
############################################################
if (UNIX)
add_custom_target(tags etags --members --declarations
`find ${CMAKE_CURRENT_SOURCE_DIR}/src
-name \\*.cc -or -name \\*.hh -or -name \\*.cpp -or -name \\*.h -or -name \\*.c -or
-name \\*.f`)
add_custom_target(etags DEPENDS tags)
endif (UNIX)
############################################################
# "make cscope" target
############################################################
if (UNIX)
add_custom_target(cscope find ${CMAKE_CURRENT_SOURCE_DIR}
( -name \\*.cc -or -name \\*.hh -or -name \\*.cpp -or
-name \\*.h -or -name \\*.c -or -name \\*.f )
-exec echo \"{}\" \; > cscope.files && cscope -q -b VERBATIM)
endif (UNIX)
############################################################
# "make lint" target
############################################################
if (UNIX)
# Full lint
add_custom_target(lint ${BUILD_SUPPORT_DIR}/cpplint.py
--verbose=4
--filter=-whitespace/comments,-readability/todo,-build/header_guard,-build/include_order
`find ${CMAKE_CURRENT_SOURCE_DIR}/src -name \\*.cc -or -name \\*.h`)
endif (UNIX)
#############################################################
# Test linking
set(PANDAS_MIN_TEST_LIBS
pandas_test_main
pandas)
# Unit tests need to link to libpython. NumPy can be linked by importing the
# numpy module
if(NOT APPLE)
ADD_THIRDPARTY_LIB(python
SHARED_LIB "${PYTHON_LIBRARIES}")
list(APPEND PANDAS_MIN_TEST_LIBS python)
endif()
set(PANDAS_TEST_LINK_LIBS ${PANDAS_MIN_TEST_LIBS})
############################################################
# Subdirectories
############################################################
add_subdirectory(src/pandas)
add_subdirectory(src/pandas/util)
set(PANDAS_SRCS
src/pandas/array.cc
src/pandas/dispatch.cc
src/pandas/init.cc
src/pandas/numpy_interop.cc
src/pandas/pytypes.cc
src/pandas/types/boolean.cc
src/pandas/types/category.cc
src/pandas/types/integer.cc
src/pandas/types/floating.cc
)
add_library(pandas SHARED
${PANDAS_SRCS})
target_link_libraries(pandas
pandas_util)
set_target_properties(pandas PROPERTIES LINKER_LANGUAGE CXX)
if(APPLE)
set_target_properties(pandas PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
endif()
############################################################
# Setup and build Cython modules
############################################################
foreach(pyx_api_file
pandas/native.pyx
pandas/internals/config.pyx)
set_source_files_properties(${pyx_api_file} PROPERTIES CYTHON_API 1)
endforeach(pyx_api_file)
set(USE_RELATIVE_RPATH ON)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
foreach(module native internals.config)
string(REPLACE "." ";" directories ${module})
list(GET directories -1 module_name)
list(REMOVE_AT directories -1)
string(REPLACE "." "/" module_root "${module}")
set(module_SRC pandas/${module_root}.pyx)
set_source_files_properties(${module_SRC} PROPERTIES CYTHON_IS_CXX 1)
cython_add_module(${module_name}
${module_name}_pyx
${module_name}_output
${module_SRC})
if (directories)
string(REPLACE ";" "/" module_output_directory ${directories})
set_target_properties(${module_name} PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${module_output_directory})
endif()
if(APPLE)
set(module_install_rpath "@loader_path")
else()
set(module_install_rpath "$ORIGIN")
endif()
list(LENGTH directories i)
while(${i} GREATER 0)
set(module_install_rpath "${module_install_rpath}/..")
math(EXPR i "${i} - 1" )
endwhile(${i} GREATER 0)
# for inplace development for now
set(module_install_rpath "${CMAKE_SOURCE_DIR}/pandas/")
set_target_properties(${module_name} PROPERTIES
INSTALL_RPATH ${module_install_rpath})
target_link_libraries(${module_name} pandas)
endforeach(module)
# add_dependencies(pandas native_pyx)