Skip to content

Commit

Permalink
Refs #6475. Modify build policy to superbuild. (eProsima#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
julionce authored and BorjaOuterelo committed Oct 3, 2019
1 parent 9253488 commit 9837d6c
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 33 deletions.
73 changes: 40 additions & 33 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
###############################################################################
cmake_minimum_required(VERSION 3.5.0 FATAL_ERROR)

###############################################################################
# Build options
###############################################################################
option(UCDR_SUPERBUILD "Enable superbuild compilation." ON)
option(UCDR_BUILD_TESTS "Build tests" OFF)
option(UCDR_BUILD_EXAMPLES "Build examples" OFF)
option(BUILD_SHARED_LIBS "Control shared/static library building." OFF)

# Set CMAKE_BUILD_TYPE to Release by default.
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Release' as none was specified.")
Expand All @@ -29,15 +37,36 @@ endif()
###############################################################################
# Product information
###############################################################################
cmake_policy(SET CMP0048 NEW)
project(microcdr VERSION "1.1.0" LANGUAGES C)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
if(NOT UCDR_SUPERBUILD)
project(microcdr VERSION "1.1.0" LANGUAGES C)
else()
project(ucdr_superbuild NONE)
include(${PROJECT_SOURCE_DIR}/cmake/SuperBuild.cmake)
return()
endif()

###############################################################################
# Build options
# Config
###############################################################################
option(UCDR_BUILD_TESTS "Build tests" OFF)
option(UCDR_BUILD_EXAMPLES "Build examples" OFF)
option(BUILD_SHARED_LIBS "Control shared/static library building." OFF)
# Install path
include(GNUInstallDirs)
set(BIN_INSTALL_DIR ${CMAKE_INSTALL_BINDIR} CACHE PATH "Installation directory for binaries")
set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE PATH "Installation directory for C headers")
set(LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR} CACHE PATH "Installation directory for libraries")
set(DATA_INSTALL_DIR ${CMAKE_INSTALL_DATADIR} CACHE PATH "Installation directory for data")
if(WIN32)
set(LICENSE_INSTALL_DIR . CACHE PATH "Installation directory for licenses")
else()
set(LICENSE_INSTALL_DIR ${DATA_INSTALL_DIR}/${PROJECT_NAME} CACHE PATH "Installation directory for licenses")
endif()

set(CONFIG_BIG_ENDIANNESS OFF CACHE BOOL "Set the machine endianness to big endianness (default: little endianness).")
if(CONFIG_BIG_ENDIANNESS)
set(CONFIG_MACHINE_ENDIANNESS UCDR_BIG_ENDIANNESS) #big
else()
set(CONFIG_MACHINE_ENDIANNESS UCDR_LITTLE_ENDIANNESS) #little
endif()

###############################################################################
# Check MSVC architecture
Expand Down Expand Up @@ -101,33 +130,6 @@ target_include_directories(${PROJECT_NAME}
$<INSTALL_INTERFACE:include>
)

###############################################################################
# Config
###############################################################################
# Install path
include(GNUInstallDirs)
set(BIN_INSTALL_DIR ${CMAKE_INSTALL_BINDIR} CACHE PATH "Installation directory for binaries")
set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE PATH "Installation directory for C headers")
set(LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR} CACHE PATH "Installation directory for libraries")
set(DATA_INSTALL_DIR ${CMAKE_INSTALL_DATADIR} CACHE PATH "Installation directory for data")
if(WIN32)
set(LICENSE_INSTALL_DIR . CACHE PATH "Installation directory for licenses")
else()
set(LICENSE_INSTALL_DIR ${DATA_INSTALL_DIR}/${PROJECT_NAME} CACHE PATH "Installation directory for licenses")
endif()

# Config.h
set(CONFIG_BIG_ENDIANNESS OFF CACHE BOOL "Set the machine endianness to big endianness (by default is little endianness)")
if(CONFIG_BIG_ENDIANNESS)
set(CONFIG_MACHINE_ENDIANNESS UCDR_BIG_ENDIANNESS) #big
else()
set(CONFIG_MACHINE_ENDIANNESS UCDR_LITTLE_ENDIANNESS) #little
endif()

configure_file(${PROJECT_SOURCE_DIR}/include/ucdr/config.h.in
${PROJECT_BINARY_DIR}/include/ucdr/config.h
)

###############################################################################
# Examples
###############################################################################
Expand Down Expand Up @@ -174,6 +176,11 @@ install(
PATTERN "*.h"
)

# Generate config.h
configure_file(${PROJECT_SOURCE_DIR}/include/ucdr/config.h.in
${PROJECT_BINARY_DIR}/include/ucdr/config.h
)

# Install config.h
install(
FILES
Expand Down
64 changes: 64 additions & 0 deletions cmake/SuperBuild.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright 2019 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.

include(ExternalProject)

unset(_deps)

if(UCDR_BUILD_TESTS)
unset(googletest_DIR CACHE)
enable_language(CXX)
find_package(GTest QUIET)
find_package(GMock QUIET)
if(NOT GTest_FOUND OR NOT GMock_FOUND)
unset(GTEST_ROOT CACHE)
unset(GMOCK_ROOT CACHE)
ExternalProject_Add(googletest
GIT_REPOSITORY
https://github.com/google/googletest.git
GIT_TAG
2fe3bd994b3189899d93f1d5a881e725e046fdc2
PREFIX
${PROJECT_BINARY_DIR}/googletest
INSTALL_DIR
${PROJECT_BINARY_DIR}/temp_install
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
$<$<PLATFORM_ID:Windows>:-Dgtest_force_shared_crt:BOOL=ON>
BUILD_COMMAND
COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config Release --target install
COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config Debug --target install
INSTALL_COMMAND
""
)
set(GTEST_ROOT ${PROJECT_BINARY_DIR}/temp_install CACHE PATH "" FORCE)
set(GMOCK_ROOT ${PROJECT_BINARY_DIR}/temp_install CACHE PATH "" FORCE)
list(APPEND _deps googletest)
endif()
endif()

# Client project.
ExternalProject_Add(ucdr
SOURCE_DIR
${PROJECT_SOURCE_DIR}
BINARY_DIR
${CMAKE_CURRENT_BINARY_DIR}
CMAKE_CACHE_ARGS
-DUCDR_SUPERBUILD:BOOL=OFF
INSTALL_COMMAND
""
DEPENDS
${_deps}
)

0 comments on commit 9837d6c

Please sign in to comment.