Skip to content

Commit

Permalink
Created cmake config file
Browse files Browse the repository at this point in the history
  • Loading branch information
jlblancoc committed Oct 1, 2015
1 parent b31f6bc commit ca10479
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 31 deletions.
36 changes: 31 additions & 5 deletions CMakeLists.txt
Expand Up @@ -10,6 +10,22 @@ project(SRBA_ALL)
# 1. Set-up CMake and find pkgs
# =====================================
SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS 1)

# Declare lib version:
SET(CMAKE_SRBA_VERSION_NUMBER_MAJOR 1)
SET(CMAKE_SRBA_VERSION_NUMBER_MINOR 4)
SET(CMAKE_SRBA_VERSION_NUMBER_PATCH 0)
SET(CMAKE_SRBA_FULL_VERSION "${CMAKE_SRBA_VERSION_NUMBER_MAJOR}.${CMAKE_SRBA_VERSION_NUMBER_MINOR}.${CMAKE_SRBA_VERSION_NUMBER_PATCH}")

IF (CMAKE_VERSION VERSION_GREATER 2.8.0)
SET(ENABLE_SOLUTION_FOLDERS ON CACHE BOOL "Group projects under virtual folders of the compiler IDE (e.g. VisualStudio)")
MARK_AS_ADVANCED(ENABLE_SOLUTION_FOLDERS)
ENDIF ()
if (ENABLE_SOLUTION_FOLDERS)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMakeTargets")
endif ()

if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW) # Required by CMake 2.7+
endif(COMMAND cmake_policy)
Expand All @@ -31,7 +47,21 @@ if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" OR CMAKE_COMPILER_IS_GNUCXX)
endif()

# =====================================
# 2. Declare targets
# 2. Install, config files, etc.
# =====================================

# Generate CMake config file for usage without "make install"
# ---------------------------------------------------------------
SET(THE_INCLUDE_DIRECTORIES "${SRBA_ALL_SOURCE_DIR}/include")
CONFIGURE_FILE(
"${SRBA_ALL_SOURCE_DIR}/SRBA-config.cmake.in"
"${SRBA_ALL_BINARY_DIR}/SRBA-config.cmake" @ONLY IMMEDIATE )

SET(SRBA_DIR ${SRBA_ALL_BINARY_DIR} CACHE PATH "Directory for SRBA-config.cmake" )
MARK_AS_ADVANCED(SRBA_DIR)

# =====================================
# 3. Declare targets
# =====================================
# C++ Library: It's hdr only, so we don't need to compile it!
include_directories("${SRBA_ALL_SOURCE_DIR}/include/")
Expand All @@ -45,7 +75,3 @@ add_subdirectory(examples)
add_subdirectory(tests)


# =====================================
# 3. Install, config files, etc.
# =====================================

34 changes: 34 additions & 0 deletions SRBA-config.cmake.in
@@ -0,0 +1,34 @@
# =========================================================================
# libSRBA CMake configuration file
#
# ** File generated automatically, do not modify **
#
# Usage from an external project:
# In your CMakeLists.txt, add these lines:
#
# FIND_PACKAGE( SRBA REQUIRED )
# INCLUDE_DIRECTORIES(${SRBA_INCLUDE_DIRS})
#
# This file will define the following variables:
# - SRBA_INCLUDE_DIRS: The list of include directories
# - SRBA_VERSION: The SRBA version (e.g. "1.0.0").
# - SRBA_VERSION_{MAJOR,MINOR,PATCH}: 3 variables for the version parts
#
# =========================================================================

# SRBA version numbers:
SET(SRBA_VERSION @CMAKE_SRBA_FULL_VERSION@)
SET(SRBA_VERSION_MAJOR @CMAKE_SRBA_VERSION_NUMBER_MAJOR@)
SET(SRBA_VERSION_MINOR @CMAKE_SRBA_VERSION_NUMBER_MINOR@)
SET(SRBA_VERSION_PATCH @CMAKE_SRBA_VERSION_NUMBER_PATCH@)

# Extract the directory where *this* file has been installed (determined at cmake run-time)
get_filename_component(THIS_SRBA_CONFIG_PATH "${CMAKE_CURRENT_LIST_FILE}" PATH)

SET(SRBA_INCLUDE_DIRS "@THE_INCLUDE_DIRECTORIES@") # SRBA include directories

# Compiler flags:
if(MSVC)
# For MSVC to avoid the C1128 error about too large object files:
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
endif(MSVC)
8 changes: 7 additions & 1 deletion apps/srba-slam/CMakeLists.txt
Expand Up @@ -5,6 +5,8 @@
PROJECT(srba_slam)

FIND_PACKAGE(MRPT REQUIRED gui vision)
FIND_PACKAGE(SRBA REQUIRED)
INCLUDE_DIRECTORIES(${SRBA_INCLUDE_DIRS})

