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