1 cmake_minimum_required(VERSION 2.8.5)
3 if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
4 # If this is the root project, issue a project() command so that
5 # the Visual Studio generator will create an .sln file.
6 set(CMAKE_CONFIGURATION_TYPES "Debug;RelWithAsserts;RelWithDebInfo" CACHE INTERNAL "Build configs")
8 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
9 set(JUNCTION_WITH_SAMPLES TRUE CACHE BOOL "Include all Junction samples in generated build system")
10 set(JUNCTION_MAKE_INSTALLABLE TRUE)
11 set(TURF_MAKE_INSTALLABLE TRUE)
14 # Default values, can be overridden by user
15 set(JUNCTION_USERCONFIG "" CACHE STRING "Optional path to additional config file (relative to root CMakeLists.txt)")
16 set(JUNCTION_WITH_FOLLY FALSE CACHE BOOL "Use Folly")
17 set(JUNCTION_WITH_CDS FALSE CACHE BOOL "Use CDS")
18 set(JUNCTION_WITH_NBDS FALSE CACHE BOOL "Use NBDS")
19 set(JUNCTION_WITH_TBB FALSE CACHE BOOL "Use TBB")
20 set(JUNCTION_WITH_TERVEL FALSE CACHE BOOL "Use Tervel")
21 set(JUNCTION_TRACK_GRAMPA_STATS FALSE CACHE BOOL "Enable stats in ConcurrentMap_Grampa")
22 set(JUNCTION_USE_STRIPING TRUE CACHE BOOL "Allocate a fixed-size ConditionBank for striped primitives")
24 # Initialize variables used to collect include dirs/libraries.
25 set(JUNCTION_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/include")
26 set(JUNCTION_ALL_INCLUDE_DIRS "${JUNCTION_INCLUDE_DIRS}")
27 set(JUNCTION_ALL_LIBRARIES junction)
28 set(JUNCTION_ALL_DLLS "")
29 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
31 # Add turf targets and import its macros since we use them below
32 find_package(Turf REQUIRED)
33 include("${TURF_ROOT}/cmake/Macros.cmake")
34 if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
35 # If this is the root project, apply build settings here so that
36 # they're applied to all targets
37 ApplyTurfBuildSettings()
39 add_subdirectory(${TURF_ROOT} turf)
40 list(APPEND JUNCTION_ALL_INCLUDE_DIRS ${TURF_INCLUDE_DIRS})
41 list(APPEND JUNCTION_ALL_LIBRARIES ${TURF_ALL_LIBRARIES})
43 # Optional: Locate Folly and append it to the list of include dirs/libraries.
44 if(JUNCTION_WITH_FOLLY)
45 find_package(Folly REQUIRED)
46 list(APPEND JUNCTION_ALL_INCLUDE_DIRS ${FOLLY_INCLUDE_DIR})
47 list(APPEND JUNCTION_ALL_LIBRARIES ${FOLLY_LIBRARIES})
50 # Optional: Locate CDS and append it to the list of include dirs/libraries.
52 find_package(CDS REQUIRED)
53 list(APPEND JUNCTION_ALL_INCLUDE_DIRS ${CDS_INCLUDE_DIR})
54 list(APPEND JUNCTION_ALL_LIBRARIES ${CDS_LIBRARY})
55 list(APPEND JUNCTION_ALL_DLLS ${CDS_DLL})
58 # Optional: Locate NBDS and append it to the list of include dirs/libraries.
59 if(JUNCTION_WITH_NBDS)
60 set(NBDS_USE_TURF_HEAP FALSE CACHE BOOL "Redirect NBDS's memory allocator to use Turf")
61 find_package(NBDS REQUIRED)
62 list(APPEND JUNCTION_ALL_INCLUDE_DIRS ${NBDS_INCLUDE_DIRS})
63 # If NBDS_USE_TURF_HEAP=1, then NBDS has dependencies on junction, so add junction to the linker
64 # command line again as needed by the GNU linker.
65 list(APPEND JUNCTION_ALL_LIBRARIES ${NBDS_LIBRARIES} junction)
68 # Optional: Locate Intel TBB and append it to the list of include dirs/libraries.
70 set(TBB_USE_TURF_HEAP FALSE CACHE BOOL "Redirect TBB's memory allocator to use Turf")
71 find_package(TBB REQUIRED)
72 list(APPEND JUNCTION_ALL_INCLUDE_DIRS ${TBB_INCLUDE_DIRS})
73 # If TBB_USE_TURF_HEAP=1, then TBB has dependencies on junction, so add junction to the linker
74 # command line again as needed by the GNU linker.
75 list(APPEND JUNCTION_ALL_LIBRARIES ${TBB_LIBRARIES} junction)
78 # Optional: Locate Tervel and append it to the list of include dirs/libraries.
79 if(JUNCTION_WITH_TERVEL)
80 find_package(Tervel REQUIRED)
81 list(APPEND JUNCTION_ALL_INCLUDE_DIRS ${TERVEL_INCLUDE_DIRS})
82 list(APPEND JUNCTION_ALL_LIBRARIES ${TERVEL_LIBRARIES})
85 # Optional: Locate libcuckoo and append it to the list of include dirs/libraries.
86 if(JUNCTION_WITH_LIBCUCKOO)
87 find_package(LibCuckoo REQUIRED)
88 list(APPEND JUNCTION_ALL_INCLUDE_DIRS ${LIBCUCKOO_INCLUDE_DIRS})
91 # If this is the root listfile, add all samples
92 if((CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) AND JUNCTION_WITH_SAMPLES)
93 file(GLOB children samples/*)
94 foreach(child ${children})
95 if(EXISTS "${child}/CMakeLists.txt")
96 add_subdirectory("${child}")
101 # Gather source files.
102 GetFilesWithSourceGroups(GLOB_RECURSE JUNCTION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/junction junction/*.cpp junction/*.h)
104 # Configure autogenerated headers.
105 ConfigureFileIfChanged(cmake/junction_config.h.in "${CMAKE_CURRENT_BINARY_DIR}/include/junction_config.h" JUNCTION_FILES)
106 if(JUNCTION_USERCONFIG)
107 # Interpret JUNCTION_USERCONFIG relative to root project, in case Junction was added as a subdirectory
108 GetAbsoluteRelativeTo(absPath "${CMAKE_SOURCE_DIR}" "${JUNCTION_USERCONFIG}")
109 ConfigureFileIfChanged("${absPath}" "${CMAKE_CURRENT_BINARY_DIR}/include/junction_userconfig.h" JUNCTION_FILES)
111 WriteFileIfDifferent("// JUNCTION_USERCONFIG not set when CMake was run. This is a placeholder file.\n" "${CMAKE_CURRENT_BINARY_DIR}/include/junction_userconfig.h" JUNCTION_FILES)
114 # Define library target.
115 add_library(junction ${JUNCTION_FILES})
117 # Set include dirs for this library (done last, so it's not inherited by subprojects like Tervel, NBDS).
118 include_directories(${JUNCTION_ALL_INCLUDE_DIRS})
121 if(JUNCTION_MAKE_INSTALLABLE)
122 install(TARGETS junction DESTINATION lib)
123 install(DIRECTORY junction/ DESTINATION include/junction FILES_MATCHING PATTERN "*.h")
124 file(GLOB configHeaders "${CMAKE_CURRENT_BINARY_DIR}/include/*.h")
125 install(FILES ${configHeaders} DESTINATION include)
128 # Export include dirs/libraries to parent project if we were invoked using add_subdirectory().
129 if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
130 set(JUNCTION_INCLUDE_DIRS "${JUNCTION_INCLUDE_DIRS}" PARENT_SCOPE)
131 set(JUNCTION_ALL_INCLUDE_DIRS "${JUNCTION_ALL_INCLUDE_DIRS}" PARENT_SCOPE)
132 set(JUNCTION_ALL_LIBRARIES "${JUNCTION_ALL_LIBRARIES}" PARENT_SCOPE)
133 set(JUNCTION_ALL_DLLS "${JUNCTION_ALL_DLLS}" PARENT_SCOPE)