CMakeLists.txt 6.09 KB
Newer Older
johan's avatar
johan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
############################################################################
# CMakeLists.txt
# Copyright (C) 2017  Belledonne Communications, Grenoble France
#
############################################################################
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#
############################################################################
Johan Pascal's avatar
Johan Pascal committed
22 23 24 25 26
include(GNUInstallDirs)
include(CheckSymbolExists)
include(CheckLibraryExists)
include(CMakePushCheckState)
include(CMakePackageConfigHelpers)
johan's avatar
johan committed
27 28

cmake_minimum_required(VERSION 3.0)
29
project(lime VERSION 0.0.1 LANGUAGES CXX C)
johan's avatar
johan committed
30 31

set(LIME_SO_VERSION "0")
32
set(LIME_VERSION ${PROJECT_VERSION})
johan's avatar
johan committed
33

johan's avatar
johan committed
34 35
option(ENABLE_SHARED "Build shared library." YES)
option(ENABLE_STATIC "Build static library." YES)
johan's avatar
johan committed
36
option(ENABLE_STRICT "Build with strict compile options." YES)
37 38
option(ENABLE_CURVE25519 "Enable support of Curve 25519." YES)
option(ENABLE_CURVE448 "Enable support of Curve 448(goldilock)." YES)
johan's avatar
johan committed
39
option(ENABLE_UNIT_TESTS "Enable compilation of unit tests." YES)
Johan Pascal's avatar
Johan Pascal committed
40
option(ENABLE_PROFILING "Enable profiling, GCC only" NO)
johan's avatar
johan committed
41
option(ENABLE_C_INTERFACE "Enable support of C89 foreign function interface" NO)
johan's avatar
johan committed
42
option(ENABLE_JNI "Enable support of Java foreign function interface" NO)
johan's avatar
johan committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

if(NOT CPACK_GENERATOR AND NOT CMAKE_INSTALL_RPATH AND CMAKE_INSTALL_PREFIX)
	set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR})
	message(STATUS "Setting install rpath to ${CMAKE_INSTALL_RPATH}")
endif()

if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
	set(BcToolbox_FIND_COMPONENTS tester)
	include("${EP_bctoolbox_CONFIG_DIR}/BcToolboxConfig.cmake")
else()
	find_package(BcToolbox 0.5.1 REQUIRED OPTIONAL_COMPONENTS tester)
endif()

find_package(Soci REQUIRED)

include_directories(
	include/
	src/
	${CMAKE_CURRENT_BINARY_DIR}
)
if(MSVC)
	include_directories(${MSVC_INCLUDE_DIR})
endif()

set(LIME_INCLUDE_DIRS
Johan Pascal's avatar
Johan Pascal committed
70
	${PROJECT_SOURCE_DIR}/include
johan's avatar
johan committed
71 72 73 74 75
)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/config.h PROPERTIES GENERATED ON)

76
set(LIME_CPPFLAGS ${BCTOOLBOX_CPPFLAGS})
johan's avatar
johan committed
77 78 79 80 81 82
if(LIME_CPPFLAGS)
	list(REMOVE_DUPLICATES LIME_CPPFLAGS)
	add_definitions(${LIME_CPPFLAGS})
endif()
add_definitions("-DLIME_EXPORTS")

johan's avatar
johan committed
83
set(STRICT_OPTIONS_C)
johan's avatar
johan committed
84 85 86
set(STRICT_OPTIONS_CPP )
set(STRICT_OPTIONS_CXX )
set(STRICT_OPTIONS_OBJC )
johan's avatar
johan committed
87 88 89 90 91 92 93 94 95 96

if(ENABLE_JNI)
	set(CMAKE_CXX_STANDARD 14)
else()
	set(CMAKE_CXX_STANDARD 11)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_C_STANDARD 99)

johan's avatar
johan committed
97 98 99 100
if(MSVC)
	if(ENABLE_STRICT)
		list(APPEND STRICT_OPTIONS_CPP "/WX")
	endif()
johan's avatar
johan committed
101 102
	# avoid conflicts with std::min and std::max
	add_definitions("-DNOMINMAX")
johan's avatar
johan committed
103
else()
Johan Pascal's avatar
Johan Pascal committed
104 105 106
	if (ENABLE_PROFILING)
		list(APPEND STRICT_OPTIONS_CXX "-g -pg")
	endif()
