Commit 68d2099b authored by Nicolas Michon's avatar Nicolas Michon

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

parent a75ba6e7
......@@ -21,7 +21,7 @@
#
############################################################################
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.1)
project(BELCARD VERSION 1.0.2 LANGUAGES C CXX)
set(BELCARD_SO_VERSION "1")
......@@ -47,21 +47,9 @@ 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(belr REQUIRED CONFIG)
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
include("${EP_belr_CONFIG_DIR}/BelrConfig.cmake")
else()
find_package(Belr REQUIRED)
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.0.3 REQUIRED OPTIONAL_COMPONENTS tester)
endif()
find_package(bctoolbox 0.0.3 REQUIRED OPTIONAL_COMPONENTS tester)
if(UNIX AND NOT APPLE)
include(CheckIncludeFiles)
......@@ -120,38 +108,40 @@ if(STRICT_OPTIONS_C)
list(REMOVE_DUPLICATES STRICT_OPTIONS_C)
endif()
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
set(EXPORT_TARGETS_NAME "LinphoneBuilder")
else()
set(EXPORT_TARGETS_NAME "belcard")
endif()
set(EXPORT_TARGETS_NAME "belcard")
add_subdirectory(include)
add_subdirectory(src)
if(ENABLE_UNIT_TESTS AND BCTOOLBOX_TESTER_FOUND)
if(ENABLE_UNIT_TESTS)
add_subdirectory(tester)
endif()
if(ENABLE_TOOLS)
add_subdirectory(tools)
endif()
include(CMakePackageConfigHelpers)
set(CONFIG_PACKAGE_LOCATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake")
set(INCLUDE_INSTALL_DIR "include")
export(EXPORT ${EXPORT_TARGETS_NAME}Targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/BelcardTargets.cmake"
FILE "${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_TARGETS_NAME}Targets.cmake"
)
configure_file(cmake/BelcardConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/BelcardConfig.cmake"
@ONLY
configure_package_config_file(cmake/BelcardConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_TARGETS_NAME}Config.cmake"
INSTALL_DESTINATION ${CONFIG_PACKAGE_LOCATION}
NO_SET_AND_CHECK_MACRO
)
set(ConfigPackageLocation share/Belcard/cmake)
set(ConfigPackageLocation "share/${EXPORT_TARGETS_NAME}/cmake")
install(EXPORT ${EXPORT_TARGETS_NAME}Targets
FILE BelcardTargets.cmake
FILE ${EXPORT_TARGETS_NAME}Targets.cmake
DESTINATION ${ConfigPackageLocation}
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/BelcardConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_TARGETS_NAME}Config.cmake"
DESTINATION ${ConfigPackageLocation}
)
add_subdirectory(build)
......@@ -28,34 +28,24 @@
# BELCARD_LIBRARIES - The libraries needed to use belcard
# BELCARD_CPPFLAGS - The compilation flags needed to use belcard
if(NOT LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
include("${CMAKE_CURRENT_LIST_DIR}/BelcardTargets.cmake")
endif()
@PACKAGE_INIT@
set(BELCARD_TARGETNAME belcard)
include("${CMAKE_CURRENT_LIST_DIR}/${BELCARD_TARGETNAME}Targets.cmake")
if(@ENABLE_SHARED@)
set(BELCARD_TARGETNAME belcard)
set(BELCARD_LIBRARIES ${BELCARD_TARGETNAME})
else()
set(BELCARD_TARGETNAME belcard-static)
if(TARGET ${BELCARD_TARGETNAME})
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
set(BELCARD_LIBRARIES ${BELCARD_TARGETNAME})
else()
get_target_property(BELCARD_LIBRARIES ${BELCARD_TARGETNAME} LOCATION)
endif()
get_target_property(BELCARD_LIBRARIES ${BELCARD_TARGETNAME} LOCATION)
get_target_property(BELCARD_LINK_LIBRARIES ${BELCARD_TARGETNAME} INTERFACE_LINK_LIBRARIES)
if(BELCARD_LINK_LIBRARIES)
list(APPEND BELCARD_LIBRARIES ${BELCARD_LINK_LIBRARIES})
endif()
endif()
endif()
get_target_property(BELCARD_INCLUDE_DIRS ${BELCARD_TARGETNAME} INTERFACE_INCLUDE_DIRECTORIES)
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
list(INSERT BELCARD_INCLUDE_DIRS 0 "${EP_belcard_INCLUDE_DIR}")
else()
list(INSERT BELCARD_INCLUDE_DIRS 0 "@CMAKE_INSTALL_FULL_INCLUDEDIR@")
endif()
list(REMOVE_DUPLICATES BELCARD_INCLUDE_DIRS)
set(BELCARD_CPPFLAGS @BELCARD_CPPFLAGS@)
set(BELCARD_FOUND 1)
......@@ -49,10 +49,9 @@ bc_apply_compile_flags(BELCARD_SOURCE_FILES_C STRICT_OPTIONS_CPP STRICT_OPTIONS_
bc_apply_compile_flags(BELCARD_SOURCE_FILES_CXX STRICT_OPTIONS_CPP STRICT_OPTIONS_CXX)
if(ENABLE_STATIC)
add_library(belcard-static STATIC ${BELCARD_HEADER_FILES} ${BELCARD_SOURCE_FILES_C} ${BELCARD_SOURCE_FILES_CXX})
set_target_properties(belcard-static PROPERTIES OUTPUT_NAME belcard)
target_include_directories(belcard-static PUBLIC ${BELR_INCLUDE_DIRS} ${BCTOOLBOX_INCLUDE_DIRS})
target_link_libraries(belcard-static INTERFACE ${BELR_LIBRARIES} ${BCTOOLBOX_CORE_LIBRARIES})
add_library(belcard STATIC ${BELCARD_HEADER_FILES} ${BELCARD_SOURCE_FILES_C} ${BELCARD_SOURCE_FILES_CXX})
set_target_properties(belcard PROPERTIES OUTPUT_NAME belcard)
target_link_libraries(belcard PRIVATE belr bctoolbox)
endif()
if(ENABLE_SHARED)
add_library(belcard SHARED ${BELCARD_HEADER_FILES} ${BELCARD_SOURCE_FILES_C} ${BELCARD_SOURCE_FILES_CXX} ${VCARD_GRAMMAR_FILES})
......@@ -71,42 +70,34 @@ if(ENABLE_SHARED)
PUBLIC_HEADER "${BELCARD_HEADER_FILES}"
)
endif()
set_target_properties(belcard PROPERTIES VERSION ${BELCARD_SO_VERSION})
target_include_directories(belcard PUBLIC ${BELR_INCLUDE_DIRS} ${BCTOOLBOX_INCLUDE_DIRS})
target_link_libraries(belcard PRIVATE ${BELR_LIBRARIES} ${BCTOOLBOX_CORE_LIBRARIES})
if(MSVC)
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/belcard.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 belcard-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 belcard 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 ${BELCARD_HEADER_FILES}
DESTINATION include/belcard
set_target_properties(belcard PROPERTIES VERSION ${BELCARD_SO_VERSION})
target_include_directories(belcard INTERFACE
$<INSTALL_INTERFACE:include>
)
target_link_libraries(belcard PRIVATE belr bctoolbox)
if(MSVC)
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/belcard.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 belcard 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
)
install(FILES ${BELCARD_HEADER_FILES}
DESTINATION include/belcard
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
)
install(FILES ${VCARD_GRAMMAR_FILES}
DESTINATION "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/belr/grammars"
)
)
install(FILES ${VCARD_GRAMMAR_FILES}
DESTINATION "${CMAKE_INSTALL_DATADIR}/belr/grammars"
)
......@@ -23,7 +23,7 @@
if(ENABLE_SHARED)
set(BELCARD_LIBRARIES_FOR_TESTER belcard)
else()
set(BELCARD_LIBRARIES_FOR_TESTER belcard-static)
set(BELCARD_LIBRARIES_FOR_TESTER belcard)
endif()
set(VCARD_FILES
......@@ -53,8 +53,8 @@ bc_apply_compile_flags(SOURCE_FILES_CXX STRICT_OPTIONS_CPP STRICT_OPTIONS_CXX)
add_executable(belcard_tester ${SOURCE_FILES_CXX} ${HEADER_FILES_CXX})
set_target_properties(belcard_tester PROPERTIES LINKER_LANGUAGE CXX)
target_include_directories(belcard_tester PUBLIC ${BCTOOLBOX_TESTER_INCLUDE_DIRS})
target_link_libraries(belcard_tester ${BELCARD_LIBRARIES_FOR_TESTER} ${BCTOOLBOX_TESTER_LIBRARIES})
target_include_directories(belcard_tester PRIVATE ${BCTOOLBOX_INCLUDE_DIRS})
target_link_libraries(belcard_tester belcard bctoolbox bctoolbox-tester)
if(NOT IOS)
install(TARGETS belcard_tester
......
......@@ -23,7 +23,7 @@
if(ENABLE_SHARED)
set(BELCARD_LIBRARIES_FOR_TOOLS belcard)
else()
set(BELCARD_LIBRARIES_FOR_TOOLS belcard-static)
set(BELCARD_LIBRARIES_FOR_TOOLS belcard)
endif()
foreach(EXECTUABLE belcard-folder belcard-unfolder belcard-parser)
......@@ -31,13 +31,14 @@ foreach(EXECTUABLE belcard-folder belcard-unfolder belcard-parser)
bc_apply_compile_flags(SOURCE_FILES_CXX STRICT_OPTIONS_CPP STRICT_OPTIONS_CXX)
add_executable(${EXECTUABLE} ${SOURCE_FILES_CXX})
set_target_properties(${EXECTUABLE} PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(${EXECTUABLE} ${BELCARD_LIBRARIES_FOR_TOOLS} ${BELR_LIBRARIES})
if(NOT IOS)
install(TARGETS ${EXECTUABLE}
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()
target_link_libraries(${EXECTUABLE} PRIVATE belcard belr)
if(NOT IOS)
install(TARGETS ${EXECTUABLE}
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()
endforeach()
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