OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-cogutil / cmake / FindCxxtest.cmake

87 lines · cmake ref:
# Copyright (c) 2008, OpenCog.org (http://opencog.org)
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.

# The following values are defined
# CXXTEST_FOUND - system has cxxtest
# CXXTEST_GEN   - the binary used to generate the tests

# Find path to the cxxtestgen.py script (NB: this stuff should move to FindCXXTEST.cmake)
# CXXTEST_BIN_DIR environment variable must have been defined already

# cxxtest has a Python version and a Perl version. First, look
# for the Python version (.py extension).
FIND_PATH(CXXTEST_PYTHON_BIN_DIR cxxtestgen.py
	$ENV{CXXTEST_BIN_DIR}
	/usr/bin
	/usr/local/bin
	DOC "Where is cxxtest located?"
)

# Sometimes, the python version doesn't have a .py extension.
IF (NOT CXXTEST_PYTHON_BIN_DIR)
	FIND_PATH(CXXTEST_PYTHON_BIN_DIR cxxtestgen
		$ENV{CXXTEST_BIN_DIR}
		/usr/bin
		/usr/local/bin
		DOC "Where is cxxtest located?"
	)
	SET(CXXTEST_NO_PY_EXT TRUE)
ENDIF (NOT CXXTEST_PYTHON_BIN_DIR)

# If we found a Python version of cxxtestgen, verify Python3 is available
IF (CXXTEST_PYTHON_BIN_DIR)
	FIND_PACKAGE(Python3 COMPONENTS Interpreter)
	IF (Python3_Interpreter_FOUND)
		SET(CXXTEST_FOUND 1)
		IF (CXXTEST_NO_PY_EXT)
			SET(CXXTEST_GEN "${CXXTEST_PYTHON_BIN_DIR}/cxxtestgen" CACHE FILEPATH "CxxTest binary filepath")
		ELSE (CXXTEST_NO_PY_EXT)
			SET(CXXTEST_GEN "${CXXTEST_PYTHON_BIN_DIR}/cxxtestgen.py" CACHE FILEPATH "CxxTest binary filepath")
		ENDIF (CXXTEST_NO_PY_EXT)
	ENDIF (Python3_Interpreter_FOUND)
ENDIF (CXXTEST_PYTHON_BIN_DIR)

# If we still haven't found it, try the perl version.
IF (NOT CXXTEST_FOUND)
	FIND_PATH(CXXTEST_PERL_BIN_DIR cxxtestgen.pl
		$ENV{CXXTEST_BIN_DIR}
		/usr/bin
		/usr/local/bin
		DOC "Where is cxxtest located?"
	)
	IF (CXXTEST_PERL_BIN_DIR)
		SET(CXXTEST_FOUND 1)
		SET(CXXTEST_GEN "${CXXTEST_PERL_BIN_DIR}/cxxtestgen.pl" CACHE FILEPATH "CxxTest binary filepath")
	ENDIF (CXXTEST_PERL_BIN_DIR)
ENDIF (NOT CXXTEST_FOUND)


IF (WIN32)
	FIND_PATH(CXXTEST_INCLUDE_DIR "TestSuite.h"
		$ENV{CXXTEST_INCLUDE_DIR}
		"C:/Program Files/Cxxtest/cxxtest"
		"C:/Cxxtest/cxxtest"
		DOC "Where are cxxtest include files?"
	)
	IF (CXXTEST_BIN_DIR AND CXXTEST_INCLUDE_DIR)
	   GET_FILENAME_COMPONENT(CXXTEST_INCLUDE_DIRS "${CXXTEST_INCLUDE_DIR}" PATH)
	ELSE (CXXTEST_BIN_DIR AND CXXTEST_INCLUDE_DIR)
	   SET(CXXTEST_INCLUDE_DIRS)
	   SET(CXXTEST_FOUND 0)
	ENDIF (CXXTEST_BIN_DIR AND CXXTEST_INCLUDE_DIR)
ENDIF (WIN32)

# abort if required the results.
IF(NOT CXXTEST_FOUND)
	SET(CXXTEST_BIN_DIR_MESSAGE "Cxxtest was not found. Make sure CXXTEST_BIN_DIR is set.")
	IF(NOT Cxxtest_FIND_QUIETLY)
		MESSAGE(STATUS "${CXXTEST_BIN_DIR_MESSAGE}")
	ELSE(NOT Cxxtest_FIND_QUIETLY)
		IF(Cxxtest_FIND_REQUIRED)
			MESSAGE(FATAL_ERROR "${CXXTEST_BIN_DIR_MESSAGE}")
		ENDIF(Cxxtest_FIND_REQUIRED)
	ENDIF(NOT Cxxtest_FIND_QUIETLY)
ENDIF(NOT CXXTEST_FOUND)