Start modularizing the CMake buildsystem

The main reason for modularizing the unit tests was to split off
libboost_unit_test_framework from the osrm toolchain binaries.

Now only the unit test binaries link against it, unblocking
binary distribution without unit test library dependencies.

I started this on v4 a couple of weeks ago and hit a -llua5 issue on
Travis. By now v5 diverged quite a bit (especially in the code that I
have to stare at for debugging the issues).

https://github.com/Project-OSRM/osrm-backend/pull/2073

Let's bring this to v5+ only.

This is blocking:

- https://github.com/Project-OSRM/osrm-backend/issues/2065
- https://github.com/Project-OSRM/osrm-backend/issues/2197#issuecomment-204864938
This commit is contained in:
Daniel J. Hofmann 2016-04-06 12:44:46 +02:00 committed by Patrick Niklaus
parent 83b86bf092
commit b1ed268d0e
4 changed files with 96 additions and 41 deletions

View File

@ -161,10 +161,10 @@ script:
sudo ldconfig sudo ldconfig
fi fi
- echo "travis_fold:start:UNIT_TESTS" - echo "travis_fold:start:UNIT_TESTS"
- ./extractor-tests - ./unit_tests/extractor-tests
- ./engine-tests - ./unit_tests/engine-tests
- ./util-tests - ./unit_tests/util-tests
- ./server-tests - ./unit_tests/server-tests
- echo "travis_fold:end:UNIT_TESTS" - echo "travis_fold:end:UNIT_TESTS"
- popd - popd
- echo "travis_fold:start:CUCUMBER" - echo "travis_fold:start:CUCUMBER"
@ -173,7 +173,7 @@ script:
- echo "travis_fold:start:BENCHMARK" - echo "travis_fold:start:BENCHMARK"
- make -C test/data benchmark - make -C test/data benchmark
- echo "travis_fold:end:BENCHMARK" - echo "travis_fold:end:BENCHMARK"
- ./build/library-tests test/data/monaco.osrm - ./build/unit_tests/library-tests test/data/monaco.osrm
- mkdir example/build && pushd example/build - mkdir example/build && pushd example/build
- cmake .. - cmake ..
- make - make

View File

