commit 064b0e4c74ab1e9585fc2a67e1e61e4571c9861f
parent d2cc6eec8ce52a8665b553579b14a6d2240c0dc8
Author: vaplv <vaplv@free.fr>
Date: Sat, 8 Feb 2014 15:11:02 +0100
Improve the project/config cmake script
Diffstat:
3 files changed, 57 insertions(+), 32 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -6,12 +6,12 @@ if(NOT CMAKE_COMPILER_IS_GNUCC)
message(FATAL_ERROR "Unsupported compiler")
endif(NOT CMAKE_COMPILER_IS_GNUCC)
+################################################################################
+# Some cmake variable
+################################################################################
set(CMAKE_CURRENT_SOURCE_DIR ${PROJECT_SOURCE_DIR}/../src)
set(CMAKE_DEBUG_POSTFIX "-dbg")
-find_package(Threads)
-find_package(OpenMP)
-
################################################################################
# Setup compile flags/parameters
################################################################################
@@ -34,24 +34,18 @@ set(CMAKE_C_FLAGS "${C_FLAGS} ${C_FLAGS_UNIX} ${C_FLAGS_WARN} ${C_FLAGS_LINK}")
set(CMAKE_C_FLAGS_DEBUG "-g -DDEBUG")
set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
+################################################################################
+# Check dependencies
+################################################################################
+find_package(Threads REQUIRED)
+find_package(OpenMP)
+
if(CMAKE_USE_PTHREADS_INIT)
add_definitions(-DRSYS_USE_PTHREADS)
endif(CMAKE_USE_PTHREADS_INIT)
################################################################################
-# Helper macros
-################################################################################
-# Prepend each file in the `_files' list by `_path'
-macro(prepend_path _files _path)
- unset(_tmp)
- foreach(f ${${_files}})
- list(APPEND _tmp ${_path}/${f})
- endforeach(f)
- set(${_files} ${_tmp})
-endmacro(prepend_path)
-
-################################################################################
-# Define targets
+# Configure and define targets
################################################################################
set(VERSION_MAJOR 0)
set(VERSION_MINOR 0)
@@ -60,9 +54,11 @@ set(RSYS_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
message(STATUS "Current library version: ${RSYS_VERSION}")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/rsys_version.h.in
- ${CMAKE_CURRENT_SOURCE_DIR}/rsys_version.h)
+ ${CMAKE_CURRENT_SOURCE_DIR}/rsys_version.h @ONLY)
+configure_file(${PROJECT_SOURCE_DIR}/config/rsys-config.cmake.in
+ ${PROJECT_SOURCE_DIR}/config/rsys-config.cmake @ONLY)
configure_file(${PROJECT_SOURCE_DIR}/config/rsys-config-version.cmake.in
- ${PROJECT_SOURCE_DIR}/config/rsys-config-version.cmake)
+ ${PROJECT_SOURCE_DIR}/config/rsys-config-version.cmake @ONLY)
set(RSYS_FILES_CMAKE
rsys-config.cmake
@@ -75,7 +71,6 @@ set(RSYS_FILES_SRC
pthread/pthread_condition.c
pthread/pthread_mutex.c)
set(RSYS_FILES_INC_COMMON
- atomic.h
clock_time.h
free_list.h
image.h
@@ -89,6 +84,14 @@ set(RSYS_FILES_INC_COMMON
set(RSYS_FILES_INC_EDIT ${RSYS_FILES_INC_COMMON} rsys_version.h.in)
set(RSYS_FILES_INC_INSTALL ${RSYS_FILES_INC_COMMON} rsys_version.h)
+# Prepend each file in the `_files' list by `_path'
+macro(prepend_path _files _path)
+ unset(_tmp)
+ foreach(f ${${_files}})
+ list(APPEND _tmp ${_path}/${f})
+ endforeach(f)
+ set(${_files} ${_tmp})
+endmacro(prepend_path)
prepend_path(RSYS_FILES_CMAKE ${PROJECT_SOURCE_DIR}/config)
prepend_path(RSYS_FILES_SRC ${CMAKE_CURRENT_SOURCE_DIR})
prepend_path(RSYS_FILES_INC_EDIT ${CMAKE_CURRENT_SOURCE_DIR})
@@ -136,8 +139,9 @@ if(NOT OPENMP_FOUND)
else(NOT OPENMP_FOUND)
new_test(test_condition rsys)
new_test(test_mutex rsys)
- set_target_properties(test_mutex test_condition PROPERTIES COMPILE_FLAGS ${OpenMP_C_FLAGS})
- set_target_properties(test_mutex test_condition PROPERTIES LINK_FLAGS ${OpenMP_C_FLAGS})
+ set_target_properties(test_mutex test_condition PROPERTIES
+ COMPILE_FLAGS ${OpenMP_C_FLAGS}
+ LINK_FLAGS ${OpenMP_C_FLAGS})
endif(NOT OPENMP_FOUND)
################################################################################
diff --git a/cmake/config/rsys-config.cmake b/cmake/config/rsys-config.cmake
@@ -1,11 +0,0 @@
-# Try to find the rsys devel. Once done this will define:
-# - RSYS_FOUND - system has foundation
-# - RSYS_INCLUDE_DIR - the foundation include directory
-# - RSYS_LIBRARIES - Link these to use foundation
-include(FindPackageHandleStandardArgs)
-find_path(RSYS_INCLUDE_DIR rsys/rsys.h)
-find_library(RSYS_LIBRARIES rsys)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(rsys DEFAULT_MSG
- RSYS_LIBRARIES
- RSYS_INCLUDE_DIR)
-
diff --git a/cmake/config/rsys-config.cmake.in b/cmake/config/rsys-config.cmake.in
@@ -0,0 +1,32 @@
+# Try to find the rsys devel. Once done this will define:
+# - RSYS_FOUND - system has rsys
+# - RSYS_INCLUDE_DIRS - the rsys include directory
+# - RSYS_LIBRARIES - Link these to use rsys
+# - RSYS_LIBRARIES_DEBUG - Link these to use rsys in debug
+include(FindPackageHandleStandardArgs)
+
+find_path(RSYS_INCLUDE_DIRS rsys/rsys.h)
+find_library(RSYS_LIBRARIES rsys)
+find_library(RSYS_LIBRARIES_DEBUG rsys@CMAKE_DEBUG_POSTFIX@)
+
+if(RSYS_FIND_COMPONENTS)
+ set(_rsys RSYS)
+elseif(Rsys_FIND_COMPONENTS)
+ set(_rsys Rsys)
+elseif(RSys_FIND_COMPONENTS)
+ set(_rsys RSys)
+else(RSYS_FIND_COMPONENTS)
+ set(_rsys rsys)
+endif(RSYS_FIND_COMPONENTS)
+
+foreach(_cmp ${${_rsys}_FIND_COMPONENTS})
+ if(${_rsys}_FIND_REQUIRED_${_cmp})
+ list(APPEND _rsys_required_components ${_cmp})
+ endif(${_rsys}_FIND_REQUIRED_${_cmp})
+endforeach(_cmp)
+
+if(NOT _rsys_required_components)
+ list(APPEND _rsys_required_components ${RSYS_LIBRARIES} ${RSYS_INCLUDE_DIRS})
+endif(NOT _rsys_required_components)
+
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(RSys DEFAULT_MSG ${_rsys_required_components})