forked from RobotLocomotion/cmake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpods.cmake
700 lines (619 loc) · 25.9 KB
/
pods.cmake
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
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
# Macros to simplify compliance with the pods build policies.
#
# To enable the macros, add the following lines to CMakeLists.txt:
# set(POD_NAME <pod-name>)
# include(cmake/pods.cmake)
#
# If POD_NAME is not set, then the CMake source directory is used as POD_NAME
#
# Next, any of the following macros can be used. See the individual macro
# definitions in this file for individual documentation.
#
# General
# pods_find_pkg_config(...)
# pods_install_pkg_config_file(...)
# pods_install_bash_setup(...)
# get_relative_path(from to)
#
# C/C++
# pods_install_headers(...)
# pods_install_libraries(...)
# pods_install_executables(...)
#
# pods_use_pkg_config_packages(...)
# pods_use_pkg_config_includes(...)
#
# Python
# pods_install_python_packages(...)
# pods_install_python_script(...)
#
# Java
# pods_install_jars(...)
# pods_use_pkg_config_classpath(...)
#
# ----
# File: pods.cmake
# Distributed with pods version: 12.11.14
# On windows, the compilers and the shell commands (potentially) use different syntax for their path strings.
# These macros try to handle that case as cleanly as possible, and do nothing on non-windows
macro(pkg_config_path var)
if (WIN32)
string(REGEX REPLACE "\\/" "\\\\" ${var} ${${var}})
endif()
endmacro()
# pods_install_headers(<header1.h> ... DESTINATION <subdir_name>)
#
# Install a (list) of header files.
#
# Header files will all be installed to include/<subdir_name>
#
# example:
# add_library(perception detector.h sensor.h)
# pods_install_headers(detector.h sensor.h DESTINATION perception)
#
function(pods_install_headers)
list(GET ARGV -2 checkword)
if(NOT checkword STREQUAL DESTINATION)
message(FATAL_ERROR "pods_install_headers missing DESTINATION parameter")
endif()
list(GET ARGV -1 dest_dir)
list(REMOVE_AT ARGV -1)
list(REMOVE_AT ARGV -1)
#copy the headers to the INCLUDE_OUTPUT_PATH (${CMAKE_BINARY_DIR}/include)
foreach(header ${ARGV})
get_filename_component(_header_name ${header} NAME)
configure_file(${header} ${INCLUDE_OUTPUT_PATH}/${dest_dir}/${_header_name} COPYONLY)
endforeach(header)
#mark them to be installed
install(FILES ${ARGV} DESTINATION include/${dest_dir})
endfunction(pods_install_headers)
# pods_install_executables(<executable1> ...)
#
# Install a (list) of executables to bin/
function(pods_install_executables)
install(TARGETS ${ARGV} RUNTIME DESTINATION bin)
endfunction(pods_install_executables)
# pods_install_libraries(<library1> ...)
#
# Install a (list) of libraries to lib/
function(pods_install_libraries)
install(TARGETS ${ARGV} RUNTIME DESTINATION lib LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)
endfunction(pods_install_libraries)
function(pods_install_jars)
foreach(jarfile ${ARGV})
install_jar(${jarfile} share/java)
endforeach()
endfunction(pods_install_jars)
# pods_install_pkg_config_file(<package-name>
# [VERSION <version>]
# [DESCRIPTION <description>]
# [CFLAGS <cflag> ...]
# [LIBS <lflag> ...]
# [CLASSPATH <target-jar1> <target-jar2> ...]
# [REQUIRES <required-package-name> ...])
#
# Create and install a pkg-config .pc file.
#
# example:
# add_library(mylib mylib.c)
# pods_install_pkg_config_file(mylib LIBS -lmylib REQUIRES glib-2.0)
function(pods_install_pkg_config_file)
list(GET ARGV 0 pc_name)
# TODO error check
set(pc_version 0.0.1)
set(pc_description ${pc_name})
set(pc_requires "")
set(pc_libs "")
set(pc_cflags "")
set(pc_classpath "")
set(pc_fname "${PKG_CONFIG_OUTPUT_PATH}/${pc_name}.pc")
set(modewords LIBS CFLAGS CLASSPATH REQUIRES VERSION DESCRIPTION)
set(curmode "")
# parse function arguments and populate pkg-config parameters
list(REMOVE_AT ARGV 0)
foreach(word ${ARGV})
list(FIND modewords ${word} mode_index)
if(${mode_index} GREATER -1)
set(curmode ${word})
elseif(curmode STREQUAL LIBS)
set(pc_libs "${pc_libs} ${word}")
elseif(curmode STREQUAL CFLAGS)
set(pc_cflags "${pc_cflags} ${word}")
elseif(curmode STREQUAL CLASSPATH)
if ("${pc_classpath}" STREQUAL "")
set(pc_classpath "\${prefix}/share/java/${word}.jar")
else()
set(pc_classpath "${pc_classpath}:\${prefix}/share/java/${word}.jar")
endif()
elseif(curmode STREQUAL REQUIRES)
set(pc_requires "${pc_requires} ${word}")
elseif(curmode STREQUAL VERSION)
set(pc_version ${word})
set(curmode "")
elseif(curmode STREQUAL DESCRIPTION)
set(pc_description "${word}")
set(curmode "")
else(${mode_index} GREATER -1)
message("WARNING incorrect use of pods_add_pkg_config (${word})")
break()
endif(${mode_index} GREATER -1)
endforeach(word)
set(prefix ${CMAKE_INSTALL_PREFIX})
# write the .pc file out
file(WRITE ${pc_fname}
"prefix=${prefix}\n"
"exec_prefix=\${prefix}\n"
"libdir=\${exec_prefix}/lib\n"
"includedir=\${prefix}/include\n"
"\n"
"Name: ${pc_name}\n"
"Description: ${pc_description}\n"
"Requires: ${pc_requires}\n"
"Version: ${pc_version}\n"
"Libs: -L\${libdir} ${pc_libs}\n"
"Cflags: -I\${includedir} ${pc_cflags}\n"
"classpath=${pc_classpath}\n"
)
# mark the .pc file for installation to the lib/pkgconfig directory
install(FILES ${pc_fname} DESTINATION lib/pkgconfig)
endfunction(pods_install_pkg_config_file)
# pods_install_bash_setup(<package-name> <line1> <line2> ...)
#
# Create and install the lines into config/${package}_setup.sh
#
# example:
# pods_install_bash_setup(mypod "export LD_LIBRARY_PATH=${CMAKE_INSTALL_PREFIX}/lib")
function(pods_install_bash_setup package)
list(REMOVE_AT ARGV 0)
set(filename ${PROJECT_BINARY_DIR}/config/${package}_setup.sh)
# todo: add a \n at the end of every element of ARGV?
file(WRITE ${filename} ${ARGV} )
install(FILES ${filename} DESTINATION config)
# execute_process(COMMAND chmod +x ${CMAKE_INSTALL_PREFIX}/config/${package}_setup.sh)
if (APPLE)
set(LD_LIBRARY_PATH DYLD_LIBRARY_PATH)
else()
set(LD_LIBRARY_PATH LD_LIBRARY_PATH)
endif()
set(prefix ${CMAKE_INSTALL_PREFIX})
set(filename ${PROJECT_BINARY_DIR}/config/pods_setup_all.sh)
file(WRITE ${filename}
"# THIS FILE IS AUTOMATICALLY GENERATED. ANY EDITS YOU MAKE WILL LIKELY BE OVERWRITTEN.\n"
"\n"
"export PATH=$PATH:${prefix}/bin\n"
"export ${LD_LIBRARY_PATH}=\$${LD_LIBRARY_PATH}:${prefix}/lib\n"
"for i in ${prefix}/config/*_setup.sh; do\n"
" echo sourcing $i;\n"
" source $i;\n"
"done\n"
)
install(FILES ${filename} DESTINATION config)
# execute_process(COMMAND chmod +x ${CMAKE_INSTALL_PREFIX}/config/pods_setup_all.sh)
endfunction()
# pods_install_python_script(<script_name> <python_module_or_file>)
#
# Create and install a script that invokes the python interpreter with a
# specified python module or script.
#
# A launcher script will be installed to bin/<script_name>. The script simply
# adds <install-prefix>/lib/pythonX.Y/dist-packages
# and <install-prefix>/lib/pythonX.Y/site-packages
# to the PYTHONPATH, and then
# invokes `python -m <python_module>` or `python python_file`
# depending on whether the function was passed a module name or script file.
#
# example:
# pods_install_python_script(run-py-module py_pkg.py_module)
# pods_install_python_script(run-py-script py_script.py)
function(pods_install_python_script script_name python_module_or_file)
find_package(PythonInterp REQUIRED)
# which python version?
execute_process(COMMAND
${PYTHON_EXECUTABLE} -c "import sys; sys.stdout.write(sys.version[:3])"
OUTPUT_VARIABLE pyversion)
# where do we install .py files to?
set(python_install_dir
${CMAKE_INSTALL_PREFIX}/lib/python${pyversion}/dist-packages)
set(python_old_install_dir #todo: when do we get rid of this?
${CMAKE_INSTALL_PREFIX}/lib/python${pyversion}/site-packages)
if (python_module_or_file MATCHES ".+\\.py") #ends with a .py
get_filename_component(py_file ${python_module_or_file} ABSOLUTE)
if (NOT EXISTS ${py_file})
message(FATAL_ERROR "${python_module_or_file} is not an absolute or relative path to a python script")
endif()
#get the directory where we'll install the script ${sanitized_POD_NAME}_scripts
string(REGEX REPLACE "[^a-zA-Z0-9]" "_" __sanitized_pod_name "${POD_NAME}")
set(pods_scripts_dir "${python_install_dir}/${__sanitized_pod_name}_scripts")
# install the python script file
install(FILES ${py_file} DESTINATION "${pods_scripts_dir}")
get_filename_component(py_script_name ${py_file} NAME)
# write the bash script file
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${script_name}
"#!/bin/sh\n"
"export PYTHONPATH=${python_install_dir}:${python_old_install_dir}:\${PYTHONPATH}\n"
"exec ${PYTHON_EXECUTABLE} ${pods_scripts_dir}/${py_script_name} $*\n")
else()
get_filename_component(py_module ${python_module_or_file} NAME) #todo: check whether module exists?
# write the bash script file
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${script_name}
"#!/bin/sh\n"
"export PYTHONPATH=${python_install_dir}:${python_old_install_dir}:\${PYTHONPATH}\n"
"exec ${PYTHON_EXECUTABLE} -m ${py_module} $*\n")
endif()
# install it...
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${script_name} DESTINATION bin)
endfunction()
# _pods_install_python_package(<py_src_dir> <py_module_name>)
#
# Internal helper function
# Install python module in <py_src_dir> to lib/pythonX.Y/dist-packages/<py_module_name>,
# where X.Y refers to the current python version (e.g., 2.6)
#
function(_pods_install_python_package py_src_dir py_module_name)
find_package(PythonInterp REQUIRED)
# which python version?
execute_process(COMMAND
${PYTHON_EXECUTABLE} -c "import sys; sys.stdout.write(sys.version[:3])"
OUTPUT_VARIABLE pyversion)
# where do we install .py files to?
set(python_install_dir
${CMAKE_INSTALL_PREFIX}/lib/python${pyversion}/dist-packages)
if(EXISTS "${py_src_dir}/__init__.py")
#install the single module
file(GLOB_RECURSE module_files ${py_src_dir}/*)
foreach(file ${module_files})
if(NOT file MATCHES ".*\\.svn.*|.*\\.pyc|.*[~#]")
file(RELATIVE_PATH __tmp_path ${py_src_dir} ${file})
get_filename_component(__tmp_dir ${__tmp_path} PATH)
install(FILES ${file}
DESTINATION "${python_install_dir}/${py_module_name}/${__tmp_dir}")
endif()
endforeach()
else()
message(FATAL_ERROR "${py_src_dir} is not a python package!\n")
endif()
endfunction()
# pods_install_python_packages(<src_dir1> ...)
#
# Install python packages to lib/pythonX.Y/dist-packages, where X.Y refers to
# the current python version (e.g., 2.6)
#
# For each <src_dir> pass in, it will do the following:
# If <src_dir> is a python package (it has a __init__.py file) it will be installed
# along with any .py files in subdirectories
#
# Otherwise the script searches for and installs any python packages in <src_dir>
function(pods_install_python_packages py_src_dir)
get_filename_component(py_src_abs_dir ${py_src_dir} ABSOLUTE)
if(ARGC GREATER 1)
#install each module seperately
foreach(py_module ${ARGV})
pods_install_python_packages(${py_module})
endforeach()
elseif(EXISTS "${py_src_abs_dir}/__init__.py")
#install the single module by name
get_filename_component(py_module_name ${py_src_abs_dir} NAME)
_pods_install_python_package(${py_src_abs_dir} ${py_module_name})
else()
# install any packages within the passed in py_src_dir
set(_installed_a_package FALSE)
file(GLOB sub-dirs RELATIVE ${py_src_abs_dir} ${py_src_abs_dir}/*)
foreach(sub-dir ${sub-dirs})
if(EXISTS "${py_src_abs_dir}/${sub-dir}/__init__.py")
_pods_install_python_package(${py_src_abs_dir}/${sub-dir} ${sub-dir})
set(_installed_a_package TRUE)
endif()
endforeach()
if (NOT _installed_a_package)
message(FATAL_ERROR "${py_src_dir} does not contain any python packages!\n")
endif()
endif()
endfunction()
# pods_find_pkg_config(<package-name> <minimum_version>)
#
# Invokes `pkg-config --exists <package-name>` and, per the cmake standard,
# sets the variable <package-name>_FOUND if it succeeds
#
# Takes an optional minimum version number as the second argument.
#
# example usage:
# pods_find_pkg_config(eigen3)
# if (eigen3_FOUND)
# ... do something ...
# endif()
function(pods_find_pkg_config)
if (DEFINED ${ARGV0}_FOUND AND ${ARGV0}_FOUND AND ${ARGC} EQUAL 1) # not caching version info yet (but I could)
return()
endif()
if (NOT PKG_CONFIG_EXECUTABLE)
find_package(PkgConfig REQUIRED)
endif()
if(${ARGC} EQUAL 1)
execute_process(COMMAND
${PKG_CONFIG_EXECUTABLE} --exists ${ARGV}
RESULT_VARIABLE found)
elseif(${ARGC} EQUAL 2)
execute_process(COMMAND
${PKG_CONFIG_EXECUTABLE} --atleast-version=${ARGV1} ${ARGV0}
RESULT_VARIABLE found)
else()
message(FATAL_ERROR "pods_find_pkg_config take one or two arguments")
endif()
if (found EQUAL 0)
message(STATUS "Found ${ARGV0}")
set(${ARGV0}_FOUND 1 CACHE BOOL "" FORCE)
else()
message(STATUS "Could NOT find ${ARGV0} (version >= ${ARGV1}) using pods_find_pkg_config. PKG_CONFIG_PATH = $ENV{PKG_CONFIG_PATH}")
set(${ARGV0}_FOUND 0 CACHE BOOL "" FORCE)
endif()
endfunction()
# pods_use_pkg_config_packages(<target> <package-name> ...)
#
# Convenience macro to get compiler and linker flags from pkg-config and apply them
# to the specified target.
#
# Invokes `pkg-config --cflags-only-I <package-name> ...` and adds the result to the
# include directories.
#
# Additionally, invokes `pkg-config --libs <package-name> ...` and adds the result to
# the target's link flags (via target_link_libraries)
#
# example:
# add_executable(myprogram main.c)
# pods_use_pkg_config_packages(myprogram glib-2.0 opencv)
function(pods_use_pkg_config_packages target)
if(${ARGC} LESS 2)
message(WARNING "Useless invocation of pods_use_pkg_config_packages")
elseif (${ARGC} GREATER 2)
foreach (__package ${ARGN})
pods_use_pkg_config_packages(${target} ${__package})
endforeach()
else()
if (NOT PKG_CONFIG_EXECUTABLE)
find_package(PkgConfig REQUIRED)
endif()
string(STRIP ${ARGN} __package)
if (DEFINED ${__package}_CONFIG_IN_CACHE) # then i've already searched
set(PODS_PKG_FOUND "${${__package}_CONFIG_IN_CACHE}")
set(PODS_PKG_LIBRARIES "${${__package}_LIBRARIES}")
set(PODS_PKG_LIBRARY_DIRS "${${__package}_LIBRARY_DIRS}")
set(PODS_PKG_LDFLAGS "${${__package}_LDFLAGS}")
set(PODS_PKG_LDFLAGS_OTHER "${${__package}_LDFLAGS_OTHER}")
set(PODS_PKG_INCLUDE_DIRS "${${__package}_INCLUDE_DIRS}")
set(PODS_PKG_CFLAGS "${${__package}_CFLAGS}")
set(PODS_PKG_CFLAGS_OTHER "${${__package}_CFLAGS_OTHER}")
else()
set(PODS_PKG_FOUND "")
set(PODS_PKG_LIBRARIES "")
set(PODS_PKG_LIBRARY_DIRS "")
set(PODS_PKG_LDFLAGS "")
set(PODS_PKG_LDFLAGS_OTHER "")
set(PODS_PKG_INCLUDE_DIRS "")
set(PODS_PKG_CFLAGS "")
set(PODS_PKG_CFLAGS_OTHER "")
include(FindPkgConfig)
pkg_check_modules(PODS_PKG ${__package})
if (NOT PODS_PKG_FOUND)
message(FATAL_ERROR "ERROR: pods_use_pkg_config_packages FAILED. could not find packages ${ARGN}. PKG_CONFIG_PATH = $ENV{PKG_CONFIG_PATH}")
endif()
set("${__package}_CONFIG_IN_CACHE" "${PODS_PKG_FOUND}" CACHE STRING "")
set("${__package}_LIBRARIES" "${PODS_PKG_LIBRARIES}" CACHE STRING "")
set("${__package}_LIBRARY_DIRS" "${PODS_PKG_LIBRARY_DIRS}" CACHE STRING "")
set("${__package}_LDFLAGS" "${PODS_PKG_LDFLAGS}" CACHE STRING "")
set("${__package}_LDFLAGS_OTHER" "${PODS_PKG_LDFLAGS_OTHER}" CACHE STRING "")
set("${__package}_INCLUDE_DIRS" "${PODS_PKG_INCLUDE_DIRS}" CACHE STRING "")
set("${__package}_CFLAGS" "${PODS_PKG_CFLAGS}" CACHE STRING "")
set("${__package}_CFLAGS_OTHER" "${PODS_PKG_CFLAGS_OTHER}" CACHE STRING "")
endif()
# message(STATUS "using pkg ${__package}")
# message(STATUS " FOUND = ${PODS_PKG_FOUND}")
# message(STATUS " LIBRARIES = ${PODS_PKG_LIBRARIES}")
# message(STATUS " LIBRARY_DIRS = ${PODS_PKG_LIBRARY_DIRS}")
# message(STATUS " LDFLAGS = ${PODS_PKG_LDFLAGS}")
# message(STATUS " LDFLAGS_OTHER = ${PODS_PKG_LDFLAGS_OTHER}")
# message(STATUS " INCLUDE_DIRS = ${PODS_PKG_INCLUDE_DIRS}")
# message(STATUS " CFLAGS = ${PODS_PKG_CFLAGS}")
# message(STATUS " CFLAGS_OTHER = ${PODS_PKG_CFLAGS_OTHER}")
foreach (__inc_dir ${PODS_PKG_INCLUDE_DIRS})
string(STRIP ${__inc_dir} __inc_dir)
if (__inc_dir)
# message("include: ${__inc_dir}")
include_directories(SYSTEM ${__inc_dir})
endif()
endforeach()
foreach(__ld_dir ${PODS_PKG_LIBRARY_DIRS})
string(STRIP ${__ld_dir} __ld_dir)
if (__ld_dir)
if (WIN32) # only MSVC?
target_link_libraries(${target} "-LIBPATH:${__ld_dir}")
else()
target_link_libraries(${target} "-L${__ld_dir}")
endif()
endif()
endforeach()
# make the target depend on libraries that are cmake targets
foreach(__depend_target_name ${PODS_PKG_LIBRARIES})
# message(STATUS "${target} depends on ${__depend_target_name}")
if (TARGET ${__depend_target_name})
target_link_libraries(${target} ${__depend_target_name})
else()
target_link_libraries(${target} ${__depend_target_name})
# ask cmake to actually find the library (tried this to help when i had only dynamic versions of some libraries, and msvc was only looking for static)
# set(mylib "")
# find_library(mylib ${__depend_target_name} HINTS ${_pods_pkg_ld_dirs})
# message(STATUS ${mylib})
# if (NOT mylib)
# message(FATAL_ERROR "Could not find library ${__depend_target_name} specified in pkg-config ${__package} (looked in ${_pods_pkg_ld_dirs} in addition to the usual places)")
# else()
# message(STATUS "FOUND ${mylib}")
# endif()
# target_link_libraries(${target} ${mylib})
endif()
endforeach()
if (PODS_PKG_LDFLAGS_OTHER)
target_link_libraries(${target} ${PODS_PKG_LDFLAGS_OTHER})
endif()
if (PODS_PKG_CFLAGS_OTHER)
# TODO: Handle more PODS_PKG_CFLAGS_OTHER flags
string(FIND "${PODS_PKG_CFLAGS_OTHER}" "-pthread" PTHREAD_POS)
# handle pthread
if (PTHREAD_POS GREATER -1)
# from http://stackoverflow.com/a/29871891
find_package(Threads REQUIRED)
if (THREADS_HAVE_PTHREAD_ARG)
set_property(TARGET ${target} PROPERTY COMPILE_OPTIONS "-pthread")
set_property(TARGET ${target} PROPERTY INTERFACE_COMPILE_OPTIONS "-pthread")
endif()
if (CMAKE_THREAD_LIBS_INIT)
target_link_libraries(${target} "${CMAKE_THREAD_LIBS_INIT}")
endif()
endif()
endif(PODS_PKG_CFLAGS_OTHER)
endif()
endfunction()
# pods_use_pkg_config_includes(<package-name> ...)
#
# Invokes `pkg-config --cflags-only-I <package-name> ...` and adds the result to the
# include directories.
#
macro(pods_use_pkg_config_includes)
if(${ARGC} LESS 1)
message(WARNING "Useless invocation of pods_use_pkg_config_includes")
else()
if (NOT PKG_CONFIG_EXECUTABLE)
find_package(PkgConfig REQUIRED)
endif()
execute_process(COMMAND
${PKG_CONFIG_EXECUTABLE} --cflags-only-I ${ARGN}
OUTPUT_VARIABLE _pods_pkg_include_flags)
string(STRIP ${_pods_pkg_include_flags} _pods_pkg_include_flags)
string(REPLACE "-I" "" _pods_pkg_include_flags "${_pods_pkg_include_flags}")
include_directories(SYSTEM ${_pods_pkg_include_flags})
endif()
endmacro()
# pods_use_pkg_config_classpath(<package-name> ...)
#
# Convenience macro to get classpath flags from pkg-config and add them to CMAKE_JAVA_INCLUDE_PATH
#
# Invokes `pkg-config --variable=classpath <package-name> ...`, adds the result to the
# include path, and then calls pods_use_pkg_config_classpath on the required packages (to recursively add the path)
#
# also sets the variable <package-name>
# example:
# pods_use_pkg_config_classpath(lcm-java)
function(pods_use_pkg_config_classpath)
if(${ARGC} LESS 1)
message(WARNING "Useless invocation of pods_use_pkg_config_packages")
return()
endif()
if (NOT PKG_CONFIG_EXECUTABLE)
find_package(PkgConfig REQUIRED)
endif()
foreach(arg ${ARGV})
string(STRIP ${arg} _arg)
execute_process(COMMAND
${PKG_CONFIG_EXECUTABLE} --variable=classpath ${arg}
OUTPUT_VARIABLE _pods_pkg_classpath_flags)
string(STRIP ${_pods_pkg_classpath_flags} _pods_pkg_classpath_flags)
if (NOT WIN32)
string(REPLACE ":" " " _pods_pkg_classpath_flags ${_pods_pkg_classpath_flags})
endif()
if (NOT WIN32)
string(REPLACE " " ":" _pods_pkg_classpath_flags ${_pods_pkg_classpath_flags})
endif()
set( CMAKE_JAVA_INCLUDE_PATH ${CMAKE_JAVA_INCLUDE_PATH}:${_pods_pkg_classpath_flags})
string(REPLACE "::" ":" CMAKE_JAVA_INCLUDE_PATH ${CMAKE_JAVA_INCLUDE_PATH})
string(REGEX REPLACE "^:" "" CMAKE_JAVA_INCLUDE_PATH ${CMAKE_JAVA_INCLUDE_PATH})
execute_process(COMMAND
${PKG_CONFIG_EXECUTABLE} --print-requires ${arg}
OUTPUT_VARIABLE _pods_pkg_classpath_requires OUTPUT_STRIP_TRAILING_WHITESPACE)
if (NOT "${_pods_pkg_classpath_requires}" STREQUAL "")
string(STRIP ${_pods_pkg_classpath_requires} _pods_pkg_classpath_requires)
pods_use_pkg_config_classpath(${_pods_pkg_classpath_requires})
endif()
set( ${_arg}_CLASSPATH "${_pods_pkg_classpath_flags}" PARENT_SCOPE )
endforeach()
set( CMAKE_JAVA_INCLUDE_PATH ${CMAKE_JAVA_INCLUDE_PATH} PARENT_SCOPE )
endfunction()
# pods_config_search_paths()
#
# Setup include, linker, and pkg-config paths according to the pods core
# policy. This macro is automatically invoked, there is no need to do so
# manually.
macro(pods_config_search_paths)
if(NOT DEFINED __pods_setup)
#set where files should be output locally
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
set(INCLUDE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/include)
foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} )
string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${LIBRARY_OUTPUT_PATH} )
endforeach( OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES )
set(PKG_CONFIG_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib/pkgconfig)
#set where files should be installed to
set(LIBRARY_INSTALL_PATH ${CMAKE_INSTALL_PREFIX}/lib)
set(EXECUTABLE_INSTALL_PATH ${CMAKE_INSTALL_PREFIX}/bin)
set(INCLUDE_INSTALL_PATH ${CMAKE_INSTALL_PREFIX}/include)
set(PKG_CONFIG_INSTALL_PATH ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig)
pkg_config_path(PKG_CONFIG_OUTPUT_PATH)
pkg_config_path(PKG_CONFIG_INSTALL_PATH)
# add build/lib/pkgconfig to the pkg-config search path
if (WIN32)
set(_path "${PKG_CONFIG_OUTPUT_PATH};${PKG_CONFIG_INSTALL_PATH};$ENV{PKG_CONFIG_PATH}")
string(REGEX REPLACE ";+$" "" _path "${_path}")
set(ENV{PKG_CONFIG_PATH} "${_path}")
else()
set(ENV{PKG_CONFIG_PATH} "${PKG_CONFIG_OUTPUT_PATH}:${PKG_CONFIG_INSTALL_PATH}:$ENV{PKG_CONFIG_PATH}")
endif()
# add build/lib to the link path
link_directories(${LIBRARY_OUTPUT_PATH})
link_directories(${LIBRARY_INSTALL_PATH})
# abuse RPATH
if(${CMAKE_INSTALL_RPATH})
set(CMAKE_INSTALL_RPATH ${LIBRARY_INSTALL_PATH}:${CMAKE_INSTALL_RPATH})
else(${CMAKE_INSTALL_RPATH})
set(CMAKE_INSTALL_RPATH ${LIBRARY_INSTALL_PATH})
endif(${CMAKE_INSTALL_RPATH})
# for osx, which uses "install name" path rather than rpath
#set(CMAKE_INSTALL_NAME_DIR ${LIBRARY_OUTPUT_PATH})
set(CMAKE_INSTALL_NAME_DIR ${CMAKE_INSTALL_RPATH})
set(__pods_setup true)
endif(NOT DEFINED __pods_setup)
endmacro(pods_config_search_paths)
macro(enforce_out_of_source)
if(PROJECT_BINARY_DIR STREQUAL PROJECT_SOURCE_DIR)
message(FATAL_ERROR
"\n
Do not run cmake directly in the pod directory.
use the supplied Makefile instead! You now need to
remove CMakeCache.txt and the CMakeFiles directory.
Then to build, simply type:
$ make
")
endif()
endmacro(enforce_out_of_source)
#set the variable POD_NAME to the directory path, and set the cmake PROJECT_NAME
if(NOT POD_NAME)
get_filename_component(POD_NAME ${PROJECT_SOURCE_DIR} NAME)
message(STATUS "POD_NAME is not set... Defaulting to directory name: ${POD_NAME}")
endif(NOT POD_NAME)
project(${POD_NAME})
set(POD_NAME "${POD_NAME}" CACHE STRING "${POD_NAME}" )
# PODs out-of-source build logic
if (CMAKE_INSTALL_PREFIX STREQUAL "/usr/local" OR
CMAKE_INSTALL_PREFIX STREQUAL "C:/Program Files/Project" OR
CMAKE_INSTALL_PREFIX STREQUAL "C:/Program Files (x86)/Project")
find_file(_build_dir build PATHS ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/.. ${PROJECT_SOURCE_DIR}/../.. ${PROJECT_SOURCE_DIR}/../../.. ${PROJECT_SOURCE_DIR}/../../../..)
if (_build_dir)
set(CMAKE_INSTALL_PREFIX "${_build_dir}")
else()
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_SOURCE_DIR}/build)
set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}/build)
endif()
endif()
message(STATUS CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX})
#make sure we're running an out-of-source build
enforce_out_of_source()
#call the function to setup paths
pods_config_search_paths()