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 get_filename_component(outerPath "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE)
33 set(TURF_ROOT "${outerPath}/turf" CACHE STRING "Path to Turf")
34 include("${TURF_ROOT}/cmake/Macros.cmake")
35 if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
36 # If this is the root project, apply build settings here so that
37 # they're applied to all targets
38 ApplyTurfBuildSettings()
40 add_subdirectory(${TURF_ROOT} turf)
41 list(APPEND JUNCTION_ALL_INCLUDE_DIRS ${TURF_INCLUDE_DIRS})
42 list(APPEND JUNCTION_ALL_LIBRARIES ${TURF_ALL_LIBRARIES})
44 # Optional: Locate Folly and append it to the list of include dirs/libraries.
45 if(JUNCTION_WITH_FOLLY)
46 find_package(Folly REQUIRED)
47 list(APPEND JUNCTION_ALL_INCLUDE_DIRS ${FOLLY_INCLUDE_DIR})
48 list(APPEND JUNCTION_ALL_LIBRARIES ${FOLLY_LIBRARIES})
51 # Optional: Locate CDS and append it to the list of include dirs/libraries.
53 find_package(CDS REQUIRED)
54 list(APPEND JUNCTION_ALL_INCLUDE_DIRS ${CDS_INCLUDE_DIR})
55 list(APPEND JUNCTION_ALL_LIBRARIES ${CDS_LIBRARY})
56 list(APPEND JUNCTION_ALL_DLLS ${CDS_DLL})
59 # Optional: Locate NBDS and append it to the list of include dirs/libraries.
60 if(JUNCTION_WITH_NBDS)
61 set(NBDS_USE_TURF_HEAP FALSE CACHE BOOL "Redirect NBDS's memory allocator to use Turf")
62 find_package(NBDS REQUIRED)
63 list(APPEND JUNCTION_ALL_INCLUDE_DIRS ${NBDS_INCLUDE_DIRS})
64 # If NBDS_USE_TURF_HEAP=1, then NBDS has dependencies on junction, so add junction to the linker
65 # command line again as needed by the GNU linker.
66 list(APPEND JUNCTION_ALL_LIBRARIES ${NBDS_LIBRARIES} junction)
69 # Optional: Locate Intel TBB and append it to the list of include dirs/libraries.
71 set(TBB_USE_TURF_HEAP FALSE CACHE BOOL "Redirect TBB's memory allocator to use Turf")
72 find_package(TBB REQUIRED)
73 list(APPEND JUNCTION_ALL_INCLUDE_DIRS ${TBB_INCLUDE_DIRS})
74 # If TBB_USE_TURF_HEAP=1, then TBB has dependencies on junction, so add junction to the linker
75 # command line again as needed by the GNU linker.
76 list(APPEND JUNCTION_ALL_LIBRARIES ${TBB_LIBRARIES} junction)
79 # Optional: Locate Tervel and append it to the list of include dirs/libraries.
80 if(JUNCTION_WITH_TERVEL)
81 find_package(Tervel REQUIRED)
82 list(APPEND JUNCTION_ALL_INCLUDE_DIRS ${TERVEL_INCLUDE_DIRS})
83 list(APPEND JUNCTION_ALL_LIBRARIES ${TERVEL_LIBRARIES})
86 # Optional: Locate libcuckoo and append it to the list of include dirs/libraries.
87 if(JUNCTION_WITH_LIBCUCKOO)
88 find_package(LibCuckoo REQUIRED)
89 list(APPEND JUNCTION_ALL_INCLUDE_DIRS ${LIBCUCKOO_INCLUDE_DIRS})
92 # If this is the root listfile, add all samples
93 if((CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) AND JUNCTION_WITH_SAMPLES)
94 file(GLOB children samples/*)
95 foreach(child ${children})
96 if(EXISTS "${child}/CMakeLists.txt")
97 add_subdirectory("${child}")
102 # Gather source files.
103 GetFilesWithSourceGroups(GLOB_RECURSE JUNCTION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/junction junction/*.cpp junction/*.h)
105 # Configure autogenerated headers.
106 ConfigureFileIfChanged(cmake/junction_config.h.in "${CMAKE_CURRENT_BINARY_DIR}/include/junction_config.h" JUNCTION_FILES)
107 if(JUNCTION_USERCONFIG)
108 # Interpret JUNCTION_USERCONFIG relative to root project, in case Junction was added as a subdirectory
109 GetAbsoluteRelativeTo(absPath "${CMAKE_SOURCE_DIR}" "${JUNCTION_USERCONFIG}")
110 ConfigureFileIfChanged("${absPath}" "${CMAKE_CURRENT_BINARY_DIR}/include/junction_userconfig.h" JUNCTION_FILES)
112 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)
115 # Define library target.
116 add_library(junction ${JUNCTION_FILES})
118 # Set include dirs for this library (done last, so it's not inherited by subprojects like Tervel, NBDS).
119 include_directories(${JUNCTION_ALL_INCLUDE_DIRS})
122 if(JUNCTION_MAKE_INSTALLABLE)
123 install(TARGETS junction DESTINATION lib)
124 install(DIRECTORY junction/ DESTINATION include/junction FILES_MATCHING PATTERN "*.h")
125 file(GLOB configHeaders "${CMAKE_CURRENT_BINARY_DIR}/include/*.h")
126 install(FILES ${configHeaders} DESTINATION include)
129 # Export include dirs/libraries to parent project if we were invoked using add_subdirectory().
130 if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
131 set(JUNCTION_INCLUDE_DIRS "${JUNCTION_INCLUDE_DIRS}" PARENT_SCOPE)
132 set(JUNCTION_ALL_INCLUDE_DIRS "${JUNCTION_ALL_INCLUDE_DIRS}" PARENT_SCOPE)
133 set(JUNCTION_ALL_LIBRARIES "${JUNCTION_ALL_LIBRARIES}" PARENT_SCOPE)
134 set(JUNCTION_ALL_DLLS "${JUNCTION_ALL_DLLS}" PARENT_SCOPE)