Commit 3f8f16be authored by Nicolas Michon's avatar Nicolas Michon

Cmake changes for cross-compilation and better use of imported targets

parents bf58e02c c9ffea7b
......@@ -19,141 +19,134 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
############################################################################
cmake_minimum_required(VERSION 3.0)
project(BELR VERSION 0.1.3 LANGUAGES C CXX)
set(BELR_SO_VERSION "1")
option(ENABLE_SHARED "Build shared library." ON)
option(ENABLE_STATIC "Build static library." ON)
option(ENABLE_STRICT "Build with strict compile options." YES)
option(ENABLE_TOOLS "Turn on or off compilation of tools." YES)
option(ENABLE_TESTS "Enable compilation of unit tests." YES)
cmake_minimum_required(VERSION 3.1)
project(BELR VERSION 0.1.3 LANGUAGES C CXX)
set(BELR_SO_VERSION "1")
option(ENABLE_SHARED "Build shared library." ON)
option(ENABLE_STATIC "Build static library." ON)
option(ENABLE_STRICT "Build with strict compile options." YES)
option(ENABLE_TOOLS "Turn on or off compilation of tools." YES)
option(ENABLE_TESTS "Enable compilation of unit tests." YES)
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()
include(GNUInstallDirs)
include(CheckSymbolExists)
include(CMakePushCheckState)
include(CheckCXXCompilerFlag)
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()
# find_package should be invoked here to check for libraries - however do NOT
# call include_directories here (see below)
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.0.5 REQUIRED OPTIONAL_COMPONENTS tester)
endif()
set(LINK_FLAGS )
if(UNIX AND NOT APPLE)
include(CheckIncludeFiles)
check_include_files(libudev.h HAVE_LIBUDEV_H)
endif()
include_directories(
include/
src/
${CMAKE_CURRENT_BINARY_DIR}
)
if(MSVC)
include_directories(${MSVC_INCLUDE_DIR})
endif()
set(STRICT_OPTIONS_CPP )
set(STRICT_OPTIONS_C )
set(STRICT_OPTIONS_CXX )
set(STRICT_OPTIONS_OBJC )
if(MSVC)
if(ENABLE_STRICT)
list(APPEND STRICT_OPTIONS_CPP "/WX")
endif()
else()
include(GNUInstallDirs)
include(CheckSymbolExists)
include(CMakePushCheckState)
include(CheckCXXCompilerFlag)
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()
# find_package should be invoked here to check for libraries - however do NOT
# call include_directories here (see below)
find_package(bctoolbox 0.0.5 REQUIRED OPTIONAL_COMPONENTS tester)
set(LINK_FLAGS )
if(UNIX AND NOT APPLE)
include(CheckIncludeFiles)
check_include_files(libudev.h HAVE_LIBUDEV_H)
endif()
include_directories(
include
src
${CMAKE_CURRENT_BINARY_DIR}
)
if(MSVC)
include_directories(${MSVC_INCLUDE_DIR})
endif()
set(STRICT_OPTIONS_CPP )
set(STRICT_OPTIONS_C )
set(STRICT_OPTIONS_CXX )
set(STRICT_OPTIONS_OBJC )
if(MSVC)
if(ENABLE_STRICT)
list(APPEND STRICT_OPTIONS_CPP "/WX")
endif()
else()
list(APPEND STRICT_OPTIONS_CPP "-Wall" "-Wuninitialized" "-Wno-error=deprecated-declarations")
list(APPEND STRICT_OPTIONS_C "-Wdeclaration-after-statement" "-Wstrict-prototypes" "-Wno-error=strict-prototypes")
list(APPEND STRICT_OPTIONS_CXX "-std=c++11")
if(CMAKE_C_COMPILER_ID MATCHES "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")
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")
CHECK_CXX_COMPILER_FLAG("-Wsuggest-override" SUGGEST_OVERRIDE)
if(SUGGEST_OVERRIDE)
list(APPEND STRICT_OPTIONS_CPP "-Wsuggest-override -Werror=suggest-override")
endif()
endif()
endif()
if(STRICT_OPTIONS_CPP)
list(REMOVE_DUPLICATES STRICT_OPTIONS_CPP)
endif()
if(STRICT_OPTIONS_C)
list(REMOVE_DUPLICATES STRICT_OPTIONS_C)
endif()
set(BELR_CPPFLAGS ${BCTOOLBOX_CPPFLAGS})
if(ENABLE_STATIC)
list(APPEND BELR_CPPFLAGS "-DBELR_STATIC")
endif()
if(BELR_CPPFLAGS)
list(REMOVE_DUPLICATES BELR_CPPFLAGS)
add_definitions(${BELR_CPPFLAGS})
endif()
add_definitions("-DBELR_EXPORTS")
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
set(EXPORT_TARGETS_NAME "LinphoneBuilder")
else()
set(EXPORT_TARGETS_NAME "belr")
endif()
set(BELR_GRAMMARS_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/belr/grammars")
set(BELR_GRAMMARS_RELATIVE_DIR "${CMAKE_INSTALL_DATADIR}/belr/grammars")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
add_subdirectory(include)
add_subdirectory(src)
if(ENABLE_TESTS AND BCTOOLBOX_TESTER_FOUND)
add_subdirectory(tester)
endif()
if(ENABLE_TOOLS)
add_subdirectory(tools)
endif()
include(CMakePackageConfigHelpers)
export(EXPORT ${EXPORT_TARGETS_NAME}Targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/BelrTargets.cmake"
)
configure_file(cmake/BelrConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/BelrConfig.cmake"
@ONLY
)
set(ConfigPackageLocation share/Belr/cmake)
install(EXPORT ${EXPORT_TARGETS_NAME}Targets
FILE BelrTargets.cmake
DESTINATION ${ConfigPackageLocation}
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/BelrConfig.cmake"
DESTINATION ${ConfigPackageLocation}
)
add_subdirectory(build)
endif()
endif()
if(STRICT_OPTIONS_CPP)
list(REMOVE_DUPLICATES STRICT_OPTIONS_CPP)
endif()
if(STRICT_OPTIONS_C)
list(REMOVE_DUPLICATES STRICT_OPTIONS_C)
endif()
set(BELR_CPPFLAGS ${BCTOOLBOX_CPPFLAGS})
if(ENABLE_STATIC)
list(APPEND BELR_CPPFLAGS "-DBELR_STATIC")
endif()
if(BELR_CPPFLAGS)
list(REMOVE_DUPLICATES BELR_CPPFLAGS)
add_definitions(${BELR_CPPFLAGS})
endif()
add_definitions("-DBELR_EXPORTS")
set(EXPORT_TARGET_NAME "belr")
set(BELR_GRAMMARS_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/${EXPORT_TARGET_NAME}/grammars")
set(BELR_GRAMMARS_RELATIVE_DIR "${CMAKE_INSTALL_DATADIR}/${EXPORT_TARGET_NAME}/grammars")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
add_subdirectory(include)
add_subdirectory(src)
if(ENABLE_TESTS)
add_subdirectory(tester)
endif()
if(ENABLE_TOOLS)
add_subdirectory(tools)
endif()
include(CMakePackageConfigHelpers)
set(EXPORT_TARGET_NAME belr)
set(ConfigPackageLocation share/${EXPORT_TARGET_NAME}/cmake)
export(EXPORT ${EXPORT_TARGET_NAME}Targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_TARGET_NAME}Targets.cmake"
)
configure_package_config_file(cmake/BelrConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_TARGET_NAME}Config.cmake"
INSTALL_DESTINATION ${ConfigPackageLocation}
NO_SET_AND_CHECK_MACRO
)
install(EXPORT ${EXPORT_TARGET_NAME}Targets
FILE ${EXPORT_TARGET_NAME}Targets.cmake
DESTINATION ${ConfigPackageLocation}
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_TARGET_NAME}Config.cmake"
DESTINATION ${ConfigPackageLocation}
)
add_subdirectory(build)
......@@ -28,15 +28,15 @@
# BELR_LIBRARIES - The libraries needed to use belr
# BELR_CPPFLAGS - The compilation flags needed to use belr
if(NOT LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
include("${CMAKE_CURRENT_LIST_DIR}/BelrTargets.cmake")
endif()
@PACKAGE_INIT@
set(BELR_TARGETNAME belr)
include("${CMAKE_CURRENT_LIST_DIR}/${BELR_TARGETNAME}Targets.cmake")
if(@ENABLE_SHARED@)
set(BELR_TARGETNAME belr)
set(BELR_LIBRARIES ${BELR_TARGETNAME})
else()
set(BELR_TARGETNAME belr-static)
if(TARGET ${BELR_TARGETNAME})
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
set(BELR_LIBRARIES ${BELR_TARGETNAME})
......@@ -48,14 +48,9 @@ else()
list(APPEND BELR_LIBRARIES ${BELR_LINK_LIBRARIES})
endif()
endif()
get_target_property(BELR_INCLUDE_DIRS ${BELR_TARGETNAME} INTERFACE_INCLUDE_DIRECTORIES)
endif()
get_target_property(BELR_INCLUDE_DIRS ${BELR_TARGETNAME} INTERFACE_INCLUDE_DIRECTORIES)
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
list(INSERT BELR_INCLUDE_DIRS 0 "${EP_belr_INCLUDE_DIR}")
else()
list(INSERT BELR_INCLUDE_DIRS 0 "@CMAKE_INSTALL_FULL_INCLUDEDIR@")
endif()
list(REMOVE_DUPLICATES BELR_INCLUDE_DIRS)
set(BELR_CPPFLAGS @BELR_CPPFLAGS@)
set(BELR_FOUND 1)
......@@ -19,84 +19,80 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
############################################################################
set(LIBS ${BCTOOLBOX_CORE_LIBRARIES})
set(BELR_HEADER_FILES )
set(BELR_SOURCE_FILES_C )
set(BELR_SOURCE_FILES_CXX
abnf.cpp
belr.cpp
grammarbuilder.cpp
parser.cpp
binarystream.cpp
)
bc_apply_compile_flags(BELR_SOURCE_FILES_C STRICT_OPTIONS_CPP STRICT_OPTIONS_C)
bc_apply_compile_flags(BELR_SOURCE_FILES_CXX STRICT_OPTIONS_CPP STRICT_OPTIONS_CXX)
add_definitions(
-DBCTBX_LOG_DOMAIN="belr"
)
if(WIN32 AND NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
list(APPEND LIBS ws2_32)
endif()
if(ENABLE_STATIC)
add_library(belr-static STATIC ${BELR_HEADER_FILES} ${BELR_SOURCE_FILES_C} ${BELR_SOURCE_FILES_CXX})
set_target_properties(belr-static PROPERTIES OUTPUT_NAME belr)
target_include_directories(belr-static PUBLIC ${BCTOOLBOX_CORE_INCLUDE_DIRS})
target_link_libraries(belr-static INTERFACE ${LIBS})
endif()
if(ENABLE_SHARED)
add_library(belr SHARED ${BELR_HEADER_FILES} ${BELR_SOURCE_FILES_C} ${BELR_SOURCE_FILES_CXX})
set(LIBS bctoolbox)
set(BELR_HEADER_FILES )
set(BELR_SOURCE_FILES_C )
set(BELR_SOURCE_FILES_CXX
abnf.cpp
belr.cpp
grammarbuilder.cpp
parser.cpp
binarystream.cpp
)
bc_apply_compile_flags(BELR_SOURCE_FILES_C STRICT_OPTIONS_CPP STRICT_OPTIONS_C)
bc_apply_compile_flags(BELR_SOURCE_FILES_CXX STRICT_OPTIONS_CPP STRICT_OPTIONS_CXX)
add_definitions(
-DBCTBX_LOG_DOMAIN="belr"
)
if(WIN32 AND NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
list(APPEND LIBS ws2_32)
endif()
if(ENABLE_STATIC)
add_library(belr STATIC ${BELR_HEADER_FILES} ${BELR_SOURCE_FILES_C} ${BELR_SOURCE_FILES_CXX})
set_target_properties(belr PROPERTIES OUTPUT_NAME belr)
target_link_libraries(belr PUBLIC ${LIBS})
target_include_directories(belr INTERFACE
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
)
endif()
if(ENABLE_SHARED)
add_library(belr SHARED ${BELR_HEADER_FILES} ${BELR_SOURCE_FILES_C} ${BELR_SOURCE_FILES_CXX})
if(APPLE)
if(IOS)
set(MIN_OS ${LINPHONE_IOS_DEPLOYMENT_TARGET})
else()
set(MIN_OS ${CMAKE_OSX_DEPLOYMENT_TARGET})
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/build/osx/")
set_target_properties(belr PROPERTIES
FRAMEWORK TRUE
MACOSX_FRAMEWORK_IDENTIFIER org.linphone.belr
MACOSX_FRAMEWORK_INFO_PLIST Info.plist.in
PUBLIC_HEADER "${BELR_HEADER_FILES}"
)
endif()
set_target_properties(belr PROPERTIES VERSION ${BELR_SO_VERSION})
target_include_directories(belr PUBLIC ${BCTOOLBOX_CORE_INCLUDE_DIRS})
target_link_libraries(belr PRIVATE ${LIBS})
if(MSVC)
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/belr.pdb
DESTINATION ${CMAKE_INSTALL_BINDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
endif()
endif()
endif()
if(ENABLE_STATIC)
install(TARGETS belr-static EXPORT ${EXPORT_TARGETS_NAME}Targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
endif()
if(ENABLE_SHARED)
install(TARGETS belr EXPORT ${EXPORT_TARGETS_NAME}Targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
FRAMEWORK DESTINATION Frameworks
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
endif()
install(FILES ${BELR_HEADER_FILES}
DESTINATION include/belr
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
)
if(IOS)
set(MIN_OS ${LINPHONE_IOS_DEPLOYMENT_TARGET})
else()
set(MIN_OS ${CMAKE_OSX_DEPLOYMENT_TARGET})
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/build/osx/")
set_target_properties(belr PROPERTIES
FRAMEWORK TRUE
MACOSX_FRAMEWORK_IDENTIFIER org.linphone.belr
MACOSX_FRAMEWORK_INFO_PLIST Info.plist.in
PUBLIC_HEADER "${BELR_HEADER_FILES}"
)
endif()
set_target_properties(belr PROPERTIES VERSION ${BELR_SO_VERSION})
target_include_directories(belr INTERFACE
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
)
target_link_libraries(belr PUBLIC ${LIBS})
if(MSVC)
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/belr.pdb
DESTINATION ${CMAKE_INSTALL_BINDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
endif()
endif()
endif()
install(TARGETS belr EXPORT ${EXPORT_TARGET_NAME}Targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
FRAMEWORK DESTINATION Frameworks
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
install(FILES ${BELR_HEADER_FILES}
DESTINATION include/belr
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
)
......@@ -23,7 +23,7 @@
if(ENABLE_SHARED)
set(BELR_LIBRARIES_FOR_TESTER belr)
else()
set(BELR_LIBRARIES_FOR_TESTER belr-static)
set(BELR_LIBRARIES_FOR_TESTER belr)
endif()
set(GRAMMAR_FILES
......@@ -48,9 +48,9 @@ bc_apply_compile_flags(SOURCE_FILES_CXX STRICT_OPTIONS_CPP STRICT_OPTIONS_CXX)
add_executable(belr_tester ${SOURCE_FILES_CXX} ${HEADER_FILES_CXX})
set_target_properties(belr_tester PROPERTIES LINKER_LANGUAGE CXX)
target_include_directories(belr_tester PUBLIC ${BCTOOLBOX_TESTER_INCLUDE_DIRS})
target_include_directories(belr_tester PUBLIC ${BCTOOLBOX_INCLUDE_DIRS})
target_link_libraries(belr_tester ${BELR_LIBRARIES_FOR_TESTER} ${BCTOOLBOX_LIBRARIES})
target_link_libraries(belr_tester ${BELR_LIBRARIES_FOR_TESTER} bctoolbox bctoolbox-tester)
if(NOT "${LINK_FLAGS_STR}" STREQUAL "")
set_target_properties(belle_sip_tester PROPERTIES LINK_FLAGS "${LINK_FLAGS_STR}")
......
......@@ -23,7 +23,7 @@
if(ENABLE_SHARED)
set(BELR_LIBRARIES_FOR_TOOLS belr)
else()
set(BELR_LIBRARIES_FOR_TOOLS belr-static)
set(BELR_LIBRARIES_FOR_TOOLS belr)
endif()
foreach(EXECUTABLE belr-parse belr-demo belr-compiler)
......@@ -31,7 +31,7 @@ foreach(EXECUTABLE belr-parse belr-demo belr-compiler)
bc_apply_compile_flags(SOURCE_FILES_CXX STRICT_OPTIONS_CPP STRICT_OPTIONS_CXX)
add_executable(${EXECUTABLE} ${SOURCE_FILES_CXX})
set_target_properties(${EXECUTABLE} PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(${EXECUTABLE} ${BELR_LIBRARIES_FOR_TOOLS} ${BCTOOLBOX_CORE_LIBRARIES})
target_link_libraries(${EXECUTABLE} ${BELR_LIBRARIES_FOR_TOOLS} bctoolbox)
endforeach()
if(NOT IOS)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment