Skip to content

Commit

Permalink
partial CMake support ++
Browse files Browse the repository at this point in the history
- initial cmake support
- downgrade cmake requirement to 2.8.12
- factorize cmake test flags / libs options
- add the strings related tests to cmake
- run under RHEL6 + gcc 4.9.X
- add the time related tests to cmake
- add static library installation to cmake
- add headers installation to cmake
- add the container related tests to cmake
- add the types related tests to cmake
  • Loading branch information
adevress committed Sep 29, 2017
1 parent cdf20ca commit 02d7a3d
Show file tree
Hide file tree
Showing 19 changed files with 1,169 additions and 0 deletions.
118 changes: 118 additions & 0 deletions CMake/CompilerFlagsHelpers.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#
# Copyright 2017 The Abseil Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


set(SUPPORTED_COMPILER_LANGUAGE_LIST "C;CXX")

## detect compiler
foreach(COMPILER_LANGUAGE ${SUPPORTED_COMPILER_LANGUAGE_LIST})

if(CMAKE_${COMPILER_LANGUAGE}_COMPILER_ID STREQUAL "XL")
set(CMAKE_${COMPILER_LANGUAGE}_COMPILER_IS_XLC ON)
elseif(CMAKE_${COMPILER_LANGUAGE}_COMPILER_ID STREQUAL "Intel")
set(CMAKE_${COMPILER_LANGUAGE}_COMPILER_IS_ICC ON)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(CMAKE_${COMPILER_LANGUAGE}_COMPILER_IS_MSVC)
elseif(${CMAKE_${COMPILER_LANGUAGE}_COMPILER_ID} STREQUAL "Clang")
set(CMAKE_${COMPILER_LANGUAGE}_COMPILER_IS_CLANG ON)
else(CMAKE_${COMPILER_LANGUAGE}_COMPILER_ID STREQUAL "GNU")
set(CMAKE_${COMPILER_LANGUAGE}_COMPILER_IS_GCC ON)
endif()

endforeach()




foreach(COMPILER_LANGUAGE ${SUPPORTED_COMPILER_LANGUAGE_LIST})

# XLC compiler
if(CMAKE_${COMPILER_LANGUAGE}_COMPILER_IS_XLC)

# XLC -qinfo=all is awfully verbose on any platforms that use the GNU STL
# Enable by default only the relevant one
set(CMAKE_${COMPILER_LANGUAGE}_WARNING_ALL "-qformat=all -qinfo=lan:trx:ret:zea:cmp:ret")

set(CMAKE_${COMPILER_LANGUAGE}_DEBUGINFO_FLAGS "-g")

set(CMAKE_${COMPILER_LANGUAGE}_OPT_NONE "-O0")
set(CMAKE_${COMPILER_LANGUAGE}_OPT_NORMAL "-O2")
set(CMAKE_${COMPILER_LANGUAGE}_OPT_AGGRESSIVE "-O3")
set(CMAKE_${COMPILER_LANGUAGE}_OPT_FASTEST "-O5")

set(CMAKE_${COMPILER_LANGUAGE}_NO_ASSERT "-DNDEBUG")

set(CMAKE_${COMPILER_LANGUAGE}_STACK_PROTECTION "-qstackprotect")

set(CMAKE_${COMPILER_LANGUAGE}_POSITION_INDEPENDANT "-qpic=small")

set(CMAKE_${COMPILER_LANGUAGE}_VECTORIZE "-qhot")

# Microsoft compiler
elseif(CMAKE_${COMPILER_LANGUAGE}_COMPILER_IS_MSVC)

set(CMAKE_${COMPILER_LANGUAGE}_DEBUGINFO_FLAGS "-Zi")

set(CMAKE_${COMPILER_LANGUAGE}_OPT_NONE "")
set(CMAKE_${COMPILER_LANGUAGE}_OPT_NORMAL "-O2")
set(CMAKE_${COMPILER_LANGUAGE}_OPT_AGGRESSIVE "-O2")
set(CMAKE_${COMPILER_LANGUAGE}_OPT_FASTEST "-O2")

set(CMAKE_${COMPILER_LANGUAGE}_STACK_PROTECTION "-GS")

# enable by default on MSVC
set(CMAKE_${COMPILER_LANGUAGE}_POSITION_INDEPENDANT "")


## GCC, CLANG, rest of the world
else()

set(CMAKE_${COMPILER_LANGUAGE}_WARNING_ALL "-Wall -Wextra")

