From 51655b24509ffddcaeff5183b2a76f5d9427036f Mon Sep 17 00:00:00 2001 From: spo Date: Thu, 26 May 2016 16:02:51 +0300 Subject: [PATCH] Add GTest.cmake & PythonAPI.cmake and use it in CMakeLists.txt --- CMakeCommon/GTest.cmake | 24 +++++++++++ CMakeCommon/PythonAPI.cmake | 11 +++++ src/ConstructionAPI/CMakeLists.txt | 31 ++++++-------- src/ConstructionAPI/Test/CMakeLists.txt | 57 +++++++++---------------- 4 files changed, 68 insertions(+), 55 deletions(-) create mode 100644 CMakeCommon/GTest.cmake create mode 100644 CMakeCommon/PythonAPI.cmake diff --git a/CMakeCommon/GTest.cmake b/CMakeCommon/GTest.cmake new file mode 100644 index 000000000..448ba617d --- /dev/null +++ b/CMakeCommon/GTest.cmake @@ -0,0 +1,24 @@ +## Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +cmake_minimum_required (VERSION 2.6) + +include(FindGTest) + + +#FIND_PACKAGE(GTest REQUIRED) +#INCLUDE_DIRECTORIES(${GTEST_INCLUDE_DIRS}) + +#FIND_PACKAGE(GMock REQUIRED) +#INCLUDE_DIRECTORIES(${GMOCK_INCLUDE_DIRS}) + + +# GCC 4.4.6 does not support some C++11 features used by GMock +add_definitions(-DGTEST_LANG_CXX11=0) + +include_directories( + $ENV{GTEST_ROOT}/googletest/include + $ENV{GTEST_ROOT}/googlemock/include + ) + +set(GTEST_LIBRARY $ENV{GTEST_ROOT}/googlemock/make/gmock_main.a) + \ No newline at end of file diff --git a/CMakeCommon/PythonAPI.cmake b/CMakeCommon/PythonAPI.cmake new file mode 100644 index 000000000..e63cd58bb --- /dev/null +++ b/CMakeCommon/PythonAPI.cmake @@ -0,0 +1,11 @@ +## Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +find_package(SWIG REQUIRED) +include(${SWIG_USE_FILE}) + +set(CMAKE_SWIG_FLAGS "-Wall") + +# For doxyhelp.i +include_directories( + ${PROJECT_BINARY_DIR}/doc/swig +) diff --git a/src/ConstructionAPI/CMakeLists.txt b/src/ConstructionAPI/CMakeLists.txt index 8faa88b43..ef8fcb5ea 100644 --- a/src/ConstructionAPI/CMakeLists.txt +++ b/src/ConstructionAPI/CMakeLists.txt @@ -1,12 +1,6 @@ ## Copyright (C) 2014-20xx CEA/DEN, EDF R&D INCLUDE(Common) -INCLUDE(UnitTest) - -FIND_PACKAGE(SWIG REQUIRED) -INCLUDE(${SWIG_USE_FILE}) -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) - SET(PROJECT_HEADERS ConstructionAPI.h @@ -22,24 +16,21 @@ SET(PROJECT_LIBRARIES ModelHighAPI ) -ADD_DEFINITIONS(-DCONSTRUCTIONAPI_EXPORTS ${CAS_DEFINITIONS}) -ADD_LIBRARY(ConstructionAPI SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS}) - -SET(CMAKE_SWIG_FLAGS "-Wall") - -SET_SOURCE_FILES_PROPERTIES(ConstructionAPI.i PROPERTIES CPLUSPLUS ON) -SET_SOURCE_FILES_PROPERTIES(ConstructionAPI.i PROPERTIES SWIG_DEFINITIONS "-shadow") - INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/src/ModelAPI ${PROJECT_SOURCE_DIR}/src/ModelHighAPI ) +ADD_DEFINITIONS(-DCONSTRUCTIONAPI_EXPORTS ${CAS_DEFINITIONS}) +ADD_LIBRARY(ConstructionAPI SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS}) TARGET_LINK_LIBRARIES(ConstructionAPI ${PROJECT_LIBRARIES}) -SET(SWIG_SCRIPTS - ${CMAKE_CURRENT_BINARY_DIR}/ConstructionAPI.py - ) +# SWIG wrapper + +INCLUDE(PythonAPI) + +SET_SOURCE_FILES_PROPERTIES(ConstructionAPI.i PROPERTIES CPLUSPLUS ON) +SET_SOURCE_FILES_PROPERTIES(ConstructionAPI.i PROPERTIES SWIG_DEFINITIONS "-shadow") SET(SWIG_LINK_LIBRARIES ConstructionAPI @@ -62,7 +53,11 @@ ENDIF(WIN32) INSTALL(TARGETS _ConstructionAPI DESTINATION ${SHAPER_INSTALL_SWIG}) INSTALL(TARGETS ConstructionAPI DESTINATION ${SHAPER_INSTALL_BIN}) -INSTALL(FILES ${SWIG_SCRIPTS} DESTINATION ${SHAPER_INSTALL_SWIG}) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/ConstructionAPI.py DESTINATION ${SHAPER_INSTALL_SWIG}) + +# Tests + +INCLUDE(UnitTest) ADD_UNIT_TESTS( TestPoint.py diff --git a/src/ConstructionAPI/Test/CMakeLists.txt b/src/ConstructionAPI/Test/CMakeLists.txt index ec2e920da..bbc44a46a 100644 --- a/src/ConstructionAPI/Test/CMakeLists.txt +++ b/src/ConstructionAPI/Test/CMakeLists.txt @@ -1,45 +1,28 @@ ## Copyright (C) 2014-20xx CEA/DEN, EDF R&D -add_definitions(-DGTEST_LANG_CXX11=0) +include(GTest) -INCLUDE(FindGTest) -#FIND_PACKAGE(GTest REQUIRED) -#INCLUDE_DIRECTORIES(${GTEST_INCLUDE_DIRS}) +include_directories( + ${PROJECT_SOURCE_DIR}/src/Events + ${PROJECT_SOURCE_DIR}/src/ModelAPI + ${PROJECT_SOURCE_DIR}/src/ModelHighAPI + ${PROJECT_SOURCE_DIR}/src/ConstructionAPI +) -#FIND_PACKAGE(GMock REQUIRED) -#INCLUDE_DIRECTORIES(${GMOCK_INCLUDE_DIRS}) +set(PROJECT_SOURCES + TestPoint.cpp +) -INCLUDE_DIRECTORIES( - ${PROJECT_SOURCE_DIR}/src/Events - ${PROJECT_SOURCE_DIR}/src/ModelAPI - ${PROJECT_SOURCE_DIR}/src/ModelHighAPI - - $ENV{GTEST_ROOT}/googletest/include - $ENV{GTEST_ROOT}/googlemock/include - ) +set(PROJECT_LIBRARIES + ModelAPI + ModelHighAPI + ConstructionAPI +) -SET(TEST_LIBRARIES - ModelAPI - ModelHighAPI - ConstructionAPI - ) +set(PACKAGE_NAME "ConstructionAPI") +set(TARGET_NAME "Test${PACKAGE_NAME}") -SET(PACKAGE_NAME "ConstructionAPI") -SET(TEST_NAME "${PACKAGE_NAME}_GTest") -SET(TARGET_NAME "Test${PACKAGE_NAME}") +add_executable(${TARGET_NAME} ${PROJECT_SOURCES}) +target_link_libraries(${TARGET_NAME} ${PROJECT_LIBRARIES} ${GTEST_LIBRARY}) -ADD_EXECUTABLE(${TARGET_NAME} - TestPoint.cpp - ) - -TARGET_LINK_LIBRARIES(${TARGET_NAME} - ${TEST_LIBRARIES} - - $ENV{GTEST_ROOT}/googlemock/make/gmock_main.a - ) - -GET_TARGET_PROPERTY(TEST_SOURCES ${TARGET_NAME} SOURCES) -GTEST_ADD_TESTS(${CMAKE_BINARY_DIR}/bin/${TARGET_NAME} - "" - ${TEST_SOURCES} - ) \ No newline at end of file +GTEST_ADD_TESTS(${CMAKE_BINARY_DIR}/bin/${TARGET_NAME} "" ${PROJECT_SOURCES}) -- 2.39.2