/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk

« back to all changes in this revision

Viewing changes to cmake/FindGC.cmake

  • Committer: Gustav Hartvigsson
  • Date: 2016-02-01 14:29:35 UTC
  • mfrom: (121.1.4 simpletypesystem_gc)
  • Revision ID: gustav.hartvigsson@gmail.com-20160201142935-tz7ef63id2g3yfof
* Merged GC branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
2
# FindGC.cmake
 
3
 
4
#   Copyright (c) 2010-2015  Takashi Kato <ktakashi@ymail.com>
 
5
 
6
#   Redistribution and use in source and binary forms, with or without
 
7
#   modification, are permitted provided that the following conditions
 
8
#   are met:
 
9
 
10
#   1. Redistributions of source code must retain the above copyright
 
11
#      notice, this list of conditions and the following disclaimer.
 
12
 
13
#   2. Redistributions in binary form must reproduce the above copyright
 
14
#      notice, this list of conditions and the following disclaimer in the
 
15
#      documentation and/or other materials provided with the distribution.
 
16
 
17
#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
18
#   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
19
#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
20
#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 
21
#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
22
#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
 
23
#   TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 
24
#   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 
25
#   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 
26
#   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 
27
#   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
28
 
29
#  $Id: $
 
30
 
31
 
 
32
# CMake module to find Boehm GC
 
33
 
 
34
# use pkg-config if available
 
35
FIND_PACKAGE(PkgConfig)
 
36
PKG_CHECK_MODULES(PC_BDW_GC QUIET bdw-gc)
 
37
 
 
38
# try newer one first in case of gc.h is overwritten.
 
39
FIND_PATH(BOEHM_GC_INCLUDE_DIR gc/gc.h
 
40
  HINTS ${PC_BDW_GC_INCLUDEDIR} ${PC_BDW_GC_INCLUDE_DIRS})
 
41
 
 
42
IF (NOT BOEHM_GC_INCLUDE_DIR)
 
43
  FIND_PATH(BOEHM_GC_INCLUDE_DIR gc.h
 
44
    HINTS ${PC_BDW_GC_INCLUDEDIR} ${PC_BDW_GC_INCLUDE_DIRS})
 
45
  IF (BOEHM_GC_INCLUDE_DIR)
 
46
    SET(HAVE_GC_H TRUE)
 
47
  ENDIF()
 
48
ELSE()
 
49
  SET(HAVE_GC_GC_H TRUE)
 
50
ENDIF()
 
51
 
 
52
# For FreeBSD we need to use gc-threaded
 
53
IF(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
 
54
  # checks if 'gc' supports 'GC_get_parallel' and if it does
 
55
  # then use it
 
56
  INCLUDE(${CMAKE_ROOT}/Modules/CheckCSourceCompiles.cmake)
 
57
  # not sure if this links properly...
 
58
  FIND_LIBRARY(BOEHM_GC_LIBRARIES NAMES gc
 
59
    HINTS ${PC_BDW_GC_LIBDIR} ${PC_BDW_GC_LIBRARY_DIRS})
 
60
  SET(CMAKE_REQUIRED_LIBRARIES "gc")
 
61
  SET(CMAKE_REQUIRED_DEFINITIONS "-DGC_THREADS")
 
62
  SET(CMAKE_REQUIRED_INCLUDES "${BOEHM_GC_INCLUDE_DIR}")
 
63
  SET(CMAKE_REQUIRED_FLAGS "-L${PC_BDW_GC_LIBRARY_DIRS}")
 
64
  MESSAGE(STATUS "Boehm GC include dir: ${CMAKE_REQUIRED_INCLUDES}")
 
65
  CHECK_C_SOURCE_RUNS(
 
66
    "#include <gc.h>
 
67
int main() {
 
68
int i= GC_get_parallel();
 
69
return 0;
 
70
}
 
71
" GC_GET_PARALLEL_WORKS)
 
72
  IF (NOT GC_GET_PARALLEL_WORKS)
 
73
    MESSAGE(STATUS "Try gc-threaded")
 
74
    SET(CMAKE_REQUIRED_LIBRARIES "gc-threaded")
 
75
    SET(CMAKE_REQUIRED_DEFINITIONS "-DGC_THREADS")
 
76
    SET(CMAKE_REQUIRED_INCLUDES "${BOEHM_GC_INCLUDE_DIR}")
 
77
    SET(CMAKE_REQUIRED_FLAGS "-L${PC_BDW_GC_LIBRARY_DIRS}")
 
78
    FIND_LIBRARY(BOEHM_GC_LIBRARIES NAMES gc-threaded
 
79
      HINTS ${PC_BDW_GC_LIBDIR} ${PC_BDW_GC_LIBRARY_DIRS})
 
80
    CHECK_C_SOURCE_RUNS(
 
81
      "#include <gc.h>
 
82
int main() {
 
83
int i=GC_get_parallel();
 
84
return 0;
 
85
}
 
86
" GC_GET_THREADED_PARALLEL_WORKS)
 
87
    IF(GC_GET_THREADED_PARALLEL_WORKS)
 
88
      # If non threaded library is installed, then for some reason CMake
 
89
      # would pick the wrong one (libgc.so). To avoid that, we make sure
 
90
      # libgc-threaded.so will be used.
 
91
      SET(BOEHM_GC_LIBRARIES "${PC_BDW_GC_LIBRARY_DIRS}/libgc-threaded.so")
 
92
    ENDIF()
 
93
  ENDIF()
 
94
ELSE()
 
95
  FIND_LIBRARY(BOEHM_GC_LIBRARIES NAMES gc
 
96
    HINTS ${PC_BDW_GC_LIBDIR} ${PC_BDW_GC_LIBRARY_DIRS})
 
97
  # OpenSolaris uses bgc as Boehm GC runtime in its package manager.
 
98
  # so try it
 
99
  IF (NOT BOEHM_GC_LIBRARIES)
 
100
    FIND_LIBRARY(BOEHM_GC_LIBRARIES NAMES bgc
 
101
      HINTS ${PC_BDW_GC_LIBDIR} ${PC_BDW_GC_LIBRARY_DIRS})
 
102
  ENDIF()
 
103
ENDIF()
 
104
 
 
105
INCLUDE(FindPackageHandleStandardArgs)
 
106
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Boehm_GC DEFAULT_MSG
 
107
                                  BOEHM_GC_LIBRARIES BOEHM_GC_INCLUDE_DIR)
 
108
 
 
109
MARK_AS_ADVANCED(BOEHM_GC_LIBRARIES BOEHM_GC_INCLUDE_DIR)