parent
0b396e2089
commit
e0ffb2c2a7
@ -1,9 +1,7 @@
|
|||||||
set(_cmake_oldestSupported "_MSC_VER >= 1600")
|
set(_cmake_oldestSupported "_MSC_VER >= 1600")
|
||||||
|
|
||||||
# Not yet supported:
|
|
||||||
#set(_cmake_feature_test_c_static_assert "")
|
|
||||||
|
|
||||||
set(_cmake_feature_test_c_restrict "_MSC_VER >= 1927")
|
set(_cmake_feature_test_c_restrict "_MSC_VER >= 1927")
|
||||||
|
set(_cmake_feature_test_c_static_assert "_MSC_VER >= 1928")
|
||||||
|
|
||||||
set(_cmake_feature_test_c_variadic_macros "${_cmake_oldestSupported}")
|
set(_cmake_feature_test_c_variadic_macros "${_cmake_oldestSupported}")
|
||||||
set(_cmake_feature_test_c_function_prototypes "${_cmake_oldestSupported}")
|
set(_cmake_feature_test_c_function_prototypes "${_cmake_oldestSupported}")
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.18)
|
||||||
|
project(cxx-as-objcxx LANGUAGES OBJCXX)
|
||||||
|
|
||||||
|
add_executable(cxx-as-objcxx main.cpp)
|
||||||
|
set_source_files_properties(main.cpp PROPERTIES LANGUAGE OBJCXX)
|
@ -0,0 +1,6 @@
|
|||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
@ -0,0 +1,96 @@
|
|||||||
|
# This test checks whether adding a source file to the project triggers an AUTOMOC re-run.
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
project(RerunMocOnAddFile)
|
||||||
|
include("../AutogenCoreTest.cmake")
|
||||||
|
|
||||||
|
# Create an executable to generate a clean target
|
||||||
|
set(main_source "${CMAKE_CURRENT_BINARY_DIR}/generated_main.cpp")
|
||||||
|
file(WRITE "${main_source}" "int main() {}")
|
||||||
|
add_executable(exe "${main_source}")
|
||||||
|
|
||||||
|
# Utility variables
|
||||||
|
set(timeformat "%Y.%j.%H.%M%S")
|
||||||
|
set(testProjectTemplateDir "${CMAKE_CURRENT_SOURCE_DIR}/MocOnAddFile")
|
||||||
|
set(testProjectSrc "${CMAKE_CURRENT_BINARY_DIR}/MocOnAddFile")
|
||||||
|
set(testProjectBinDir "${CMAKE_CURRENT_BINARY_DIR}/MocOnAddFile-build")
|
||||||
|
|
||||||
|
# Utility macros
|
||||||
|
macro(sleep)
|
||||||
|
message(STATUS "Sleeping for a few seconds.")
|
||||||
|
execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
macro(acquire_timestamp When)
|
||||||
|
file(TIMESTAMP "${mocBasicBin}" time${When} "${timeformat}")
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
macro(rebuild buildName)
|
||||||
|
message(STATUS "Starting build ${buildName}.")
|
||||||
|
execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${testProjectBinDir}" RESULT_VARIABLE result)
|
||||||
|
if (result)
|
||||||
|
message(FATAL_ERROR "Build ${buildName} failed.")
|
||||||
|
else()
|
||||||
|
message(STATUS "Build ${buildName} finished.")
|
||||||
|
endif()
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
macro(require_change)
|
||||||
|
if (timeAfter VERSION_GREATER timeBefore)
|
||||||
|
message(STATUS "As expected the file ${mocBasicBin} changed.")
|
||||||
|
else()
|
||||||
|
message(SEND_ERROR "Unexpectedly the file ${mocBasicBin} did not change!\nTimestamp pre: ${timeBefore}\nTimestamp aft: ${timeAfter}\n")
|
||||||
|
endif()
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
macro(require_change_not)
|
||||||
|
if (timeAfter VERSION_GREATER timeBefore)
|
||||||
|
message(SEND_ERROR "Unexpectedly the file ${mocBasicBin} changed!\nTimestamp pre: ${timeBefore}\nTimestamp aft: ${timeAfter}\n")
|
||||||
|
else()
|
||||||
|
message(STATUS "As expected the file ${mocBasicBin} did not change.")
|
||||||
|
endif()
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
# Create the test project from the template
|
||||||
|
unset(additional_project_sources)
|
||||||
|
unset(main_cpp_includes)
|
||||||
|
configure_file("${testProjectTemplateDir}/CMakeLists.txt.in" "${testProjectSrc}/CMakeLists.txt")
|
||||||
|
configure_file("${testProjectTemplateDir}/main.cpp.in" "${testProjectSrc}/main.cpp")
|
||||||
|
|
||||||
|
# Initial build
|
||||||
|
try_compile(MOC_RERUN
|
||||||
|
"${testProjectBinDir}"
|
||||||
|
"${testProjectSrc}"
|
||||||
|
MocOnAddFile
|
||||||
|
CMAKE_FLAGS "-DQT_TEST_VERSION=${QT_TEST_VERSION}"
|
||||||
|
"-DCMAKE_AUTOGEN_VERBOSE=${CMAKE_AUTOGEN_VERBOSE}"
|
||||||
|
"-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}"
|
||||||
|
OUTPUT_VARIABLE output
|
||||||
|
)
|
||||||
|
if (NOT MOC_RERUN)
|
||||||
|
message(FATAL_ERROR "Initial build of mocOnAddFile failed. Output: ${output}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Sleep to ensure new timestamps
|
||||||
|
sleep()
|
||||||
|
|
||||||
|
# Add a QObject class (defined in header) to the project and build
|
||||||
|
set(additional_project_sources myobject.cpp)
|
||||||
|
set(main_cpp_includes "#include \"myobject.h\"")
|
||||||
|
configure_file("${testProjectTemplateDir}/CMakeLists.txt.in" "${testProjectSrc}/CMakeLists.txt"
|
||||||
|
@ONLY)
|
||||||
|
configure_file("${testProjectTemplateDir}/main.cpp.in" "${testProjectSrc}/main.cpp" @ONLY)
|
||||||
|
configure_file("${testProjectTemplateDir}/myobject.h" "${testProjectSrc}/myobject.h" COPYONLY)
|
||||||
|
configure_file("${testProjectTemplateDir}/myobject.cpp" "${testProjectSrc}/myobject.cpp" COPYONLY)
|
||||||
|
rebuild(2)
|
||||||
|
|
||||||
|
# Sleep to ensure new timestamps
|
||||||
|
sleep()
|
||||||
|
|
||||||
|
# Add a QObject class (defined in source) to the project and build
|
||||||
|
set(additional_project_sources myobject.cpp anotherobject.cpp)
|
||||||
|
configure_file("${testProjectTemplateDir}/CMakeLists.txt.in" "${testProjectSrc}/CMakeLists.txt"
|
||||||
|
@ONLY)
|
||||||
|
configure_file("${testProjectTemplateDir}/anotherobject.cpp" "${testProjectSrc}/anotherobject.cpp"
|
||||||
|
COPYONLY)
|
||||||
|
rebuild(3)
|
@ -0,0 +1,9 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
project(MocOnAddFile)
|
||||||
|
include("@CMAKE_CURRENT_LIST_DIR@/../AutogenCoreTest.cmake")
|
||||||
|
|
||||||
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
set(CMAKE_AUTORCC ON)
|
||||||
|
|
||||||
|
add_executable(mocOnAddFile main.cpp @additional_project_sources@)
|
||||||
|
target_link_libraries(mocOnAddFile ${QT_QTCORE_TARGET})
|
@ -0,0 +1,15 @@
|
|||||||
|
#include <qobject.h>
|
||||||
|
|
||||||
|
class AnotherObject : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
AnotherObject() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
AnotherObject* createAnotherObject()
|
||||||
|
{
|
||||||
|
return new AnotherObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "anotherobject.moc"
|
@ -0,0 +1,6 @@
|
|||||||
|
@main_cpp_includes@
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
#include "myobject.h"
|
||||||
|
|
||||||
|
MyObject::MyObject(QObject* parent)
|
||||||
|
: QObject(parent)
|
||||||
|
{
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
#ifndef MYOBJECT_H
|
||||||
|
#define MYOBJECT_H
|
||||||
|
|
||||||
|
#include <qobject.h>
|
||||||
|
|
||||||
|
class MyObject : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
MyObject(QObject* parent = 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,80 @@
|
|||||||
|
# This test checks whether a missing dependency of the moc output triggers an AUTOMOC re-run.
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
project(RerunMocOnMissingDependency)
|
||||||
|
include("../AutogenCoreTest.cmake")
|
||||||
|
|
||||||
|
# Create an executable to generate a clean target
|
||||||
|
set(main_source "${CMAKE_CURRENT_BINARY_DIR}/generated_main.cpp")
|
||||||
|
file(WRITE "${main_source}" "int main() {}")
|
||||||
|
add_executable(exe "${main_source}")
|
||||||
|
|
||||||
|
# Utility variables
|
||||||
|
set(testProjectTemplateDir "${CMAKE_CURRENT_SOURCE_DIR}/MocOnMissingDependency")
|
||||||
|
set(testProjectSrc "${CMAKE_CURRENT_BINARY_DIR}/MocOnMissingDependency")
|
||||||
|
set(testProjectBinDir "${CMAKE_CURRENT_BINARY_DIR}/MocOnMissingDependency-build")
|
||||||
|
if(DEFINED Qt5Core_VERSION AND Qt5Core_VERSION VERSION_GREATER_EQUAL "5.15.0")
|
||||||
|
set(moc_depfiles_supported TRUE)
|
||||||
|
else()
|
||||||
|
set(moc_depfiles_supported FALSE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Utility macros
|
||||||
|
macro(sleep)
|
||||||
|
message(STATUS "Sleeping for a few seconds.")
|
||||||
|
execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
macro(rebuild buildName)
|
||||||
|
message(STATUS "Starting build ${buildName}.")
|
||||||
|
execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${testProjectBinDir}"
|
||||||
|
RESULT_VARIABLE result OUTPUT_VARIABLE output)
|
||||||
|
if (result)
|
||||||
|
message(FATAL_ERROR "Build ${buildName} failed.")
|
||||||
|
else()
|
||||||
|
message(STATUS "Build ${buildName} finished.")
|
||||||
|
endif()
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
# Create the test project from the template
|
||||||
|
file(COPY "${testProjectTemplateDir}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
|
||||||
|
configure_file("${testProjectTemplateDir}/CMakeLists.txt.in" "${testProjectSrc}/CMakeLists.txt" @ONLY)
|
||||||
|
|
||||||
|
# Initial build
|
||||||
|
file(REMOVE_RECURSE "${testProjectBinDir}")
|
||||||
|
try_compile(MOC_RERUN
|
||||||
|
"${testProjectBinDir}"
|
||||||
|
"${testProjectSrc}"
|
||||||
|
MocOnMissingDependency
|
||||||
|
CMAKE_FLAGS "-DQT_TEST_VERSION=${QT_TEST_VERSION}"
|
||||||
|
"-DCMAKE_AUTOGEN_VERBOSE=ON"
|
||||||
|
"-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}"
|
||||||
|
OUTPUT_VARIABLE output
|
||||||
|
)
|
||||||
|
if (NOT MOC_RERUN)
|
||||||
|
message(FATAL_ERROR "Initial build of mocOnMissingDependency failed. Output: ${output}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Sleep to ensure new timestamps
|
||||||
|
sleep()
|
||||||
|
|
||||||
|
if(moc_depfiles_supported)
|
||||||
|
# Remove the dependency inc1/foo.h and build again.
|
||||||
|
# We expect that the moc_XXX.cpp file gets re-generated. But only if we have depfile support.
|
||||||
|
file(REMOVE_RECURSE "${testProjectSrc}/inc1")
|
||||||
|
rebuild(2)
|
||||||
|
if(NOT output MATCHES "AutoMoc: Generating \"[^\"]*moc_myobject.cpp\"")
|
||||||
|
message(FATAL_ERROR "moc_myobject.cpp was not re-generated "
|
||||||
|
"after removing one of its dependencies")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Sleep to ensure new timestamps
|
||||||
|
sleep()
|
||||||
|
|
||||||
|
# The next build should *not* re-renerate any moc outputs
|
||||||
|
rebuild(3)
|
||||||
|
if(output MATCHES "AutoMoc: Generating")
|
||||||
|
message(FATAL_ERROR "moc_myobject.cpp was not re-generated "
|
||||||
|
"after removing one of its dependencies")
|
||||||
|
endif()
|
@ -0,0 +1,7 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.18)
|
||||||
|
project(MocOnMissingDependency)
|
||||||
|
include("@CMAKE_CURRENT_LIST_DIR@/../AutogenCoreTest.cmake")
|
||||||
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
add_executable(MocOnMissingDependency main.cpp myobject.cpp)
|
||||||
|
target_include_directories(MocOnMissingDependency PRIVATE inc1 inc2)
|
||||||
|
target_link_libraries(MocOnMissingDependency PRIVATE ${QT_QTCORE_TARGET})
|
@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
#include <qobject.h>
|
@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
#include <qobject.h>
|
@ -0,0 +1,9 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "myobject.h"
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
MyObject obj;
|
||||||
|
return 0;
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
#include "myobject.h"
|
||||||
|
|
||||||
|
MyObject::MyObject(QObject* parent)
|
||||||
|
: QObject(parent)
|
||||||
|
{
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <foo.h>
|
||||||
|
|
||||||
|
class MyObject : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
MyObject(QObject* parent = 0);
|
||||||
|
};
|
@ -0,0 +1,3 @@
|
|||||||
|
check_files("${RunCMake_TEST_BINARY_DIR}"
|
||||||
|
INCLUDE
|
||||||
|
)
|
@ -0,0 +1,5 @@
|
|||||||
|
check_files("${RunCMake_TEST_BINARY_DIR}"
|
||||||
|
INCLUDE
|
||||||
|
${TARGET_BYPRODUCTS_LeafExe}
|
||||||
|
${TARGET_BYPRODUCTS_RootCustom}
|
||||||
|
)
|
@ -0,0 +1,6 @@
|
|||||||
|
check_files("${RunCMake_TEST_BINARY_DIR}"
|
||||||
|
INCLUDE
|
||||||
|
${TARGET_BYPRODUCTS_LeafCustom}
|
||||||
|
${TARGET_BYPRODUCTS_RootCustom}
|
||||||
|
${TARGET_FILE_RootExe_Release}
|
||||||
|
)
|
@ -0,0 +1,7 @@
|
|||||||
|
check_files("${RunCMake_TEST_BINARY_DIR}"
|
||||||
|
INCLUDE
|
||||||
|
${TARGET_FILE_LeafExe_Release}
|
||||||
|
${TARGET_BYPRODUCTS_LeafExe}
|
||||||
|
${TARGET_BYPRODUCTS_RootCustom}
|
||||||
|
${TARGET_FILE_RootExe_Release}
|
||||||
|
)
|
@ -0,0 +1,7 @@
|
|||||||
|
input: CUSTOM_COMMAND(
|
||||||
|
[^
|
||||||
|
]*)*
|
||||||
|
\|\| exe_autogen_timestamp_deps:Debug(
|
||||||
|
[^
|
||||||
|
]*)*
|
||||||
|
outputs:
|
@ -0,0 +1 @@
|
|||||||
|
1
|
@ -0,0 +1,4 @@
|
|||||||
|
^CMake Error at foreach-RANGE-out-of-range-test\.cmake:[0-9]+ \(foreach\):
|
||||||
|
foreach Integer out of range: '10000000000000000000'
|
||||||
|
Call Stack \(most recent call first\):
|
||||||
|
CMakeLists\.txt:3 \(include\)$
|
@ -0,0 +1,3 @@
|
|||||||
|
foreach(a RANGE 10000000000000000000)
|
||||||
|
break()
|
||||||
|
endforeach()
|
@ -0,0 +1,30 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.18)
|
||||||
|
|
||||||
|
project(TestMultipleFiles CXX)
|
||||||
|
|
||||||
|
find_package(SWIG REQUIRED)
|
||||||
|
include(UseSWIG)
|
||||||
|
|
||||||
|
unset(SWIG_LANG_TYPE)
|
||||||
|
unset(SWIG_LANG_INCLUDE_DIRECTORIES)
|
||||||
|
unset(SWIG_LANG_DEFINITIONS)
|
||||||
|
unset(SWIG_LANG_OPTIONS)
|
||||||
|
unset(SWIG_LANG_LIBRARIES)
|
||||||
|
|
||||||
|
find_package(Python3 REQUIRED COMPONENTS Development)
|
||||||
|
|
||||||
|
set_property(SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/add.i" PROPERTY CPLUSPLUS ON)
|
||||||
|
set_property(SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/sub.i" PROPERTY CPLUSPLUS ON)
|
||||||
|
set_property(SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/add.i" PROPERTY SWIG_MODULE_NAME _add)
|
||||||
|
set_property(SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/sub.i" PROPERTY SWIG_MODULE_NAME _sub)
|
||||||
|
|
||||||
|
|
||||||
|
swig_add_library(example
|
||||||
|
LANGUAGE python
|
||||||
|
TYPE MODULE
|
||||||
|
SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/add.i"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/sub.i"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/add.cxx"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/sub.cxx")
|
||||||
|
target_include_directories(example PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||||
|
target_link_libraries(example PRIVATE Python3::Module)
|
@ -0,0 +1,6 @@
|
|||||||
|
#include "add.h"
|
||||||
|
|
||||||
|
int add(int a, int b)
|
||||||
|
{
|
||||||
|
return a + b;
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
int add(int a, int b);
|
@ -0,0 +1,4 @@
|
|||||||
|
%{
|
||||||
|
#include "add.h"
|
||||||
|
%}
|
||||||
|
%include "add.h"
|
@ -0,0 +1,6 @@
|
|||||||
|
#include "sub.h"
|
||||||
|
|
||||||
|
int sub(int a, int b)
|
||||||
|
{
|
||||||
|
return a - b;
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
int sub(int a, int b);
|
@ -0,0 +1,5 @@
|
|||||||
|
%{
|
||||||
|
#include "sub.h"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "sub.h"
|
Loading…
Reference in new issue