@ -46,10 +46,9 @@ add_custom_target(FingerPrintConfigure ALL ${CMAKE_COMMAND}
COMMENT "Configuring revision fingerprint" COMMENT "Configuring revision fingerprint"
VERBATIM) VERBATIM)
add_custom_target(tests DEPENDS engine-tests extractor-tests util-tests server-tests library-tests)
add_custom_target(benchmarks DEPENDS rtree-bench) add_custom_target(benchmarks DEPENDS rtree-bench)
set(BOOST_COMPONENTS date_time filesystem iostreams program_options regex system thread unit_test_framework) set(BOOST_COMPONENTS date_time filesystem iostreams program_options regex system thread)
configure_file( configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/include/util/version.hpp.in ${CMAKE_CURRENT_SOURCE_DIR}/include/util/version.hpp.in
@ -61,12 +60,6 @@ file(GLOB ContractorGlob src/contractor/*.cpp)
file(GLOB StorageGlob src/storage/*.cpp) file(GLOB StorageGlob src/storage/*.cpp)
file(GLOB ServerGlob src/server/*.cpp src/server/**/*.cpp) file(GLOB ServerGlob src/server/*.cpp src/server/**/*.cpp)
file(GLOB EngineGlob src/engine/*.cpp src/engine/**/*.cpp) file(GLOB EngineGlob src/engine/*.cpp src/engine/**/*.cpp)
file(GLOB ExtractorTestsGlob unit_tests/extractor/*.cpp)
file(GLOB EngineTestsGlob unit_tests/engine/*.cpp)
file(GLOB UtilTestsGlob unit_tests/util/*.cpp)
file(GLOB ServerTestsGlob unit_tests/server/*.cpp)
file(GLOB LibraryTestsGlob unit_tests/library/*.cpp)
file(GLOB IOTestsGlob unit_tests/io/*.cpp)
add_library(UTIL OBJECT ${UtilGlob}) add_library(UTIL OBJECT ${UtilGlob})
add_library(EXTRACTOR OBJECT ${ExtractorGlob}) add_library(EXTRACTOR OBJECT ${ExtractorGlob})
@ -87,21 +80,9 @@ add_library(osrm_extract $<TARGET_OBJECTS:EXTRACTOR> $<TARGET_OBJECTS:UTIL>)
add_library(osrm_contract $<TARGET_OBJECTS:CONTRACTOR> $<TARGET_OBJECTS:UTIL>) add_library(osrm_contract $<TARGET_OBJECTS:CONTRACTOR> $<TARGET_OBJECTS:UTIL>)
add_library(osrm_store $<TARGET_OBJECTS:STORAGE> $<TARGET_OBJECTS:UTIL>) add_library(osrm_store $<TARGET_OBJECTS:STORAGE> $<TARGET_OBJECTS:UTIL>)
# Unit tests
add_executable(engine-tests EXCLUDE_FROM_ALL unit_tests/engine_tests.cpp ${EngineTestsGlob} $<TARGET_OBJECTS:ENGINE> $<TARGET_OBJECTS:STORAGE> $<TARGET_OBJECTS:UTIL>)
add_executable(extractor-tests EXCLUDE_FROM_ALL unit_tests/extractor_tests.cpp ${ExtractorTestsGlob} $<TARGET_OBJECTS:EXTRACTOR> $<TARGET_OBJECTS:UTIL>)
add_executable(util-tests EXCLUDE_FROM_ALL unit_tests/util_tests.cpp ${UtilTestsGlob} $<TARGET_OBJECTS:UTIL>)
add_executable(server-tests EXCLUDE_FROM_ALL unit_tests/server_tests.cpp ${ServerTestsGlob} $<TARGET_OBJECTS:UTIL> $<TARGET_OBJECTS:SERVER>)
add_executable(library-tests EXCLUDE_FROM_ALL unit_tests/library_tests.cpp ${LibraryTestsGlob})
# Benchmarks # Benchmarks
add_executable(rtree-bench EXCLUDE_FROM_ALL src/benchmarks/static_rtree.cpp $<TARGET_OBJECTS:UTIL>) add_executable(rtree-bench EXCLUDE_FROM_ALL src/benchmarks/static_rtree.cpp $<TARGET_OBJECTS:UTIL>)
target_include_directories(engine-tests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/unit_tests)
target_include_directories(util-tests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/unit_tests)
target_include_directories(library-tests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/)
target_include_directories(rtree-bench PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/unit_tests)
# Check the release mode # Check the release mode
if(NOT CMAKE_BUILD_TYPE MATCHES Debug) if(NOT CMAKE_BUILD_TYPE MATCHES Debug)
set(CMAKE_BUILD_TYPE Release) set(CMAKE_BUILD_TYPE Release)
@ -157,10 +138,6 @@ if(CMAKE_BUILD_TYPE MATCHES Release)
endif() endif()
endif() endif()
if(NOT WIN32)
add_definitions(-DBOOST_TEST_DYN_LINK)
endif()
# Configuring compilers # Configuring compilers
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Wuninitialized -Wunreachable-code -Wstrict-overflow=2 -D_FORTIFY_SOURCE=2 -fPIC -fcolor-diagnostics") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Wuninitialized -Wunreachable-code -Wstrict-overflow=2 -D_FORTIFY_SOURCE=2 -fPIC -fcolor-diagnostics")
@ -242,11 +219,14 @@ find_package(Osmium REQUIRED COMPONENTS io)
include_directories(SYSTEM ${OSMIUM_INCLUDE_DIRS}) include_directories(SYSTEM ${OSMIUM_INCLUDE_DIRS})
find_package(Boost 1.49.0 COMPONENTS ${BOOST_COMPONENTS} REQUIRED) find_package(Boost 1.49.0 REQUIRED COMPONENTS ${BOOST_COMPONENTS})
if(NOT WIN32) if(NOT WIN32)
add_definitions(-DBOOST_TEST_DYN_LINK) add_definitions(-DBOOST_TEST_DYN_LINK)
endif() endif()
add_definitions(-DBOOST_SPIRIT_USE_PHOENIX_V3 -DBOOST_RESULT_OF_USE_DECLTYPE) add_definitions(-DBOOST_SPIRIT_USE_PHOENIX_V3)
add_definitions(-DBOOST_RESULT_OF_USE_DECLTYPE)
# XXX: activate when we're clean of deprecated Boost.FS features
# add_definitions(-DBOOST_FILESYSTEM_NO_DEPRECATED)
include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
@ -257,7 +237,7 @@ if(WIN32 AND CMAKE_BUILD_TYPE MATCHES Debug)
set(TBB_LIBRARIES ${TBB_DEBUG_LIBRARIES}) set(TBB_LIBRARIES ${TBB_DEBUG_LIBRARIES})
endif() endif()
find_package( Luabind REQUIRED ) find_package(Luabind REQUIRED)
include(check_luabind) include(check_luabind)
include_directories(SYSTEM ${LUABIND_INCLUDE_DIR}) include_directories(SYSTEM ${LUABIND_INCLUDE_DIR})
@ -337,13 +317,8 @@ target_link_libraries(osrm ${ENGINE_LIBRARIES})
target_link_libraries(osrm_contract ${CONTRACTOR_LIBRARIES}) target_link_libraries(osrm_contract ${CONTRACTOR_LIBRARIES})
target_link_libraries(osrm_extract ${EXTRACTOR_LIBRARIES}) target_link_libraries(osrm_extract ${EXTRACTOR_LIBRARIES})
target_link_libraries(osrm_store ${STORAGE_LIBRARIES}) target_link_libraries(osrm_store ${STORAGE_LIBRARIES})
# Tests # Benchmarks
target_link_libraries(engine-tests ${ENGINE_LIBRARIES})
target_link_libraries(server-tests osrm ${Boost_LIBRARIES})
target_link_libraries(extractor-tests ${EXTRACTOR_LIBRARIES})
target_link_libraries(rtree-bench ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${TBB_LIBRARIES}) target_link_libraries(rtree-bench ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${TBB_LIBRARIES})
target_link_libraries(util-tests ${UTIL_LIBRARIES})
target_link_libraries(library-tests osrm ${Boost_LIBRARIES})
if(BUILD_COMPONENTS) if(BUILD_COMPONENTS)
find_package(GDAL) find_package(GDAL)
@ -460,3 +435,7 @@ configure_file(
add_custom_target(uninstall add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake) COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake)
# Modular build system: each directory registered here provides its own CMakeLists.txt
add_subdirectory(unit_tests)

View File

@ -117,13 +117,13 @@ IF %ERRORLEVEL% NEQ 0 GOTO ERROR
SET PATH=%PROJECT_DIR%\osrm-deps\libs\bin;%PATH% SET PATH=%PROJECT_DIR%\osrm-deps\libs\bin;%PATH%
ECHO running engine-tests.exe ... ECHO running engine-tests.exe ...
%Configuration%\engine-tests.exe %Configuration%\unit_tests\engine-tests.exe
IF %ERRORLEVEL% NEQ 0 GOTO ERROR IF %ERRORLEVEL% NEQ 0 GOTO ERROR
ECHO running extractor-tests.exe ... ECHO running extractor-tests.exe ...
%Configuration%\extractor-tests.exe %Configuration%\unit_tests\extractor-tests.exe
IF %ERRORLEVEL% NEQ 0 GOTO ERROR IF %ERRORLEVEL% NEQ 0 GOTO ERROR
ECHO running util-tests.exe ... ECHO running util-tests.exe ...
%Configuration%\util-tests.exe %Configuration%\unit_tests\util-tests.exe
IF %ERRORLEVEL% NEQ 0 GOTO ERROR IF %ERRORLEVEL% NEQ 0 GOTO ERROR
IF NOT "%APPVEYOR_REPO_BRANCH%"=="develop" GOTO DONE IF NOT "%APPVEYOR_REPO_BRANCH%"=="develop" GOTO DONE

76
unit_tests/CMakeLists.txt Normal file
View File

@ -0,0 +1,76 @@
file(GLOB EngineTestsSources
engine_tests.cpp
engine/*.cpp)
file(GLOB ExtractorTestsSources
extractor_tests.cpp
extractor/*.cpp)
file(GLOB LibraryTestsSources
library_tests.cpp
library/*.cpp)
file(GLOB ServerTestsSources
server_tests.cpp
server/*.cpp)
file(GLOB UtilTestsSources
util_tests.cpp
util/*.cpp)
add_executable(engine-tests
EXCLUDE_FROM_ALL
${EngineTestsSources}
$<TARGET_OBJECTS:ENGINE> $<TARGET_OBJECTS:STORAGE> $<TARGET_OBJECTS:UTIL>)
add_executable(extractor-tests
EXCLUDE_FROM_ALL
${ExtractorTestsSources}
$<TARGET_OBJECTS:EXTRACTOR> $<TARGET_OBJECTS:UTIL>)
add_executable(library-tests
EXCLUDE_FROM_ALL
${LibraryTestsSources})
add_executable(server-tests
EXCLUDE_FROM_ALL
${ServerTestsSources}
$<TARGET_OBJECTS:UTIL> $<TARGET_OBJECTS:SERVER>)
add_executable(util-tests
EXCLUDE_FROM_ALL
${UtilTestsSources}
$<TARGET_OBJECTS:UTIL>)
# FindPackage below overwrites Boost_LIBRARIES
set(AllBoostLibrariesExceptUnitTest ${Boost_LIBRARIES})
find_package(Boost 1.49.0 REQUIRED COMPONENTS unit_test_framework)
if(NOT WIN32)
add_definitions(-DBOOST_TEST_DYN_LINK)
endif()
# After the find_package call we got only the unit test library
set(BoostUnitTestLibrary ${Boost_LIBRARIES})
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
target_include_directories(engine-tests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(library-tests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(util-tests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(engine-tests ${ENGINE_LIBRARIES} ${BoostUnitTestLibrary})
target_link_libraries(extractor-tests ${EXTRACTOR_LIBRARIES} ${BoostUnitTestLibrary})
target_link_libraries(library-tests osrm ${Boost_LIBRARIES} ${BoostUnitTestLibrary})
target_link_libraries(server-tests osrm ${Boost_LIBRARIES} ${BoostUnitTestLibrary})
target_link_libraries(util-tests ${UTIL_LIBRARIES} ${BoostUnitTestLibrary})
add_custom_target(tests
DEPENDS
engine-tests extractor-tests library-tests server-tests util-tests)