Last active
June 13, 2017 04:31
-
-
Save kovrov/c846f3ee1a1a452ac1168874c42ad9fa to your computer and use it in GitHub Desktop.
~/.config/QtProject/qtcreator/templates/wizards/cmake-with-tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required (VERSION 3.1) | |
project (%{ProjectName}) | |
option (BUILD_UNIT_TESTS "Build unit-tests" OFF) | |
option (USE_GLFW "Use glfw" OFF) | |
file (GLOB SRC_LIST src/*.cpp src/*.h) | |
list (REMOVE_ITEM SRC_LIST ${CMAKE_SOURCE_DIR}/src/main.cpp) | |
set (PROJECT_IMPL ${PROJECT_NAME}_impl) | |
add_library (${PROJECT_IMPL} OBJECT ${SRC_LIST}) | |
set_property (TARGET ${PROJECT_IMPL} PROPERTY CXX_STANDARD 14) | |
add_executable (${PROJECT_NAME} "%{CppFileName}" $<TARGET_OBJECTS:${PROJECT_IMPL}>) | |
set_property (TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14) | |
if (BUILD_UNIT_TESTS) | |
add_subdirectory (tests) | |
endif () | |
add_subdirectory (external) | |
target_link_libraries (${PROJECT_NAME} ${EXTERNAL_LIBRARIES}) | |
include_directories (${EXTERNA_INCLUDE_DIRS}) | |
# libgl1-mesa-dev | |
find_package (OpenGL REQUIRED) | |
target_link_libraries (${PROJECT_NAME} ${OPENGL_LIBRARIES}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (USE_GLFW) | |
add_subdirectory (glfw) | |
add_dependencies (${PROJECT_NAME} glfw) | |
set (EXTERNAL_LIBRARIES ${GLFW_LIBRARIES} PARENT_SCOPE) | |
set (EXTERNA_INCLUDE_DIRS ${GLFW_INCLUDE_DIRS} PARENT_SCOPE) | |
endif () |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include (ExternalProject) | |
ExternalProject_Add ( | |
glfw3 | |
URL https://github.com/glfw/glfw/archive/3.2.1.tar.gz | |
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/_install" | |
) | |
ExternalProject_Get_Property (glfw3 source_dir binary_dir install_dir) | |
add_library (glfw INTERFACE IMPORTED GLOBAL) | |
add_dependencies (glfw glfw3) | |
set (DEP_LIBS "${binary_dir}/src/${CMAKE_STATIC_LIBRARY_PREFIX}glfw3${CMAKE_STATIC_LIBRARY_SUFFIX}") | |
if (UNIX AND NOT APPLE) | |
find_package(X11 REQUIRED) | |
list(APPEND DEP_LIBS ${X11_X11_LIB} ${X11_Xrandr_LIB} ${X11_Xinerama_LIB} ${X11_Xcursor_LIB} ${X11_Xxf86vm_LIB}) | |
find_package(Threads REQUIRED) | |
list(APPEND DEP_LIBS ${CMAKE_THREAD_LIBS_INIT}) | |
find_library(RT_LIBRARY rt) | |
mark_as_advanced(RT_LIBRARY) | |
if (RT_LIBRARY) | |
list(APPEND DEP_LIBS "${RT_LIBRARY}") | |
list(APPEND glfw_PKG_LIBS "-lrt") | |
endif() | |
find_library(MATH_LIBRARY m) | |
mark_as_advanced(MATH_LIBRARY) | |
if (MATH_LIBRARY) | |
list(APPEND DEP_LIBS "${MATH_LIBRARY}") | |
list(APPEND glfw_PKG_LIBS "-lm") | |
endif() | |
if (CMAKE_DL_LIBS) | |
list(APPEND DEP_LIBS "${CMAKE_DL_LIBS}") | |
list(APPEND glfw_PKG_LIBS "-l${CMAKE_DL_LIBS}") | |
endif() | |
endif() | |
set (GLFW_LIBRARIES ${DEP_LIBS} PARENT_SCOPE) | |
set (GLFW_INCLUDE_DIRS "${source_dir}/include" PARENT_SCOPE) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%{Cpp:LicenseTemplate}\ | |
#include <iostream> | |
using namespace std; | |
int main(int argc, char *argv[]) { | |
cout << "Hello World!" << endl; | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
find_package (Threads REQUIRED) | |
find_package (GTest) | |
if (NOT GTEST_FOUND) | |
add_subdirectory (gtest) | |
endif () | |
set (TEST_NAME tst_${PROJECT_NAME}) | |
file (GLOB_RECURSE TESTS_SRC_LIST *.cpp) | |
add_executable (${TEST_NAME} ${TESTS_SRC_LIST}) | |
set_property (TARGET ${TEST_NAME} PROPERTY CXX_STANDARD 14) | |
target_include_directories (${TEST_NAME} PRIVATE ${GTEST_INCLUDE_DIRS} src) | |
target_link_libraries (${TEST_NAME} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://raw.githubusercontent.com/snikulov/google-test-examples/master/ext/gtest/CMakeLists.txt | |
include (ExternalProject) | |
# Download and install GoogleTest | |
ExternalProject_Add ( | |
gtest | |
URL https://github.com/google/googletest/archive/release-1.8.0.tar.gz | |
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/gtest | |
# Disable install step | |
INSTALL_COMMAND "" | |
) | |
# Get GTest source and binary directories from CMake project | |
ExternalProject_Get_Property (gtest source_dir binary_dir) | |
# Create a libgtest target to be used as a dependency by test programs | |
add_library (libgtest IMPORTED STATIC GLOBAL) | |
add_dependencies (libgtest gtest) | |
# Set libgtest properties | |
set_target_properties (libgtest PROPERTIES | |
"IMPORTED_LOCATION" "${binary_dir}/googlemock/gtest/libgtest.a" | |
"IMPORTED_LINK_INTERFACE_LIBRARIES" "${CMAKE_THREAD_LIBS_INIT}" | |
) | |
# Create a libgmock target to be used as a dependency by test programs | |
add_library (libgmock IMPORTED STATIC GLOBAL) | |
add_dependencies (libgmock gtest) | |
# Set libgmock properties | |
set_target_properties (libgmock PROPERTIES | |
"IMPORTED_LOCATION" "${binary_dir}/googlemock/libgmock.a" | |
"IMPORTED_LINK_INTERFACE_LIBRARIES" "${CMAKE_THREAD_LIBS_INIT}" | |
) | |
# I couldn't make it work with INTERFACE_INCLUDE_DIRECTORIES | |
include_directories ( | |
"${source_dir}/googletest/include" | |
"${source_dir}/googlemock/include" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": 1, | |
"supportedProjectTypes": [ "CMakeProjectManager.CMakeProject" ], | |
"id": "R.Plain Cpp Application with Tests", | |
"category": "I.Projects", | |
"trDisplayName": "CMake C++ Project with GTest", | |
"trDescription": "Creates a simple C++ CMake project with optional GTest unit-tests.", | |
"trDisplayCategory": "Non-Qt Project", | |
"icon": "icon.png", | |
"enabled": "%{JS: [ %{Plugins} ].indexOf('CMakeProjectManager') >= 0}", | |
"options": | |
[ | |
{ "key": "CMakeFile", "value": "%{ProjectDirectory}/CMakeLists.txt" }, | |
{ "key": "ProjectFile", "value": "%{CMakeFile}" }, | |
{ "key": "CppFileName", "value": "%{JS: 'main.' + Util.preferredSuffix('text/x-c++src')}" }, | |
{ "key": "IsTopLevelProject", "value": "%{JS: !'%{Exists:ProjectExplorer.Profile.Ids}'}" } | |
], | |
"pages": | |
[ | |
{ | |
"trDisplayName": "Project Location", | |
"trShortTitle": "Location", | |
"typeId": "Project" | |
}, | |
{ | |
"trDisplayName": "Define Build System", | |
"trShortTitle": "Build System", | |
"typeId": "Fields", | |
"data": | |
[ | |
{ | |
"name": "BuildSystem", | |
"trDisplayName": "Build system:", | |
"type": "ComboBox", | |
"data": | |
{ | |
"index": 0, | |
"items": | |
[ | |
{ | |
"trKey": "CMake", | |
"value": "cmake", | |
"condition": "%{JS: [ %{Plugins} ].indexOf('CMakeProjectManager') >= 0}" | |
} | |
] | |
} | |
} | |
] | |
}, | |
{ | |
"trDisplayName": "Kit Selection", | |
"trShortTitle": "Kits", | |
"typeId": "Kits", | |
"enabled": "%{IsTopLevelProject}", | |
"data": { "projectFilePath": "%{ProjectFile}" } | |
}, | |
{ | |
"trDisplayName": "Project Management", | |
"trShortTitle": "Summary", | |
"typeId": "Summary" | |
} | |
], | |
"generators": | |
[ | |
{ | |
"typeId": "File", | |
"data": | |
[ | |
{ | |
"source": "CMakeLists.txt", | |
"openAsProject": true, | |
"condition": "%{JS: '%{BuildSystem}' === 'cmake'}" | |
}, | |
{ | |
"source": "external.CMakeLists.txt", | |
"target": "%{ProjectDirectory}/external/CMakeLists.txt" | |
}, | |
{ | |
"source": "external.glfw.CMakeLists.txt", | |
"target": "%{ProjectDirectory}/external/glfw/CMakeLists.txt" | |
}, | |
{ | |
"source": "tests.CMakeLists.txt", | |
"target": "%{ProjectDirectory}/tests/CMakeLists.txt" | |
}, | |
{ | |
"source": "tests.gtest.CMakeLists.txt", | |
"target": "%{ProjectDirectory}/tests/gtest/CMakeLists.txt" | |
}, | |
{ | |
"source": "main.cpp", | |
"target": "%{CppFileName}", | |
"openInEditor": true | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment