Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build_system: build tinyxml2 statically #386

Merged
merged 6 commits into from
May 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 2 additions & 36 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ project(dronecore)
option(BUILD_TESTS "Build tests" ON)

include(cmake/compiler_flags.cmake)
include(cmake/zlib.cmake)
include(cmake/curl.cmake)
include(cmake/tinyxml2.cmake)
include(cmake/zlib.cmake)

if(BUILD_TESTS AND (IOS OR ANDROID))
message(STATUS "Building for iOS or Android: forcing BUILD_TESTS to FALSE...")
Expand All @@ -31,41 +32,6 @@ endif()
set(dronecore_install_include_dir "include/dronecore")
set(dronecore_install_lib_dir ${lib_path})

# We need tinyxml2 for the camera definition parsing.
add_subdirectory(third_party/tinyxml2 EXCLUDE_FROM_ALL)
link_directories(third_party/tinyxml2)
include_directories(SYSTEM third_party/tinyxml2)
set(TINYXML2_LIBRARY tinyxml2)

if(APPLE AND NOT IOS)
# We install the tinyxml2 library manually for macOS and iOS.
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
# Need to remove that d again.
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/third_party/tinyxml2/libtinyxml2d.6.0.0.dylib
DESTINATION ${lib_path}
#RENAME libtinyxml2.dylib
)
else()
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/third_party/tinyxml2/libtinyxml2.6.0.0.dylib
DESTINATION ${lib_path}
#RENAME libtinyxml2.dylib
)
endif()
elseif(ANDROID)
# We install the tinyxml2 library manually for Android.
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
# Need to remove that d again.
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/third_party/tinyxml2/libtinyxml2d.so
DESTINATION ${lib_path}
RENAME libtinyxml2.so
)
else()
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/third_party/tinyxml2/libtinyxml2.so
DESTINATION ${lib_path}
)
endif()
endif()

add_subdirectory(core)
add_subdirectory(plugins)

Expand Down
14 changes: 6 additions & 8 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,17 @@ test: on
test_script:
- cd %dronecore_dir%
- if "%configuration%"=="Debug" (
copy build\third_party\gtest\googlemock\gtest\Debug\gtestd.dll build\Debug\ &&
copy build\third_party\gtest\googlemock\gtest\Debug\gtest_maind.dll build\Debug\ &&
copy build\third_party\gtest\googlemock\Debug\gmockd.dll build\Debug\ &&
copy build\third_party\gtest\googlemock\gtest\Debug\gtestd.lib build\Debug\ &&
copy build\third_party\gtest\googlemock\gtest\Debug\gtest_maind.lib build\Debug\ &&
copy build\third_party\gtest\googlemock\Debug\gmockd.lib build\Debug\ &&
copy build\plugins\mission\Debug\dronecore_mission.dll build\Debug\ &&
copy build\plugins\camera\Debug\dronecore_camera.dll build\Debug\ &&
copy build\third_party\tinyxml2\Debug\tinyxml2d.dll build\Debug\ &&
build\Debug\unit_tests_runner.exe
) else (
copy build\third_party\gtest\googlemock\gtest\Release\gtest.dll build\Release\ &&
copy build\third_party\gtest\googlemock\gtest\Release\gtest_main.dll build\Release\ &&
copy build\third_party\gtest\googlemock\Release\gmock.dll build\Release\ &&
copy build\third_party\gtest\googlemock\gtest\Release\gtest.lib build\Release\ &&
copy build\third_party\gtest\googlemock\gtest\Release\gtest_main.lib build\Release\ &&
copy build\third_party\gtest\googlemock\Release\gmock.lib build\Release\ &&
copy build\plugins\mission\Release\dronecore_mission.dll build\Release\ &&
copy build\plugins\camera\Release\dronecore_camera.dll build\Release\ &&
copy build\third_party\tinyxml2\Release\tinyxml2.dll build\Release\ &&
build\Release\unit_tests_runner.exe
)
1 change: 1 addition & 0 deletions cmake/compiler_flags.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
if(MSVC)
add_definitions(-DWINDOWS)
set(warnings "-WX -W2")
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