johan's avatar
johan committed
107
        #list(APPEND STRICT_OPTIONS_CPP "-Wall" "-Wuninitialized" "-Wno-error=deprecated-declarations") # turn off deprecated-declaration warning to avoid being flooded by soci.h
johan's avatar
johan committed
108
	list(APPEND STRICT_OPTIONS_CPP "-Wall" "-Wuninitialized" "-Wno-deprecated-declarations" "-Wno-missing-field-initializers")
johan's avatar
johan committed
109
	
johan's avatar
johan committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
	if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
		list(APPEND STRICT_OPTIONS_CPP "-Qunused-arguments" "-Wno-array-bounds")
	endif()
	if(APPLE)
		list(APPEND STRICT_OPTIONS_CPP "-Wno-error=unknown-warning-option" "-Qunused-arguments" "-Wno-tautological-compare" "-Wno-unused-function" "-Wno-array-bounds")
	endif()
	if(ENABLE_STRICT)
		list(APPEND STRICT_OPTIONS_CPP "-Werror" "-Wextra" "-Wno-unused-parameter" "-fno-strict-aliasing")
	endif()
endif()
if(STRICT_OPTIONS_CPP)
	list(REMOVE_DUPLICATES STRICT_OPTIONS_CPP)
endif()

if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
	set(EXPORT_TARGETS_NAME "LinphoneBuilder")
else()
	set(EXPORT_TARGETS_NAME "lime")
endif()

130
if (ENABLE_CURVE25519)
johan's avatar
johan committed
131 132 133 134
	add_definitions("-DEC25519_ENABLED")
	message(STATUS "Support Curve 25519")
endif()

135
if (ENABLE_CURVE448)
johan's avatar
johan committed
136 137 138 139
	add_definitions("-DEC448_ENABLED")
	message(STATUS "Support Curve 448")
endif()

johan's avatar
johan committed
140 141 142 143 144
if(ENABLE_C_INTERFACE)
	add_definitions("-DFFI_ENABLED")
	message(STATUS "Provide C89 interface")
endif()

johan's avatar
johan committed
145
if(ENABLE_JNI)
146 147 148 149 150 151 152 153
	message(STATUS "Provide JNI interface")
	if (NOT ANDROID)
		find_package(JNI REQUIRED)

		if (JNI_FOUND)
			message (STATUS "JNI_INCLUDE_DIRS=${JNI_INCLUDE_DIRS}")
			message (STATUS "JNI_LIBRARIES=${JNI_LIBRARIES}")
		endif()
johan's avatar
johan committed
154 155 156
	endif()
endif()

johan's avatar
johan committed
157 158 159 160 161 162 163 164 165 166 167 168 169 170
add_subdirectory(include)
add_subdirectory(src)
if(ENABLE_UNIT_TESTS AND BCTOOLBOX_TESTER_FOUND)
        enable_testing()
	add_subdirectory(tester)
endif()

export(EXPORT ${EXPORT_TARGETS_NAME}Targets
	FILE "${CMAKE_CURRENT_BINARY_DIR}/LimeTargets.cmake"
)
configure_file(cmake/LimeConfig.cmake.in
	"${CMAKE_CURRENT_BINARY_DIR}/LimeConfig.cmake"
	@ONLY
)
Johan Pascal's avatar
Johan Pascal committed
171
set(ConfigPackageLocation "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake")
johan's avatar
johan committed
172 173 174 175 176 177 178 179 180
install(EXPORT ${EXPORT_TARGETS_NAME}Targets
	FILE LimeTargets.cmake
	DESTINATION ${ConfigPackageLocation}
)
install(FILES
	"${CMAKE_CURRENT_BINARY_DIR}/LimeConfig.cmake"
	DESTINATION ${ConfigPackageLocation}
)

181 182 183 184 185 186 187 188 189 190 191
# Doxygen
find_package(Doxygen)
if (DOXYGEN_FOUND)
	configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
	add_custom_target(doc
		${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
		WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
		COMMENT "Generating API documentation with Doxygen" VERBATIM
)
endif()

jehan's avatar
jehan committed
192
add_subdirectory(build)