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