# We need this so Windows links to e.g. dronecore_telemetry.dll.
# Without this option it will look for dronecore_telemetry.lib and fail.
Expand Down
43 changes: 43 additions & 0 deletions cmake/tinyxml2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# We need tinyxml2 for the camera definition parsing.

# We save the value of BUILD_STATIC_LIBRARY and BUILD_SHARED_LIBRARY before altering them
set(BEFORE_TINYXML_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
set(BEFORE_TINYXML_BUILD_STATIC_LIBS ${BUILD_STATIC_LIBS})
# This trick is needed with the cache as it is an option of tinyxml2,
# and tinyxml2 is used as a submodule
set(BUILD_SHARED_LIBS CACHE BOOL OFF)
set(BUILD_STATIC_LIBS CACHE BOOL ON)
set(BUILD_SHARED_LIBS OFF)
set(BUILD_STATIC_LIBS ON)

# Being linked to a shared lib later, tinyxml2_static needs to be compiled with -fPIC
# Same trick here, we don't want to set -fPIC outside of this file
set(BEFORE_TINYXML_POSITION_INDEPENDENT_CODE ${CMAKE_POSITION_INDEPENDENT_CODE})
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# Actually include tinyxml2
add_subdirectory(third_party/tinyxml2 EXCLUDE_FROM_ALL)
link_directories(third_party/tinyxml2)
include_directories(SYSTEM third_party/tinyxml2)

set(TINYXML2_LIBRARY tinyxml2_static)

# We set CMAKE_POSITION_INDEPENDENT_CODE back to what it was before including this file
set(CMAKE_POSITION_INDEPENDENT_CODE ${BEFORE_TINYXML_POSITION_INDEPENDENT_CODE})

# We set BUILD_STATIC_LIBRARY back to what it was before including this file
if (DEFINED BEFORE_TINYXML_BUILD_SHARED_LIBS)
set(BUILD_SHARED_LIBS CACHE BOOL ${BEFORE_TINYXML_BUILD_SHARED_LIBS})
set(BUILD_SHARED_LIBS ${BEFORE_TINYXML_BUILD_SHARED_LIBS})
else()
unset(BUILD_SHARED_LIBS CACHE)
unset(BUILD_SHARED_LIBS)
endif()

if (DEFINED BEFORE_TINYXML_BUILD_STATIC_LIBS)
set(BUILD_STATIC_LIBS CACHE BOOL ${BEFORE_TINYXML_BUILD_STATIC_LIBS})
set(BUILD_STATIC_LIBS ${BEFORE_TINYXML_BUILD_STATIC_LIBS})
else()
unset(BUILD_STATIC_LIBS CACHE)
unset(BUILD_STATIC_LIBS)
endif()
8 changes: 6 additions & 2 deletions core/integration_test_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class SitlTest : public testing::Test
{
protected:
virtual void SetUp()
virtual void SetUp() override
{
#ifndef WINDOWS
const int ret = system("./start_px4_sitl.sh");
Expand All @@ -19,9 +19,11 @@ class SitlTest : public testing::Test
}
// We need to wait a bit until it's up and running.
std::this_thread::sleep_for(std::chrono::seconds(3));
#else
dronecore::LogErr() << "Auto-starting SITL not supported on Windows.";
#endif
}
virtual void TearDown()
virtual void TearDown() override
{
#ifndef WINDOWS
// Don't rush this either.
Expand All @@ -31,6 +33,8 @@ class SitlTest : public testing::Test
dronecore::LogErr() << "./stop_px4_sitl.sh failed, giving up.";
abort();
}
#else
dronecore::LogErr() << "Auto-starting SITL not supported on Windows.";
#endif
}
};
6 changes: 0 additions & 6 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@ target_link_libraries(integration_tests_runner
gmock
)

if (MSVC)
# We need this to prevent linking errors from happening in the Windows build.
target_compile_definitions(integration_tests_runner PRIVATE -DGTEST_LINKED_AS_SHARED_LIBRARY)
target_compile_options(integration_tests_runner PUBLIC "/wd4251" "/wd4275")
endif()

add_test(integration_tests
integration_tests_runner
)
Expand Down