diff --git a/CMakeLists_test_template.txt b/CMakeLists_test_template.txt index 8470b4a461e235fa56715d60687a5c9a01eee631..260e74530e616e55663826a4a7568e6388a0b682 100755 --- a/CMakeLists_test_template.txt +++ b/CMakeLists_test_template.txt @@ -18,6 +18,8 @@ IF (NOT CMAKE_BUILD_TYPE) SET(CMAKE_BUILD_TYPE "DEBUG") ENDIF (NOT CMAKE_BUILD_TYPE) +SET(CMAKE_CXX_FLAGS "-std=c++0x") + SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -D_REENTRANT") SET(CMAKE_CXX_FLAGS_DEBUG "-g -Wall -D_REENTRANT -O0 --coverage -fprofile-arcs") SET(CMAKE_LINK_FLAGS_DEBUG "--coverage -fprofile-arcs") @@ -29,7 +31,7 @@ INCLUDE(CTest) ADD_SUBDIRECTORY(src) -ADD_SUBDIRECTORY(test/gtest) +#ADD_SUBDIRECTORY(test/gtest) ADD_SUBDIRECTORY(test) diff --git a/ReadMe.md b/ReadMe.md index 3868561720c10671c5d20a9a515eceb91913eb22..139a0997e89110e85ec9c9b5c3b190b401e8758b 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -27,9 +27,8 @@ Execute the *new_project.sh* script with the following parameters: * **-p "the project description"**: this parameter is required. It provides a short description of the project. This parameter will appear in all the associated documentation. For multi-word values, use the double quote. * **-n project\_name**: this parameter is required. It specifies the name of the shared library or the binary file. **This parameter must not have any whitespace characters**. * **-d comma,separated,dependencies**: this parameter is optional. It specifies a set of dependencies of the library or application. These depedencies will be automatically included inside the CMake structure. Only dependencies developed at IRI are currently supported. Other type of dependencies should better be added by hand once the project has been already created. - [//]: <> (Commented test option until it is operative again) -[//]: <> (* **-g**: this parameters is optional. Is specifies whether the test strcture is to be included into the project or not. This includes the necessaty CMake files to download and locally build the google test software and a basic test file for the generated project.) +* **-g**: this parameters is optional. Is specifies whether the test strcture is to be included into the project or not. This includes the necessaty CMake files to download and locally build the google test software and a basic test file for the generated project. After executing the script, all the temporary and template files are removed, as well as the link to the remote GIT repository, so that the new project can be easily associated to another repository. diff --git a/test/CMakeLists.txt.in b/test/CMakeLists.txt.in new file mode 100644 index 0000000000000000000000000000000000000000..c6247af53cf5fc2afb8de60ed8dbc1e42281ace7 --- /dev/null +++ b/test/CMakeLists.txt.in @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 2.8.2) + +project(googletest-download NONE) + +include(ExternalProject) +ExternalProject_Add(googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG master + SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src" + BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" +) diff --git a/test/CMakeLists_template.txt b/test/CMakeLists_template.txt index 873a4e031d2ad3c6a26f68e9c4e0936fa2eda553..fdeded0a0a69f472b05134f23cf2d0c6ec5e17a8 100644 --- a/test/CMakeLists_template.txt +++ b/test/CMakeLists_template.txt @@ -1,15 +1,39 @@ -include_directories(${GTEST_INCLUDE_DIRS}) -include_directories(${GMOCK_INCLUDE_DIRS}) +# Download and unpack googletest at configure time +configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt) +execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) +if(result) + message(FATAL_ERROR "CMake step for googletest failed: ${result}") +endif() +execute_process(COMMAND ${CMAKE_COMMAND} --build . + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) +if(result) + message(FATAL_ERROR "Build step for googletest failed: ${result}") +endif() -include_directories(${PROJECT_SOURCE_DIR}/include) +# Prevent overriding the parent project's compiler/linker +# settings on Windows +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) -set(CTEST_CUSTOM_COVERAGE_EXCLUDE *) +# Add googletest directly to our build. This defines +# the gtest and gtest_main targets. +add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src + ${CMAKE_CURRENT_BINARY_DIR}/googletest-build + EXCLUDE_FROM_ALL) -add_executable(library_name_tests library_name_test.cpp) -add_dependencies(library_name_tests googletest) +# The gtest/gtest_main targets carry header search path +# dependencies automatically when using CMake 2.8.11 or +# later. Otherwise we have to add them here ourselves. +if (CMAKE_VERSION VERSION_LESS 2.8.11) + include_directories("${gtest_SOURCE_DIR}/include") +endif() -target_link_libraries(library_name_tests ${GTEST_LIBS_DIR}/libgtest.a ${GTEST_LIBS_DIR}/libgtest_main.a) -target_link_libraries(library_name_tests ${GMOCK_LIBS_DIR}/libgmock.a ${GMOCK_LIBS_DIR}/libgmock_main.a) -target_link_libraries(library_name_tests pthread) +# add the necessary project include directories +include_directories(../include) +# Now simply link against gtest or gtest_main as needed. Eg +add_executable(library_name_tests library_name_test.cpp) +target_link_libraries(library_name_tests gtest_main) add_test(NAME Library_name_Test COMMAND library_name_tests)