On dev: vc
[libcds.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.8.12)
2 cmake_policy(SET CMP0016 NEW)
3 set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/build/cmake ${CMAKE_MODULE_PATH})
4 include(TargetArch)
5
6 project(cds)
7
8 set(PROJECT_VERSION 2.2.0)
9
10 # Options
11 option(WITH_TESTS "Build unit tests" OFF)
12 option(WITH_TESTS_COVERAGE "Analyze test coverage using gcov (only for gcc)" OFF)
13 option(WITH_BOOST_ATOMIC "Use boost atomics (only for boost >= 1.54)" OFF)
14 option(WITH_ASAN "Build AddressSantinizer instrumented code" OFF)
15 option(WITH_TSAN "Build ThreadSantinizer instrumented code" OFF)
16
17 find_package(Threads REQUIRED)
18 find_package(Boost 1.50 COMPONENTS system thread REQUIRED)
19
20 include_directories(${Boost_INCLUDE_DIRS})
21
22 target_architecture(CMAKE_TARGET_ARCHITECTURE)
23
24 if(WITH_BOOST_ATOMIC)
25   if(${Boost_MINOR_VERSION} GREATER 53)
26     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCDS_USE_BOOST_ATOMIC")
27     message(STATUS "Boost version allows using of boost.atomic: activated")
28   endif()
29 endif(WITH_BOOST_ATOMIC)
30
31 if(WITH_ASAN)
32   if(CMAKE_COMPILER_IS_GNUCXX)
33     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1 -fPIC -fsanitize=address -g -fno-omit-frame-pointer -fno-optimize-sibling-calls")
34     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O1 -fsanitize=address -g -fno-omit-frame-pointer -fno-optimize-sibling-calls")
35     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address -pie")
36   else()
37     message(WARNING "Compiler does not support AddressSanitizer")
38   endif()
39 endif(WITH_ASAN)
40
41 if(WITH_TSAN)
42   if(CMAKE_COMPILER_IS_GNUCXX)
43     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1 -fPIC -fsanitize=thread -g -DCDS_THREAD_SANITIZER_ENABLED -fno-omit-frame-pointer")
44     set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -O1 -fPIC -fsanitize=thread -g -DCDS_THREAD_SANITIZER_ENABLED -fno-omit-frame-pointer")
45     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread -pie")
46   else()
47     message(WARNING "Compiler does not support ThreadSanitizer")
48   endif()
49 endif(WITH_TSAN)
50
51 if(WITH_TESTS_COVERAGE)
52   if(CMAKE_COMPILER_IS_GNUCXX)
53     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
54     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
55     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
56     message(STATUS "Test coverage analysis: activated")
57   else()
58         message(WARNING "Compiler is not GNU gcc! Test coverage couldn't be analyzed")
59   endif()  
60 endif(WITH_TESTS_COVERAGE)
61
62 set(CDS_SHARED_LIBRARY ${PROJECT_NAME})
63 set(CDS_STATIC_LIBRARY ${PROJECT_NAME}-s)
64
65 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
66 set(CMAKE_INCLUDE_CURRENT_DIR ON)
67
68 if(CDS_BIN_DIR)
69     set(EXECUTABLE_OUTPUT_PATH ${CDS_BIN_DIR})
70     set(LIBRARY_OUTPUT_PATH ${CDS_BIN_DIR})
71 else()
72     set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
73     set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
74 endif()
75 message(STATUS "Binary output path: ${EXECUTABLE_OUTPUT_PATH}")
76
77 if(NOT CMAKE_BUILD_TYPE)
78   set(CMAKE_BUILD_TYPE Debug CACHE STRING "Default build type to Debug" FORCE)
79 endif()
80
81 if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
82   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -pedantic -fno-strict-aliasing")  
83   if(CMAKE_TARGET_ARCHITECTURE STREQUAL "x86_64")
84     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcx16")
85   endif()    
86   if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "7.0.0")
87 #   gcc 4.8 - 6: disable noise -Wunused-local-typedefs
88     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedefs")  
89   endif()
90 endif()
91
92 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG")
93
94 message("Build type -- ${CMAKE_BUILD_TYPE}")
95 message("Compiler version: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
96 MESSAGE("Target architecture: ${CMAKE_TARGET_ARCHITECTURE}")
97 if (CMAKE_BUILD_TYPE STREQUAL "DEBUG")
98   message("Compiler flags: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}")
99 else()
100   message("Compiler flags: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}")
101 endif()
102 message("Boost: ${Boost_LIB_VERSION} in ${Boost_INCLUDE_DIRS}, lib ${Boost_LIBRARY_DIRS}")
103
104
105 include_directories(${PROJECT_SOURCE_DIR})
106
107 # Component names for separate distribution in rpms, debs etc.
108 set(LIBRARIES_COMPONENT lib)
109 set(HEADERS_COMPONENT devel)
110
111 set(SOURCES src/hp_gc.cpp
112             src/init.cpp
113             src/dhp_gc.cpp
114             src/urcu_gp.cpp
115             src/urcu_sh.cpp
116             src/michael_heap.cpp
117             src/topology_hpux.cpp
118             src/topology_linux.cpp
119             src/topology_osx.cpp
120             src/dllmain.cpp)
121
122 add_library(${CDS_SHARED_LIBRARY} SHARED ${SOURCES})
123 set_target_properties( ${CDS_SHARED_LIBRARY} PROPERTIES VERSION ${PROJECT_VERSION}
124                                                         DEBUG_POSTFIX "_d")
125 add_library(${CDS_STATIC_LIBRARY} STATIC ${SOURCES})
126 set_target_properties(${CDS_STATIC_LIBRARY} PROPERTIES DEBUG_POSTFIX "_d")
127 target_link_libraries(${CDS_SHARED_LIBRARY} PRIVATE ${CMAKE_THREAD_LIBS_INIT})
128 target_link_libraries(${CDS_STATIC_LIBRARY} PRIVATE ${CMAKE_THREAD_LIBS_INIT})
129
130 install(TARGETS ${CDS_SHARED_LIBRARY} DESTINATION lib COMPONENT ${LIBRARIES_COMPONENT})
131 install(TARGETS ${CDS_STATIC_LIBRARY} DESTINATION lib COMPONENT ${LIBRARIES_COMPONENT})
132 install(DIRECTORY ${PROJECT_SOURCE_DIR}/cds DESTINATION include COMPONENT ${HEADERS_COMPONENT})
133
134 if(WITH_TESTS)
135   enable_testing()
136   add_subdirectory(${PROJECT_SOURCE_DIR}/test)
137   message(STATUS "Build tests: activated")
138 endif(WITH_TESTS)
139
140 ### FOR PACKAGING in RPM, TGZ, DEB, NSYS...###############################################################################
141 set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
142 set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
143 set(CPACK_PACKAGE_CONTACT "Max Khizhinsky <libcds-user@lists.sourceforge.net>")
144 set(CPACK_PACKAGE_RELEASE 1)
145 set(CPACK_PACKAGE_INSTALL_DIRECTORY "cds")
146 set(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/build/cmake/description.txt")
147 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Library of concurrent data structures")
148 set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_PACKAGE_RELEASE}")
149 set(DEPLOY_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}")
150
151 # TGZ specific
152 set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
153
154 # RPM specific
155 set(CPACK_RPM_COMPONENT_INSTALL ON)
156 set(CPACK_RPM_PACKAGE_RELEASE ${CPACK_PACKAGE_RELEASE})
157 set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${PROJECT_SOURCE_DIR}/build/cmake/post_install_script.sh")
158 set(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE "${PROJECT_SOURCE_DIR}/build/cmake/post_uninstall_script.sh")
159 set(CPACK_RPM_PACKAGE_URL https://github.com/khizmax/libcds)
160 set(CPACK_RPM_PACKAGE_LICENSE GPL)
161 set(CPACK_RPM_PACKAGE_GROUP "System Environment/Base")
162 set(CPACK_RPM_PACKAGE_REQUIRES "boost >= 1.50")
163 set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION ${CPACK_PACKAGING_INSTALL_PREFIX})
164 set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION /usr/local)
165 set(CPACK_RPM_devel_PACKAGE_REQUIRES "boost >= 1.50, cds-lib = ${PROJECT_VERSION}")
166
167 # DEB specific
168 set(CPACK_DEB_COMPONENT_INSTALL ON)
169 set(CPACK_DEBIAN_PACKAGE_DEPENDS "boost (>= 1.50)")
170 set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/khizmax/libcds")
171 set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${PROJECT_SOURCE_DIR}/build/cmake/post_install_script.sh;;${PROJECT_SOURCE_DIR}/build/cmake/post_uninstall_script.sh;" )
172
173 # NSYS specific
174 set(CPACK_NSIS_PACKAGE_NAME "${CPACK_PACKAGE_NAME}")
175 set(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_NAME}")
176 set(CPACK_NSIS_CONTACT ${CPACK_PACKAGE_CONTACT})
177 set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON)
178 set(CPACK_NSIS_MODIFY_PATH ON)
179
180 # Components grouping for Mac OS X and Windows installers
181 set(CPACK_COMPONENT_${LIBRARIES_COMPONENT}_GROUP "Runtime")
182 set(CPACK_COMPONENT_${HEADERS_COMPONENT}_GROUP "Development")
183 set(CPACK_COMPONENT_${LIBRARIES_COMPONENT}_DISPLAY_NAME "Libraries")
184 set(CPACK_COMPONENT_${HEADERS_COMPONENT}_DISPLAY_NAME "C++ Headers")
185 set(CPACK_COMPONENT_${HEADERS_COMPONENT}_DEPENDS ${LIBRARIES_COMPONENT})
186 set(CPACK_COMPONENT_GROUP_DEVELOPMENT_DESCRIPTION "All of the tools you'll ever need to develop lock-free oriented software with libcds")
187 set(CPACK_COMPONENT_GROUP_RUNTIME_DESCRIPTION "Only libcds library for runtime")
188
189 include(CPack)