forked from eProsima/Fast-DDS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Squashed 'cmake/common/' content from commit 90161276
git-subtree-dir: cmake/common git-subtree-split: 901612761486a226bee28011b9de2ed563600ff1
- Loading branch information
0 parents
commit 7394185
Showing
3 changed files
with
300 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). | ||
# | ||
# 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. | ||
|
||
macro(check_stdcxx) | ||
# Check C++11 | ||
include(CheckCXXCompilerFlag) | ||
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG OR | ||
CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
check_cxx_compiler_flag(-std=c++11 SUPPORTS_CXX11) | ||
if(SUPPORTS_CXX11) | ||
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-std=c++11>) | ||
set(HAVE_CXX11 1) | ||
set(HAVE_CXX0X 1) | ||
else() | ||
set(HAVE_CXX11 0) | ||
check_cxx_compiler_flag(-std=c++0x SUPPORTS_CXX0X) | ||
if(SUPPORTS_CXX0X) | ||
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-std=c++0x>) | ||
set(HAVE_CXX0X 1) | ||
else() | ||
set(HAVE_CXX0X 0) | ||
endif() | ||
endif() | ||
elseif(MSVC OR MSVC_IDE) | ||
set(HAVE_CXX11 1) | ||
set(HAVE_CXX0X 1) | ||
else() | ||
set(HAVE_CXX11 0) | ||
set(HAVE_CXX0X 0) | ||
endif() | ||
endmacro() | ||
|
||
macro(check_compile_feature) | ||
# Check constexpr | ||
list(FIND CMAKE_CXX_COMPILE_FEATURES "cxx_constexpr" CXX_CONSTEXPR_SUPPORTED) | ||
if(${CXX_CONSTEXPR_SUPPORTED} GREATER -1) | ||
set(HAVE_CXX_CONSTEXPR 1) | ||
else() | ||
set(HAVE_CXX_CONSTEXPR 0) | ||
endif() | ||
endmacro() | ||
|
||
macro(check_endianness) | ||
# Test endianness | ||
include(TestBigEndian) | ||
test_big_endian(BIG_ENDIAN) | ||
set(__BIG_ENDIAN__ ${BIG_ENDIAN}) | ||
endmacro() | ||
|
||
macro(check_msvc_arch) | ||
if(MSVC11) | ||
if(CMAKE_CL_64) | ||
set(MSVC_ARCH "x64Win64VS2012") | ||
else() | ||
set(MSVC_ARCH "i86Win32VS2012") | ||
endif() | ||
elseif(MSVC12) | ||
if(CMAKE_CL_64) | ||
set(MSVC_ARCH "x64Win64VS2013") | ||
else() | ||
set(MSVC_ARCH "i86Win32VS2013") | ||
endif() | ||
elseif(MSVC14) | ||
if(CMAKE_CL_64) | ||
set(MSVC_ARCH "x64Win64VS2015") | ||
else() | ||
set(MSVC_ARCH "i86Win32VS2015") | ||
endif() | ||
else() | ||
message(FATAL_ERROR "Not supported version of Visual Studio") | ||
endif() | ||
endmacro() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). | ||
# | ||
# 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. | ||
|
||
macro(eprosima_find_package package) | ||
|
||
if(NOT ${package}_FOUND AND NOT (EPROSIMA_INSTALLER AND (MSVC OR MSVC_IDE))) | ||
|
||
# Parse arguments. | ||
set(options REQUIRED) | ||
cmake_parse_arguments(FIND "${options}" "" "" ${ARGN}) | ||
|
||
option(THIRDPARTY_${package} "Activate the use of internal thirdparty ${package}" OFF) | ||
|
||
find_package(${package} QUIET) | ||
if(NOT ${package}_FOUND AND (THIRDPARTY OR THIRDPARTY_${package})) | ||
set(SUBDIRECTORY_EXIST TRUE) | ||
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/thirdparty/${package}/CMakeLists.txt") | ||
execute_process( | ||
COMMAND git submodule update --recursive --init "thirdparty/${package}" | ||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} | ||
RESULT_VARIABLE EXECUTE_RESULT | ||
) | ||
if(NOT EXECUTE_RESULT EQUAL 0) | ||
set(SUBDIRECTORY_EXIST FALSE) | ||
message(WARNING "Cannot configure Git submodule ${package}") | ||
endif() | ||
endif() | ||
|
||
if(SUBDIRECTORY_EXIST) | ||
add_subdirectory(${PROJECT_SOURCE_DIR}/thirdparty/${package}) | ||
set(${package}_FOUND TRUE) | ||
if(NOT IS_TOP_LEVEL) | ||
set(${package}_FOUND TRUE PARENT_SCOPE) | ||
endif() | ||
endif() | ||
endif() | ||
|
||
if(${package}_FOUND) | ||
message(STATUS "${package} library found...") | ||
elseif(${FIND_REQUIRED}) | ||
message(FATAL_ERROR "${package} library not found...") | ||
else() | ||
message(STATUS "${package} library not found...") | ||
endif() | ||
endif() | ||
endmacro() | ||
|
||
macro(eprosima_find_thirdparty package thirdparty_name) | ||
if(NOT (EPROSIMA_INSTALLER AND (MSVC OR MSVC_IDE))) | ||
|
||
option(THIRDPARTY_${package} "Activate the use of internal thirdparty ${package}" OFF) | ||
|
||
if(THIRDPARTY OR THIRDPARTY_${package}) | ||
execute_process( | ||
COMMAND git submodule update --recursive --init "thirdparty/${thirdparty_name}" | ||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} | ||
RESULT_VARIABLE EXECUTE_RESULT | ||
) | ||
|
||
if(EXECUTE_RESULT EQUAL 0) | ||
else() | ||
message(FATAL_ERROR "Cannot configure Git submodule ${package}") | ||
endif() | ||
endif() | ||
|
||
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${PROJECT_SOURCE_DIR}/thirdparty/${thirdparty_name}) | ||
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${PROJECT_SOURCE_DIR}/thirdparty/${thirdparty_name}/${thirdparty_name}) | ||
find_package(${package} REQUIRED QUIET) | ||
|
||
endif() | ||
endmacro() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
# Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). | ||
# | ||
# 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. | ||
|
||
option(GTEST_INDIVIDUAL "Activate the execution of GTest tests" OFF) | ||
|
||
macro(check_gtest) | ||
if(NOT GTEST_FOUND) | ||
if(WIN32) | ||
option(EPROSIMA_GTEST "Activate special set of GTEST_ROOT" OFF) | ||
if(EPROSIMA_BUILD) | ||
set(EPROSIMA_GTEST ON) | ||
endif() | ||
endif() | ||
|
||
# Find package GTest | ||
if(WIN32 AND EPROSIMA_GTEST) | ||
if(NOT GTEST_ROOT) | ||
set(GTEST_ROOT_ $ENV{GTEST_ROOT}) | ||
if(GTEST_ROOT_) | ||
file(TO_CMAKE_PATH "${GTEST_ROOT_}/${MSVC_ARCH}" GTEST_ROOT) | ||
endif() | ||
else() | ||
file(TO_CMAKE_PATH "${GTEST_ROOT}/${MSVC_ARCH}" GTEST_ROOT) | ||
endif() | ||
endif() | ||
find_package(GTest) | ||
|
||
if(GTEST_FOUND) | ||
find_package(Threads REQUIRED) | ||
set(GTEST_LIBRARIES ${GTEST_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) | ||
set(GTEST_BOTH_LIBRARIES ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) | ||
endif() | ||
endif() | ||
endmacro() | ||
|
||
macro(check_gmock) | ||
if(NOT GMOCK_FOUND) | ||
if(WIN32) | ||
option(EPROSIMA_GMOCK "Activate special set of GMOCK_ROOT" OFF) | ||
if(EPROSIMA_BUILD) | ||
set(EPROSIMA_GMOCK ON) | ||
endif() | ||
endif() | ||
|
||
# Find package GMock | ||
if(WIN32 AND EPROSIMA_GMOCK) | ||
if(NOT GMOCK_ROOT) | ||
set(GMOCK_ROOT_ $ENV{GMOCK_ROOT}) | ||
if(GMOCK_ROOT_) | ||
file(TO_CMAKE_PATH "${GMOCK_ROOT_}/${MSVC_ARCH}" GMOCK_ROOT) | ||
endif() | ||
else() | ||
file(TO_CMAKE_PATH "${GMOCK_ROOT}/${MSVC_ARCH}" GMOCK_ROOT) | ||
endif() | ||
endif() | ||
find_package(GMock) | ||
|
||
if(GMOCK_FOUND) | ||
find_package(Threads REQUIRED) | ||
set(GMOCK_LIBRARIES ${GMOCK_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) | ||
set(GMOCK_BOTH_LIBRARIES ${GMOCK_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) | ||
endif() | ||
endif() | ||
endmacro() | ||
|
||
macro(add_gtest test) | ||
# Parse arguments | ||
set(multiValueArgs SOURCES ENVIRONMENTS DEPENDENCIES) | ||
cmake_parse_arguments(GTEST "" "" "${multiValueArgs}" ${ARGN}) | ||
|
||
if(GTEST_INDIVIDUAL) | ||
foreach(GTEST_SOURCE_FILE ${GTEST_SOURCES}) | ||
file(STRINGS ${GTEST_SOURCE_FILE} GTEST_NAMES REGEX ^TEST) | ||
foreach(GTEST_NAME ${GTEST_NAMES}) | ||
string(REGEX REPLACE ["\) \(,"] ";" GTEST_NAME ${GTEST_NAME}) | ||
list(GET GTEST_NAME 1 GTEST_GROUP_NAME) | ||
list(GET GTEST_NAME 3 GTEST_NAME) | ||
add_test(NAME ${GTEST_GROUP_NAME}.${GTEST_NAME} | ||
COMMAND ${test} | ||
--gtest_filter=${GTEST_GROUP_NAME}.${GTEST_NAME}) | ||
|
||
# Add environment | ||
if(WIN32) | ||
set(WIN_PATH "$ENV{PATH}") | ||
get_target_property(LINK_LIBRARIES_ ${test} LINK_LIBRARIES) | ||
if(NOT "${LINK_LIBRARIES_}" STREQUAL "LINK_LIBRARIES_-NOTFOUND") | ||
foreach(LIBRARY_LINKED ${LINK_LIBRARIES_}) | ||
if(TARGET ${LIBRARY_LINKED}) | ||
set(WIN_PATH "$<TARGET_FILE_DIR:${LIBRARY_LINKED}>;${WIN_PATH}") | ||
endif() | ||
endforeach() | ||
endif() | ||
string(REPLACE ";" "\\;" WIN_PATH "${WIN_PATH}") | ||
set_tests_properties(${test} PROPERTIES ENVIRONMENT "PATH=${WIN_PATH}") | ||
endif() | ||
|
||
foreach(property ${GTEST_ENVIRONMENTS}) | ||
set_property(TEST ${GTEST_GROUP_NAME}.${GTEST_NAME} APPEND PROPERTY ENVIRONMENT "${property}") | ||
endforeach() | ||
endforeach() | ||
endforeach() | ||
else() | ||
add_test(NAME ${test} COMMAND ${test}) | ||
|
||
# Add environment | ||
if(WIN32) | ||
set(WIN_PATH "$ENV{PATH}") | ||
get_target_property(LINK_LIBRARIES_ ${test} LINK_LIBRARIES) | ||
if(NOT "${LINK_LIBRARIES_}" STREQUAL "LINK_LIBRARIES_-NOTFOUND") | ||
foreach(LIBRARY_LINKED ${LINK_LIBRARIES_}) | ||
if(TARGET ${LIBRARY_LINKED}) | ||
set(WIN_PATH "$<TARGET_FILE_DIR:${LIBRARY_LINKED}>;${WIN_PATH}") | ||
endif() | ||
endforeach() | ||
endif() | ||
string(REPLACE ";" "\\;" WIN_PATH "${WIN_PATH}") | ||
set_tests_properties(${test} PROPERTIES ENVIRONMENT "PATH=${WIN_PATH}") | ||
endif() | ||
|
||
foreach(property ${GTEST_ENVIRONMENTS}) | ||
set_property(TEST ${test} APPEND PROPERTY ENVIRONMENT "${property}") | ||
endforeach() | ||
endif() | ||
endmacro() |