Commit 31236a3b authored by Nicolas Michon's avatar Nicolas Michon

Merge branch 'test_squash' into 'master'

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

See merge request !8
parents a75ba6e7 68d2099b
...@@ -21,7 +21,7 @@ ...@@ -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) project(BELCARD VERSION 1.0.2 LANGUAGES C CXX)
set(BELCARD_SO_VERSION "1") set(BELCARD_SO_VERSION "1")
...@@ -47,21 +47,9 @@ if(MSVC) ...@@ -47,21 +47,9 @@ if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS) add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif() endif()
# find_package should be invoked here to check for libraries - however do NOT find_package(belr REQUIRED CONFIG)
# call include_directories here (see below)
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS) find_package(bctoolbox 0.0.3 REQUIRED OPTIONAL_COMPONENTS tester)
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()
if(UNIX AND NOT APPLE) if(UNIX AND NOT APPLE)
include(CheckIncludeFiles) include(CheckIncludeFiles)
...@@ -120,38 +108,40 @@ if(STRICT_OPTIONS_C) ...@@ -120,38 +108,40 @@ if(STRICT_OPTIONS_C)
list(REMOVE_DUPLICATES STRICT_OPTIONS_C) list(REMOVE_DUPLICATES STRICT_OPTIONS_C)
endif() endif()
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS) set(EXPORT_TARGETS_NAME "belcard")
set(EXPORT_TARGETS_NAME "LinphoneBuilder")
else()
set(EXPORT_TARGETS_NAME "belcard")
endif()
add_subdirectory(include) add_subdirectory(include)
add_subdirectory(src) add_subdirectory(src)
if(ENABLE_UNIT_TESTS AND BCTOOLBOX_TESTER_FOUND)
if(ENABLE_UNIT_TESTS)
add_subdirectory(tester) add_subdirectory(tester)
endif() endif()
if(ENABLE_TOOLS) if(ENABLE_TOOLS)
add_subdirectory(tools) add_subdirectory(tools)
endif() endif()
include(CMakePackageConfigHelpers) include(CMakePackageConfigHelpers)
set(CONFIG_PACKAGE_LOCATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake")
set(INCLUDE_INSTALL_DIR "include")
export(EXPORT ${EXPORT_TARGETS_NAME}Targets 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" configure_package_config_file(cmake/BelcardConfig.cmake.in
@ONLY "${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 install(EXPORT ${EXPORT_TARGETS_NAME}Targets
FILE BelcardTargets.cmake FILE ${EXPORT_TARGETS_NAME}Targets.cmake
DESTINATION ${ConfigPackageLocation} DESTINATION ${ConfigPackageLocation}
) )
install(FILES install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/BelcardConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_TARGETS_NAME}Config.cmake"
DESTINATION ${ConfigPackageLocation} DESTINATION ${ConfigPackageLocation}
) )
add_subdirectory(build) add_subdirectory(build)
...@@ -28,34 +28,24 @@ ...@@ -28,34 +28,24 @@
# BELCARD_LIBRARIES - The libraries needed to use belcard # BELCARD_LIBRARIES - The libraries needed to use belcard
# BELCARD_CPPFLAGS - The compilation flags needed to use belcard # BELCARD_CPPFLAGS - The compilation flags needed to use belcard
if(NOT LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS) @PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/BelcardTargets.cmake")
endif() set(BELCARD_TARGETNAME belcard)
include("${CMAKE_CURRENT_LIST_DIR}/${BELCARD_TARGETNAME}Targets.cmake")
if(@ENABLE_SHARED@) if(@ENABLE_SHARED@)
set(BELCARD_TARGETNAME belcard)
set(BELCARD_LIBRARIES ${BELCARD_TARGETNAME}) set(BELCARD_LIBRARIES ${BELCARD_TARGETNAME})
else() else()
set(BELCARD_TARGETNAME belcard-static)
if(TARGET ${BELCARD_TARGETNAME}) if(TARGET ${BELCARD_TARGETNAME})
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS) get_target_property(BELCARD_LIBRARIES ${BELCARD_TARGETNAME} LOCATION)
set(BELCARD_LIBRARIES ${BELCARD_TARGETNAME})
else()
get_target_property(BELCARD_LIBRARIES ${BELCARD_TARGETNAME} LOCATION)
endif()
get_target_property(BELCARD_LINK_LIBRARIES ${BELCARD_TARGETNAME} INTERFACE_LINK_LIBRARIES) get_target_property(BELCARD_LINK_LIBRARIES ${BELCARD_TARGETNAME} INTERFACE_LINK_LIBRARIES)
if(BELCARD_LINK_LIBRARIES) if(BELCARD_LINK_LIBRARIES)
list(APPEND BELCARD_LIBRARIES ${BELCARD_LINK_LIBRARIES}) list(APPEND BELCARD_LIBRARIES ${BELCARD_LINK_LIBRARIES})
endif() endif()
endif() endif()
endif() endif()
get_target_property(BELCARD_INCLUDE_DIRS ${BELCARD_TARGETNAME} INTERFACE_INCLUDE_DIRECTORIES) 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_CPPFLAGS @BELCARD_CPPFLAGS@)
set(BELCARD_FOUND 1) set(BELCARD_FOUND 1)
...@@ -49,10 +49,9 @@ bc_apply_compile_flags(BELCARD_SOURCE_FILES_C STRICT_OPTIONS_CPP STRICT_OPTIONS_ ...@@ -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) bc_apply_compile_flags(BELCARD_SOURCE_FILES_CXX STRICT_OPTIONS_CPP STRICT_OPTIONS_CXX)
if(ENABLE_STATIC) if(ENABLE_STATIC)
add_library(belcard-static STATIC ${BELCARD_HEADER_FILES} ${BELCARD_SOURCE_FILES_C} ${BELCARD_SOURCE_FILES_CXX}) add_library(belcard STATIC ${BELCARD_HEADER_FILES} ${BELCARD_SOURCE_FILES_C} ${BELCARD_SOURCE_FILES_CXX})
set_target_properties(belcard-static PROPERTIES OUTPUT_NAME belcard) set_target_properties(belcard PROPERTIES OUTPUT_NAME belcard)
target_include_directories(belcard-static PUBLIC ${BELR_INCLUDE_DIRS} ${BCTOOLBOX_INCLUDE_DIRS}) target_link_libraries(belcard PRIVATE belr bctoolbox)
target_link_libraries(belcard-static INTERFACE ${BELR_LIBRARIES} ${BCTOOLBOX_CORE_LIBRARIES})
endif() endif()
if(ENABLE_SHARED) if(ENABLE_SHARED)
add_library(belcard SHARED ${BELCARD_HEADER_FILES} ${BELCARD_SOURCE_FILES_C} ${BELCARD_SOURCE_FILES_CXX} ${VCARD_GRAMMAR_FILES}) 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) ...@@ -71,42 +70,34 @@ if(ENABLE_SHARED)
PUBLIC_HEADER "${BELCARD_HEADER_FILES}" PUBLIC_HEADER "${BELCARD_HEADER_FILES}"
) )
endif() endif()
set_target_properties(belcard PROPERTIES VERSION ${BELCARD_SO_VERSION}) set_target_properties(belcard PROPERTIES VERSION ${BELCARD_SO_VERSION})
target_include_directories(belcard PUBLIC ${BELR_INCLUDE_DIRS} ${BCTOOLBOX_INCLUDE_DIRS}) target_include_directories(belcard INTERFACE
target_link_libraries(belcard PRIVATE ${BELR_LIBRARIES} ${BCTOOLBOX_CORE_LIBRARIES}) $<INSTALL_INTERFACE:include>
if(MSVC) )
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") target_link_libraries(belcard PRIVATE belr bctoolbox)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/belcard.pdb if(MSVC)
DESTINATION ${CMAKE_INSTALL_BINDIR} if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/belcard.pdb
) DESTINATION ${CMAKE_INSTALL_BINDIR}
endif() PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
endif() )
endif() endif()
endif()
if(ENABLE_STATIC) endif()
install(TARGETS belcard-static EXPORT ${EXPORT_TARGETS_NAME}Targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} install(TARGETS belcard EXPORT ${EXPORT_TARGETS_NAME}Targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
) FRAMEWORK DESTINATION Frameworks
endif() PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
if(ENABLE_SHARED) )
install(TARGETS belcard EXPORT ${EXPORT_TARGETS_NAME}Targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} install(FILES ${BELCARD_HEADER_FILES}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} DESTINATION include/belcard
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
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
) )
install(FILES ${VCARD_GRAMMAR_FILES} install(FILES ${VCARD_GRAMMAR_FILES}
DESTINATION "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/belr/grammars" DESTINATION "${CMAKE_INSTALL_DATADIR}/belr/grammars"
) )
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
if(ENABLE_SHARED) if(ENABLE_SHARED)
set(BELCARD_LIBRARIES_FOR_TESTER belcard) set(BELCARD_LIBRARIES_FOR_TESTER belcard)
else() else()
set(BELCARD_LIBRARIES_FOR_TESTER belcard-static) set(BELCARD_LIBRARIES_FOR_TESTER belcard)
endif() endif()
set(VCARD_FILES set(VCARD_FILES
...@@ -53,8 +53,8 @@ bc_apply_compile_flags(SOURCE_FILES_CXX STRICT_OPTIONS_CPP STRICT_OPTIONS_CXX) ...@@ -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}) add_executable(belcard_tester ${SOURCE_FILES_CXX} ${HEADER_FILES_CXX})
set_target_properties(belcard_tester PROPERTIES LINKER_LANGUAGE CXX) set_target_properties(belcard_tester PROPERTIES LINKER_LANGUAGE CXX)
target_include_directories(belcard_tester PUBLIC ${BCTOOLBOX_TESTER_INCLUDE_DIRS}) target_include_directories(belcard_tester PRIVATE ${BCTOOLBOX_INCLUDE_DIRS})
target_link_libraries(belcard_tester ${BELCARD_LIBRARIES_FOR_TESTER} ${BCTOOLBOX_TESTER_LIBRARIES}) target_link_libraries(belcard_tester belcard bctoolbox bctoolbox-tester)
if(NOT IOS) if(NOT IOS)
install(TARGETS belcard_tester install(TARGETS belcard_tester
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
if(ENABLE_SHARED) if(ENABLE_SHARED)
set(BELCARD_LIBRARIES_FOR_TOOLS belcard) set(BELCARD_LIBRARIES_FOR_TOOLS belcard)
else() else()
set(BELCARD_LIBRARIES_FOR_TOOLS belcard-static) set(BELCARD_LIBRARIES_FOR_TOOLS belcard)
endif() endif()
foreach(EXECTUABLE belcard-folder belcard-unfolder belcard-parser) foreach(EXECTUABLE belcard-folder belcard-unfolder belcard-parser)
...@@ -31,13 +31,14 @@ 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) bc_apply_compile_flags(SOURCE_FILES_CXX STRICT_OPTIONS_CPP STRICT_OPTIONS_CXX)
add_executable(${EXECTUABLE} ${SOURCE_FILES_CXX}) add_executable(${EXECTUABLE} ${SOURCE_FILES_CXX})
set_target_properties(${EXECTUABLE} PROPERTIES LINKER_LANGUAGE CXX) set_target_properties(${EXECTUABLE} PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(${EXECTUABLE} ${BELCARD_LIBRARIES_FOR_TOOLS} ${BELR_LIBRARIES}) target_link_libraries(${EXECTUABLE} PRIVATE belcard belr)
if(NOT IOS)
install(TARGETS ${EXECTUABLE} if(NOT IOS)
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} install(TARGETS ${EXECTUABLE}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
) PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
endif() )
endif()
endforeach() 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