Add libcuckoo to test suite
[junction.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.8.5)
2
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")
7         project(Junction)
8     set_property(GLOBAL PROPERTY USE_FOLDERS ON)
9     include(cmake/JunctionProjectDefs.cmake)
10     ApplyTurfBuildSettings()
11 elseif(NOT JUNCTION_FOUND)
12     message(FATAL_ERROR "You must include cmake/JunctionProjectDefs.cmake before adding this subdirectory")
13 endif() 
14
15 # Default values, can be overridden by user
16 set(JUNCTION_USERCONFIG "" CACHE STRING "Optional path to additional config file (relative to root CMakeLists.txt)")
17 set(JUNCTION_WITH_FOLLY FALSE CACHE BOOL "Use Folly")
18 set(JUNCTION_WITH_CDS FALSE CACHE BOOL "Use CDS")
19 set(JUNCTION_WITH_NBDS FALSE CACHE BOOL "Use NBDS")
20 set(JUNCTION_WITH_TBB FALSE CACHE BOOL "Use TBB")
21 set(JUNCTION_WITH_TERVEL FALSE CACHE BOOL "Use Tervel")
22 set(JUNCTION_TRACK_GRAMPA_STATS FALSE CACHE BOOL "Enable stats in ConcurrentMap_Grampa")
23 set(JUNCTION_USE_STRIPING TRUE CACHE BOOL "Allocate a fixed-size ConditionBank for striped primitives")
24
25 # Initialize variables used to collect include dirs/libraries.
26 set(JUNCTION_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/include")
27 set(JUNCTION_ALL_INCLUDE_DIRS "${JUNCTION_INCLUDE_DIRS}")
28 set(JUNCTION_ALL_LIBRARIES junction)
29 set(JUNCTION_ALL_DLLS "")
30
31 # Add turf targets
32 add_subdirectory(${TURF_ROOT} turf)
33 list(APPEND JUNCTION_ALL_INCLUDE_DIRS ${TURF_INCLUDE_DIRS})
34 list(APPEND JUNCTION_ALL_LIBRARIES ${TURF_ALL_LIBRARIES})
35
36 # Optional: Locate Folly and append it to the list of include dirs/libraries.
37 if(JUNCTION_WITH_FOLLY)
38         find_package(Folly REQUIRED)
39         list(APPEND JUNCTION_ALL_INCLUDE_DIRS ${FOLLY_INCLUDE_DIR})
40         list(APPEND JUNCTION_ALL_LIBRARIES ${FOLLY_LIBRARIES})
41 endif()
42
43 # Optional: Locate CDS and append it to the list of include dirs/libraries.
44 if(JUNCTION_WITH_CDS)
45     find_package(CDS REQUIRED)
46     list(APPEND JUNCTION_ALL_INCLUDE_DIRS ${CDS_INCLUDE_DIR})
47     list(APPEND JUNCTION_ALL_LIBRARIES ${CDS_LIBRARY})
48     list(APPEND JUNCTION_ALL_DLLS ${CDS_DLL})
49 endif()
50
51 # Optional: Locate NBDS and append it to the list of include dirs/libraries.
52 if(JUNCTION_WITH_NBDS)
53     set(NBDS_USE_TURF_HEAP FALSE CACHE BOOL "Redirect NBDS's memory allocator to use Turf")
54     find_package(NBDS REQUIRED)
55     list(APPEND JUNCTION_ALL_INCLUDE_DIRS ${NBDS_INCLUDE_DIRS})
56     # If NBDS_USE_TURF_HEAP=1, then NBDS has dependencies on junction, so add junction to the linker
57     # command line again as needed by the GNU linker.
58     list(APPEND JUNCTION_ALL_LIBRARIES ${NBDS_LIBRARIES} junction)
59 endif()
60
61 # Optional: Locate Intel TBB and append it to the list of include dirs/libraries.
62 if(JUNCTION_WITH_TBB)
63     set(TBB_USE_TURF_HEAP FALSE CACHE BOOL "Redirect TBB's memory allocator to use Turf")
64     find_package(TBB REQUIRED)
65     list(APPEND JUNCTION_ALL_INCLUDE_DIRS ${TBB_INCLUDE_DIRS})
66     # If TBB_USE_TURF_HEAP=1, then TBB has dependencies on junction, so add junction to the linker
67     # command line again as needed by the GNU linker.
68     list(APPEND JUNCTION_ALL_LIBRARIES ${TBB_LIBRARIES} junction)
69 endif()
70
71 # Optional: Locate Tervel and append it to the list of include dirs/libraries.
72 if(JUNCTION_WITH_TERVEL)
73     find_package(Tervel REQUIRED)
74     list(APPEND JUNCTION_ALL_INCLUDE_DIRS ${TERVEL_INCLUDE_DIRS})
75     list(APPEND JUNCTION_ALL_LIBRARIES ${TERVEL_LIBRARIES})
76 endif()
77
78 # Optional: Locate libcuckoo and append it to the list of include dirs/libraries.
79 if(JUNCTION_WITH_LIBCUCKOO)
80     find_package(LibCuckoo REQUIRED)
81     list(APPEND JUNCTION_ALL_INCLUDE_DIRS ${LIBCUCKOO_INCLUDE_DIRS})
82 endif()
83
84 # If this is the root listfile, add all samples
85 if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
86     file(GLOB children samples/*)
87     foreach(child ${children})
88         if(EXISTS "${child}/CMakeLists.txt")
89             add_subdirectory("${child}")
90         endif()
91     endforeach()
92 endif()
93
94 # Gather source files.
95 GetFilesWithSourceGroups(GLOB_RECURSE JUNCTION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/junction junction/*.cpp junction/*.h)
96
97 # Configure autogenerated headers.
98 ConfigureFileIfChanged(cmake/junction_config.h.in "${CMAKE_CURRENT_BINARY_DIR}/include/junction_config.h" JUNCTION_FILES)
99 if(JUNCTION_USERCONFIG)
100     # Interpret JUNCTION_USERCONFIG relative to root project, in case Junction was added as a subdirectory
101     GetAbsoluteRelativeTo(absPath "${CMAKE_SOURCE_DIR}" "${JUNCTION_USERCONFIG}")
102     ConfigureFileIfChanged("${absPath}" "${CMAKE_CURRENT_BINARY_DIR}/include/junction_userconfig.h" JUNCTION_FILES)
103 else()
104     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)
105 endif()
106
107 # Define library target.
108 add_library(junction ${JUNCTION_FILES})
109
110 # Set include dirs for this library (done last, so it's not inherited by subprojects like Tervel, NBDS).
111 include_directories(${JUNCTION_ALL_INCLUDE_DIRS})
112
113 # Export include dirs/libraries to parent project if we were invoked using add_subdirectory().
114 if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
115     set(JUNCTION_INCLUDE_DIRS "${JUNCTION_INCLUDE_DIRS}" PARENT_SCOPE)
116     set(JUNCTION_ALL_INCLUDE_DIRS "${JUNCTION_ALL_INCLUDE_DIRS}" PARENT_SCOPE)
117     set(JUNCTION_ALL_LIBRARIES "${JUNCTION_ALL_LIBRARIES}" PARENT_SCOPE)
118     set(JUNCTION_ALL_DLLS "${JUNCTION_ALL_DLLS}" PARENT_SCOPE)
119 endif()
120