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