我有以下CMakeLists.txt
:
cmake_minimum_required(VERSION 2.6)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
find_package(FOO QUIET NO_CMAKE_PACKAGE_REGISTRY)
if (FOO_FOUND)
message("FOO is found")
else (FOO_FOUND)
message("FOO not found")
endif (FOO_FOUND)
find_package(FOO QUIET)
if (FOO_FOUND)
message("FOO (2) is found")
else (FOO_FOUND)
message("FOO (2) not found")
endif (FOO_FOUND)
有一个文件${CMAKE_SOURCE_DIR}/cmake/FindFOO.cmake
。但是,当我运行cmake
时,它仅在第二种情况下检测到包FOO
:
-- (...)
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
FOO not found
FOO (2) is found
-- Configuring done
-- Generating done
-- Build files have been written to: /home/me/tmp/build
我对文档的理解是NO_CMAKE_PACKAGE_REGISTRY
禁止find_package()
查看~/.cmake/package/FOO
但我在这里什么都没有。我对cmake 2.8.9和cmake 3.5.1有相同的行为。
为什么find_package()
在第一种情况下找不到文件?
答案 0 :(得分:1)
find_package有两种模式:第一种,简单,搜索public function currentmonthAction()
{
$payload = $this->request->getJsonRawBody();
$this->setDB();
$ticketsmodel = new Tickets();
$fromcitycondition = "";
if( isset($payload->city->id) )
{
$fromcitycondition = "and fromcity='{$payload->city->id}'";
}
try{
$date = new \Datetime($payload->date);
$year = $date->format('Y');
$month = $date->format('m');
$month = '08';
$daysInMonth = cal_days_in_month(CAL_GREGORIAN, $month, $year);
/* result for all cities passenger */
$result = array();
// get all cities permutations
$tmpcitiesdata = array();
$rawresultset = Tickets::find (
array(
'columns' => 'fromcity,tocity',
'conditions' => "departure between '{$year}-{$month}-01' and '{$year}-{$month}-$daysInMonth' and tickettype in (1) ". $fromcitycondition,
'group' => 'fromcity,tocity'
));
foreach ($rawresultset as $rawresult) {
$tmpcitiesdata[$rawresult->fromcity.'-'.$rawresult->tocity]['fromcity'] = $rawresult->fromcity;
$tmpcitiesdata[$rawresult->fromcity.'-'.$rawresult->tocity]['tocity'] = $rawresult->tocity;
}
//var_dump($rawresultset);
// get tickets sold based on cities combinations
$total = 0;
foreach ($tmpcitiesdata as $tmpcities) {
$rawresultset = Tickets::find (
array(
'columns' => 'customer',
'conditions' => "departure between '{$year}-{$month}-01' and '{$year}-{$month}-$daysInMonth' and tickettype in (1) and fromcity=". $tmpcities['fromcity']." and tocity=".$tmpcities['tocity'],
'group' => 'customer'
));
$totalsoldRaw = count($rawresultset);
// get ticket cancellations
$rawresultset = Tickets::find (
array(
'conditions' => "departure between '{$year}-{$month}-01' and '{$year}-{$month}-$daysInMonth' and tickettype in (3) and fromcity=". $tmpcities['fromcity']." and tocity=".$tmpcities['tocity']
));
//make sure cancellations are tickets cancellations not booking cancellations
foreach($rawresultset as $rawresult)
{
$resultNumber = Tickets::find("departure='$rawresult->departure' and seatno={$rawresult->seatno} and id < {$rawresult->id} and tickettype = 1" );
if( count($resultNumber) > 0 ){
$totalsoldRaw = $totalsoldRaw-1;
}
}
$total += $totalsoldRaw;
array_push($result, array('total' => $totalsoldRaw, 'fromcity' => Cities::findFirstById($tmpcities['fromcity'])->name, 'tocity' => Cities::findFirstById($tmpcities['tocity'])->name));
}
//sort result based on counts
arsort($result);
//cut result to max 6 cities
$result = array_slice($result, 0, 6);
$this->response->setContentType('application/json')
->setJsonContent(
array( 'totaltickets' => $total, "allcities" => $result )
);
$this->response->send();
return;
}
catch(\PDOException $e)
{
$this->response->setStatusCode('422','Invalid Payload');
$this->response->setContentType('application/json')
->setJsonContent(array(
'flash' => array(
'class' => 'danger',
'message' => $e->getMessage()
)
));
$this->response->send();
return;
}
}
模块,第二种,更复杂,搜索FindFOO.cmake
config 文件。
默认情况下,CMake尝试两种模式,因此模块模式成功找到您的文件。
但是选项FOOConfig.cmake
仅适用于 config 模式,在任何情况下都无法找到您的文件。
NO_CMAKE_PACKAGE_REGISTRY