# ---------------------------------------------
# TARGET:
Expand Down Expand Up @@ -34,10 +36,14 @@ IF(ENABLE_PRECOMPILED_HDRS AND MSVC)
set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/srba-slam_main.cpp" PROPERTIES COMPILE_FLAGS "/Y-")
ENDIF(ENABLE_PRECOMPILED_HDRS AND MSVC)

SET(TMP_TARGET_NAME "srba-slam")
SET(TMP_TARGET_NAME srba-slam)

# Add the required libraries for linking:
TARGET_LINK_LIBRARIES(${TMP_TARGET_NAME} ${MRPT_LIBS})

if(ENABLE_SOLUTION_FOLDERS)
set_target_properties(${TMP_TARGET_NAME} PROPERTIES FOLDER "Apps")
endif(ENABLE_SOLUTION_FOLDERS)

#DeclareAppForInstall(${TMP_TARGET_NAME})

28 changes: 6 additions & 22 deletions examples/CMakeLists.txt
@@ -1,26 +1,16 @@
PROJECT(srba-tutorials)

CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW) # Required by CMake 2.7+
if(POLICY CMP0043)
cmake_policy(SET CMP0043 OLD) # Ignore COMPILE_DEFINITIONS_<Config> properties.
endif()
endif(COMMAND cmake_policy)

# --------------------------------------------------------------------------
# The list of "libs" which can be included can be found in:
# http://www.mrpt.org/Libraries
# The dependencies of a library are automatically added, so you only
# need to specify the top-most libraries your code depend on.
# --------------------------------------------------------------------------
FIND_PACKAGE(MRPT REQUIRED gui graphslam)

if(MSVC)
# For MSVC to avoid the C1128 error about too large object files:
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /bigobj")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /bigobj")
endif(MSVC)
FIND_PACKAGE(SRBA REQUIRED)
INCLUDE_DIRECTORIES(${SRBA_INCLUDE_DIRS})

# Set optimized building in GCC:
IF(CMAKE_COMPILER_IS_GNUCXX AND NOT CMAKE_BUILD_TYPE MATCHES "Debug")
Expand All @@ -32,17 +22,11 @@ MACRO(DEFINE_TUTORIAL_EXECUTABLE name extradeps)
ADD_EXECUTABLE(${name} ${name}.cpp)
TARGET_LINK_LIBRARIES(${name} ${MRPT_LIBS}) # Add the required libraries for linking:

# -------------------------------------------------------------------------
# This part can be removed if you are compiling this program outside of
# the MRPT tree:
# -------------------------------------------------------------------------
IF("${CMAKE_PROJECT_NAME}" STREQUAL "MRPT") # Fails if build outside of MRPT project.
DeclareAppDependencies(${name} mrpt-srba mrpt-gui ${extradeps}) # Dependencies
ENDIF("${CMAKE_PROJECT_NAME}" STREQUAL "MRPT")
# -------------------------------------------------------------------------
if(ENABLE_SOLUTION_FOLDERS)
set_target_properties(${name} PROPERTIES FOLDER "Examples")
endif(ENABLE_SOLUTION_FOLDERS)
ENDMACRO(DEFINE_TUTORIAL_EXECUTABLE)


# --------------------------------------------------------------------
# List of tutorials/examples:
# --------------------------------------------------------------------
Expand Down
13 changes: 10 additions & 3 deletions tests/CMakeLists.txt
Expand Up @@ -4,8 +4,11 @@
# --------------------------------------------------------------
PROJECT(tests)

# Fix a "bug" in VS11 (MSVC 2012):
FIND_PACKAGE(SRBA REQUIRED)
INCLUDE_DIRECTORIES(${SRBA_INCLUDE_DIRS})

if(MSVC)
# Fix a "bug" in VS11 (MSVC 2012):
add_definitions(-D_VARIADIC_MAX=10)
endif(MSVC)

Expand All @@ -26,9 +29,13 @@ SET(lstfiles
ADD_EXECUTABLE( test_srba ${lstfiles})
TARGET_LINK_LIBRARIES(test_srba ${MRPT_LIBS})

cmake_policy(SET CMP0003 NEW) # Required by CMake 2.7+
if(POLICY CMP0037)
cmake_policy(SET CMP0037 OLD) # Allow creating target named "test"
endif()

# Run it:
GET_TARGET_PROPERTY(GENERATED_EXE test_srba LOCATION)
ADD_CUSTOM_TARGET(test COMMAND "${GENERATED_EXE}" "${SRBA_ALL_SOURCE_DIR}")
ADD_CUSTOM_TARGET(test COMMAND "$<TARGET_FILE:test_srba>" "${SRBA_ALL_SOURCE_DIR}")
ADD_DEPENDENCIES(test test_srba)

if(ENABLE_SOLUTION_FOLDERS)
Expand Down

0 comments on commit ca10479

Please sign in to comment.