Use CMake variables for sbin and etc files
[platform/core/api/libteec.git] / CMakeLists.txt
1 #
2 #  Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
3 #
4 #  Contact: Krzysztof Dynowski <k.dynowski@samsung.com>
5 #
6 #  Licensed under the Apache License, Version 2.0 (the "License");
7 #  you may not use this file except in compliance with the License.
8 #  You may obtain a copy of the License at
9 #
10 #      http://www.apache.org/licenses/LICENSE-2.0
11 #
12 #  Unless required by applicable law or agreed to in writing, software
13 #  distributed under the License is distributed on an "AS IS" BASIS,
14 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 #  See the License for the specific language governing permissions and
16 #  limitations under the License
17 #
18 #
19 # @file CMakeLists.txt
20 # @author Krzysztof Dynowski <k.dynowski@samsung.com>
21 #
22
23 CMAKE_MINIMUM_REQUIRED (VERSION 2.6)
24
25 PROJECT(tef-libteec)
26 SET(VERSION "0.0.1")
27
28 INCLUDE(FindPkgConfig)
29 INCLUDE(GNUInstallDirs)  # CMAKE_INSTALL_xxx
30
31 ## Compiler flags, depending on the build type #################################
32 IF(NOT CMAKE_BUILD_TYPE)
33     SET(CMAKE_BUILD_TYPE "DEBUG")
34 ENDIF(NOT CMAKE_BUILD_TYPE)
35
36 ## Print build information #####################################################
37 MESSAGE(STATUS "-------------------------------------------------")
38 MESSAGE(STATUS "Compiler:          " ${CMAKE_C_COMPILER_ID})
39 MESSAGE(STATUS "Compiler version:  " ${CMAKE_C_COMPILER_VERSION})
40 MESSAGE(STATUS "Build type:        " ${CMAKE_BUILD_TYPE})
41 MESSAGE(STATUS "-------------------------------------------------")
42
43 SET(CMAKE_C_FLAGS_DEBUG        "-std=c11 -O0 -ggdb -Wp,-U_FORTIFY_SOURCE")
44 SET(CMAKE_C_FLAGS_RELEASE      "-std=c11 -O2 -DNDEBUG")
45
46 ADD_DEFINITIONS("-fPIC")   # Position Independent Code
47 ADD_DEFINITIONS("-Werror") # Make all warnings into errors
48 ADD_DEFINITIONS("-Wall")   # Generate all warnings
49 ADD_DEFINITIONS("-Wextra") # Generate even more extra warnings
50 ADD_DEFINITIONS("-pedantic") # Be pedantic
51 ADD_DEFINITIONS("-pedantic-errors") # Make pedantic warnings into errors
52
53
54 SET(TEF_API_ROOT_PATH ${PROJECT_SOURCE_DIR})
55 SET(TEF_API_PATH $(TEF_API_ROOT_PATH)/api)
56 SET(TEF_TARGET "teec")
57 SET(TEF_PC tef-libteec.pc)
58
59 # force 32-bit mode
60 IF(DEFINED FORCE_32BIT)
61     SET(CMAKE_C_FLAGS -m32)
62 ENDIF()
63
64 INCLUDE_DIRECTORIES(
65     ${TEF_API_PATH}
66 )
67
68 FILE(GLOB TEF_API_HEADERS api/tef/*.h)
69 FILE(GLOB TEF_API_SOURCES src/*.c src/simulator/*.c src/optee/*.c)
70
71 ADD_LIBRARY(${TEF_TARGET} SHARED ${TEF_API_SOURCES})
72
73 SET(_LIB_VERSION_ "${VERSION}")
74 SET(_LIB_SOVERSION_ "0")
75 SET_TARGET_PROPERTIES(${TEF_TARGET} PROPERTIES
76                       SOVERSION  ${_LIB_SOVERSION_}
77                       VERSION    ${_LIB_VERSION_})
78
79 IF(NOT DEFINED LIB_INSTALL_DIR)
80     SET(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
81 ENDIF(NOT DEFINED LIB_INSTALL_DIR)
82
83 IF(NOT DEFINED INCLUDE_INSTALL_DIR)
84     SET(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}")
85 ENDIF(NOT DEFINED INCLUDE_INSTALL_DIR)
86
87 IF(NOT DEFINED SYSCONF_INSTALL_DIR)
88         SET(SYSCONF_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_SYSCONFDIR}")
89 ENDIF(NOT DEFINED SYSCONF_INSTALL_DIR)
90
91 ADD_DEFINITIONS(-DLIB_INSTALL_DIR="${LIB_INSTALL_DIR}")
92 ADD_DEFINITIONS(-DSYSCONF_INSTALL_DIR="${SYSCONF_INSTALL_DIR}")
93
94 CONFIGURE_FILE(src/${TEF_PC}.in ${CMAKE_BINARY_DIR}/${TEF_PC} @ONLY)
95 CONFIGURE_FILE(src/scripts/tef-update.sh.in ${CMAKE_BINARY_DIR}/scripts/tef-update.sh @ONLY)
96
97 #install library
98 INSTALL(FILES src/tef.conf DESTINATION ${SYSCONF_INSTALL_DIR}/tef/)
99 INSTALL(PROGRAMS ${CMAKE_BINARY_DIR}/scripts/tef-update.sh DESTINATION ${CMAKE_INSTALL_SBINDIR})
100 INSTALL(TARGETS ${TEF_TARGET} DESTINATION ${LIB_INSTALL_DIR})
101 INSTALL(FILES       ${CMAKE_BINARY_DIR}/${TEF_PC}
102         DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
103
104
105 #install headers
106 INSTALL(FILES ${TEF_API_HEADERS} DESTINATION "${INCLUDE_INSTALL_DIR}/tef")