Building a project with CMake including other libraries which uses different build systems
I am working on an open source project which uses C
for libraries, C++
for GUI and Cmake
for managing build. This project is just started and have only couple of files. I can successfully generate makefiles
on my linux development environment and on windows I can generate Visual Studio
project files using CMake. All works well so far.
As the project is evolving, I am in a stage where I need a testing framework. I have good experience with UnitTest++
which will work well on all popular platforms.
The problem is, I have no clue to integrate the UnitTest++
开发者_StackOverflowbuild with CMake
(they use makefile on linux and visual studio project files are available for windows). I need to build UnitTest++
files to generate a library before my code is built. How can I specify this in CMake in a way which will work on linux and windows?
I'm using this CMakeLists.txt:
#/**********************************************************\
#Original Author: Richard Bateman (taxilian)
#
#Created: Nov 20, 2009
#License: Dual license model; choose one of two:
# New BSD License
# http://www.opensource.org/licenses/bsd-license.php
# - or -
# GNU Lesser General Public License, version 2.1
# http://www.gnu.org/licenses/lgpl-2.1.html
#
#Copyright 2009 PacketPass, Inc and the Firebreath development team
#\**********************************************************/
cmake_minimum_required (VERSION 2.8)
project (UnitTest++)
message ("Generating project ${PROJECT_NAME}")
include_directories (
${CMAKE_CURRENT_SOURCE_DIR}/src
)
list (APPEND SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/AssertException.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/Test.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/Checks.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/TestRunner.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/TestResults.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/TestReporter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/TestReporterStdout.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ReportAssert.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/TestList.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/TimeConstraint.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/TestDetails.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/MemoryOutStream.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/DeferredTestReporter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/DeferredTestResult.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/XmlTestReporter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/CurrentTest.cpp
)
if (UNIX)
list(APPEND SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/Posix/SignalTranslator.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/Posix/TimeHelpers.cpp
)
elseif (WIN32)
list(APPEND SOURCES
src/Win32/TimeHelpers.cpp
)
endif()
add_library (UnitTest++ STATIC ${SOURCES})
add_definitions(
-D_CRT_SECURE_NO_DEPRECATE
)
if (UNIX)
set_target_properties(UnitTest++ PROPERTIES
COMPILE_FLAGS "-g -Wall -W -ansi"
)
endif(UNIX)
精彩评论