set(CMAKE_${COMPILER_LANGUAGE}_DEBUGINFO_FLAGS "-g")

set(CMAKE_${COMPILER_LANGUAGE}_OPT_NONE "-O0")
set(CMAKE_${COMPILER_LANGUAGE}_OPT_NORMAL "-O2")
set(CMAKE_${COMPILER_LANGUAGE}_OPT_AGGRESSIVE "-O3")
set(CMAKE_${COMPILER_LANGUAGE}_OPT_FASTEST "-Ofast -march=native")


set(CMAKE_${COMPILER_LANGUAGE}_NO_ASSERT "-DNDEBUG")

set(CMAKE_${COMPILER_LANGUAGE}_STACK_PROTECTION "-fstack-protector")

set(CMAKE_${COMPILER_LANGUAGE}_POSITION_INDEPENDANT "-fPIC")

set(CMAKE_${COMPILER_LANGUAGE}_VECTORIZE "-ftree-vectorize")

if(CMAKE_${COMPILER_LANGUAGE}_COMPILER_IS_GCC AND ( CMAKE_${COMPILER_LANGUAGE}_COMPILER_VERSION VERSION_GREATER "4.7.0") )
set(CMAKE_${COMPILER_LANGUAGE}_LINK_TIME_OPT "-flto")
endif()

if( (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^ppc" ) OR ( CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^power" ) )
## ppc arch do not support -march= syntax
set(CMAKE_${COMPILER_LANGUAGE}_GEN_NATIVE "-mcpu=native")
else()
set(CMAKE_${COMPILER_LANGUAGE}_GEN_NATIVE "-march=native")
endif()
endif()



endforeach()



27 changes: 27 additions & 0 deletions CMake/FindCCTZ.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# Copyright 2017 The Abseil Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

include(FindPackageHandleStandardArgs)


find_path(CCTZ_INCLUDE_DIRS NAMES cctz/civil_time.h)
find_library(CCTZ_LIBRARIES NAMES cctz )

find_package_handle_standard_args(CCTZ DEFAULT_MSG CCTZ_INCLUDE_DIRS CCTZ_LIBRARIES)

mark_as_advanced(CCTZ_FOUND CCTZ_INCLUDE_DIRS CCTZ_LIBRARIES)


27 changes: 27 additions & 0 deletions CMake/FindGMock.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# Copyright 2017 The Abseil Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

include(FindPackageHandleStandardArgs)


find_path(GMOCK_INCLUDE_DIRS NAMES gmock/gmock.h)
find_library(GMOCK_LIBRARIES NAMES gmock )

find_package_handle_standard_args(GMOCK DEFAULT_MSG GMOCK_INCLUDE_DIRS GMOCK_LIBRARIES)

mark_as_advanced(GMOCK_FOUND GMOCK_INCLUDE_DIRS GMOCK_LIBRARIES)


29 changes: 29 additions & 0 deletions CMake/FindRE2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#
# Copyright 2017 The Abseil Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

include(FindPackageHandleStandardArgs)

set(RE2_FIND_REQUIRED TRUE)


find_path(RE2_INCLUDE_DIRS NAMES re2.h PATH_SUFFIXES re2)
find_library(RE2_LIBRARIES NAMES re2 )

find_package_handle_standard_args(RE2 DEFAULT_MSG RE2_INCLUDE_DIRS RE2_LIBRARIES)

mark_as_advanced(RE2_FOUND RE2_INCLUDE_DIRS RE2_LIBRARIES)


45 changes: 45 additions & 0 deletions CMake/ReleaseDebugAutoFlags.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#
# Copyright 2017 The Abseil Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

## default configuration
if(NOT CMAKE_BUILD_TYPE AND (NOT CMAKE_CONFIGURATION_TYPES))
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE)
message(STATUS "Setting build type to '${CMAKE_BUILD_TYPE}' as none was specified.")
endif()


# Different configuration types:
#
# Debug : Optimized for debugging, include symbols
# Release : Release mode, no debuginfo
# RelWithDebInfo : Distribution mode, basic optimizations for potable code with debuginfos
# Fast : Maximum level of optimization. Target native architecture, enable all local CPU instructions, generate not portable code

include(CompilerFlagsHelpers)


set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_WARNING_ALL} ${CMAKE_CXX_NO_ASSERT} ${CMAKE_C_OPT_NORMAL}")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_DEBUGINFO_FLAGS} ${CMAKE_C_WARNING_ALL} ${CMAKE_C_OPT_NONE} ${CMAKE_C_STACK_PROTECTION}")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_DEBUGINFO_FLAGS} ${CMAKE_C_WARNING_ALL} ${CMAKE_C_OPT_NORMAL} ${CMAKE_C_NO_ASSERT}")
set(CMAKE_C_FLAGS_FAST "${CMAKE_C_WARNING_ALL} ${CMAKE_CXX_NO_ASSERT} ${CMAKE_C_OPT_FASTEST} ${CMAKE_C_LINK_TIME_OPT} ${CMAKE_C_GEN_NATIVE}")



set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_WARNING_ALL} ${CMAKE_CXX_NO_ASSERT} ${CMAKE_CXX_OPT_NORMAL}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_DEBUGINFO_FLAGS} ${CMAKE_CXX_WARNING_ALL} ${CMAKE_CXX_OPT_NONE} ${CMAKE_CXX_STACK_PROTECTION}")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_DEBUGINFO_FLAGS} ${CMAKE_CXX_WARNING_ALL} ${CMAKE_CXX_OPT_NORMAL} ${CMAKE_CXX_NO_ASSERT}")
set(CMAKE_CXX_FLAGS_FAST "${CMAKE_CXX_WARNING_ALL} ${CMAKE_CXX_NO_ASSERT} ${CMAKE_CXX_OPT_FASTEST} ${CMAKE_CXX_LINK_TIME_OPT} ${CMAKE_CXX_GEN_NATIVE}")

52 changes: 52 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#
# Copyright 2017 The Abseil Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
cmake_minimum_required(VERSION 2.8.12)
project(absl)

# enable ctest
enable_testing()

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMake)

# use usual unix path
include(GNUInstallDirs)
include(ReleaseDebugAutoFlags)

# pthread
find_package(Threads REQUIRED)

# check for GTest
find_package(GTest REQUIRED)
find_package(GMock REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS} ${GMOCK_INCLUDE_DIRS})

# check for other google dependencies
find_package(CCTZ REQUIRED)
include_directories(${CCTZ_INCLUDE_DIRS})

# include current path
include_directories(${CMAKE_CURRENT_SOURCE_DIR})

set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")

list(APPEND ABSL_TEST_COMMON_LIBRARIES
${GTEST_MAIN_LIBRARIES}
${GTEST_LIBRARIES}
${GMOCK_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)

add_subdirectory(absl)
29 changes: 29 additions & 0 deletions absl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#
# Copyright 2017 The Abseil Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


add_subdirectory(algorithm)
add_subdirectory(base)
add_subdirectory(container)
add_subdirectory(debugging)
add_subdirectory(memory)
add_subdirectory(meta)
add_subdirectory(numeric)
add_subdirectory(strings)
add_subdirectory(synchronization)
add_subdirectory(time)
add_subdirectory(types)
add_subdirectory(utility)
46 changes: 46 additions & 0 deletions absl/algorithm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#
# Copyright 2017 The Abseil Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

file(GLOB ALGORITHM_PUBLIC_HEADERS "*.h")
file(GLOB ALGORITHM_INTERNAL_HEADERS "internal/*.h")


install(FILES ${ALGORITHM_PUBLIC_HEADERS}
DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}/absl/algorithm)
install(FILES ${ALGORITHM_INTERNAL_HEADERS}
DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}/absl/algorithm/internal)


#
## TESTS
#

# test algorithm_test
set(ALGORITHM_TEST_SRC "algorithm_test.cc")
add_executable(algorithm_test_bin ${ALGORITHM_TEST_SRC})
target_compile_options(algorithm_test_bin PRIVATE ${ABSL_COMPILE_CXXFLAGS})
target_link_libraries(algorithm_test_bin ${ABSL_TEST_COMMON_LIBRARIES})

add_test(algorithm_test_test algorithm_test_bin)


# test container_test
set(CONTAINER_TEST_SRC "container_test.cc")
add_executable(container_test_bin ${CONTAINER_TEST_SRC})
target_compile_options(container_test_bin PRIVATE ${ABSL_COMPILE_CXXFLAGS})
target_link_libraries(container_test_bin ${ABSL_TEST_COMMON_LIBRARIES})

add_test(container_test_test container_test_bin)

0 comments on commit 02d7a3d

Please sign in to comment.