From 49e88c3ee9367c1db7b3a940a55c49bde7e099fb Mon Sep 17 00:00:00 2001 From: Nils Wentzell Date: Wed, 21 Feb 2024 17:41:05 -0500 Subject: [PATCH] [cmake] Overhaul of cmake files and project structure --- CMakeLists.txt | 177 +++++++++++------------- requirements.txt | 3 - share/CMakeLists.txt | 26 +++- share/c2py.modulefile.in | 4 +- share/cmake/CMakeLists.txt | 12 +- src/CMakeLists.txt | 3 - src/c2py/CMakeLists.txt | 84 +++++++---- test/CMakeLists.txt | 62 ++++++++- test/{c2py => }/annote.cpp | 0 test/{c2py => }/annote.wrap.cxx | 0 test/{c2py => }/annote_test.py | 0 test/{c2py => }/basicfun.cpp | 0 test/{c2py => }/basicfun.cpp.cxx | 0 test/{c2py => }/basicfun.cxx | 0 test/{c2py => }/basicfun.wrap.cxx | 0 test/{c2py => }/basicfun_test.py | 0 test/c2py/CMakeLists.txt | 66 --------- test/{c2py => }/callables.cpp | 0 test/{c2py => }/callables.wrap.cxx | 0 test/{c2py => }/callables_test.py | 0 test/{c2py => }/callback.cpp | 0 test/{c2py => }/callback.wrap.cxx | 0 test/{c2py => }/callback_test.py | 0 test/{c2py => }/cls.cpp | 0 test/{c2py => }/cls.cxx | 0 test/{c2py => }/cls_basic.cpp | 0 test/{c2py => }/cls_basic.wrap.cxx | 0 test/{c2py => }/cls_basic_test.py | 0 test/{c2py => }/cls_der.cpp | 0 test/{c2py => }/cls_der.cxx | 0 test/{c2py => }/cls_der.wrap.cxx | 0 test/{c2py => }/cls_der_test.py | 0 test/{c2py => }/cls_test.py | 0 test/{c2py => }/comparison.cpp | 0 test/{c2py => }/comparison.wrap.cxx | 0 test/{c2py => }/comparison_test.py | 0 test/{c2py => }/cppcoro/generator.hpp | 0 test/{c2py => }/enumcxx.cpp | 0 test/{c2py => }/enumcxx.wrap.cxx | 0 test/{c2py => }/enumcxx_test.py | 0 test/{c2py => }/generator.cpp | 0 test/{c2py => }/generator.wrap.cxx | 0 test/{c2py => }/generator_test.py | 0 test/{c2py => }/h5_storable_test.py | 0 test/{c2py => }/issue9.cpp | 0 test/{c2py => }/issue9.wrap.cxx | 0 test/{c2py => }/issue9_test.py | 0 test/{c2py => }/itertool.cpp | 0 test/{c2py => }/itertool.wrap.cxx | 0 test/{c2py => }/itertool_test.py | 0 test/{c2py => }/itertools/itertools.hpp | 0 test/{c2py => }/synth_init.cpp | 0 test/{c2py => }/synth_init.wrap.cxx | 0 test/{c2py => }/synth_init_test.py | 0 test/{c2py => }/tpl_cls.cpp | 0 test/{c2py => }/tpl_cls.wrap.cxx | 0 test/{c2py => }/tpl_cls_test.py | 0 test/{c2py => }/tpl_derived.cpp | 0 test/{c2py => }/tpl_derived.wrap.cxx | 0 test/{c2py => }/tpl_derived_test.py | 0 test/{c2py => }/two_module_1.cpp | 0 test/{c2py => }/two_module_1.hpp | 0 test/{c2py => }/two_module_1.wrap.cxx | 0 test/{c2py => }/two_module_1.wrap.hxx | 0 test/{c2py => }/two_module_1_test.py | 0 test/{c2py => }/two_module_2.cpp | 0 test/{c2py => }/two_module_2.wrap.cxx | 0 test/{c2py => }/two_module_2_test.py | 0 68 files changed, 225 insertions(+), 212 deletions(-) delete mode 100644 requirements.txt delete mode 100644 src/CMakeLists.txt rename test/{c2py => }/annote.cpp (100%) rename test/{c2py => }/annote.wrap.cxx (100%) rename test/{c2py => }/annote_test.py (100%) rename test/{c2py => }/basicfun.cpp (100%) rename test/{c2py => }/basicfun.cpp.cxx (100%) rename test/{c2py => }/basicfun.cxx (100%) rename test/{c2py => }/basicfun.wrap.cxx (100%) rename test/{c2py => }/basicfun_test.py (100%) delete mode 100644 test/c2py/CMakeLists.txt rename test/{c2py => }/callables.cpp (100%) rename test/{c2py => }/callables.wrap.cxx (100%) rename test/{c2py => }/callables_test.py (100%) rename test/{c2py => }/callback.cpp (100%) rename test/{c2py => }/callback.wrap.cxx (100%) rename test/{c2py => }/callback_test.py (100%) rename test/{c2py => }/cls.cpp (100%) rename test/{c2py => }/cls.cxx (100%) rename test/{c2py => }/cls_basic.cpp (100%) rename test/{c2py => }/cls_basic.wrap.cxx (100%) rename test/{c2py => }/cls_basic_test.py (100%) rename test/{c2py => }/cls_der.cpp (100%) rename test/{c2py => }/cls_der.cxx (100%) rename test/{c2py => }/cls_der.wrap.cxx (100%) rename test/{c2py => }/cls_der_test.py (100%) rename test/{c2py => }/cls_test.py (100%) rename test/{c2py => }/comparison.cpp (100%) rename test/{c2py => }/comparison.wrap.cxx (100%) rename test/{c2py => }/comparison_test.py (100%) rename test/{c2py => }/cppcoro/generator.hpp (100%) rename test/{c2py => }/enumcxx.cpp (100%) rename test/{c2py => }/enumcxx.wrap.cxx (100%) rename test/{c2py => }/enumcxx_test.py (100%) rename test/{c2py => }/generator.cpp (100%) rename test/{c2py => }/generator.wrap.cxx (100%) rename test/{c2py => }/generator_test.py (100%) rename test/{c2py => }/h5_storable_test.py (100%) rename test/{c2py => }/issue9.cpp (100%) rename test/{c2py => }/issue9.wrap.cxx (100%) rename test/{c2py => }/issue9_test.py (100%) rename test/{c2py => }/itertool.cpp (100%) rename test/{c2py => }/itertool.wrap.cxx (100%) rename test/{c2py => }/itertool_test.py (100%) rename test/{c2py => }/itertools/itertools.hpp (100%) rename test/{c2py => }/synth_init.cpp (100%) rename test/{c2py => }/synth_init.wrap.cxx (100%) rename test/{c2py => }/synth_init_test.py (100%) rename test/{c2py => }/tpl_cls.cpp (100%) rename test/{c2py => }/tpl_cls.wrap.cxx (100%) rename test/{c2py => }/tpl_cls_test.py (100%) rename test/{c2py => }/tpl_derived.cpp (100%) rename test/{c2py => }/tpl_derived.wrap.cxx (100%) rename test/{c2py => }/tpl_derived_test.py (100%) rename test/{c2py => }/two_module_1.cpp (100%) rename test/{c2py => }/two_module_1.hpp (100%) rename test/{c2py => }/two_module_1.wrap.cxx (100%) rename test/{c2py => }/two_module_1.wrap.hxx (100%) rename test/{c2py => }/two_module_1_test.py (100%) rename test/{c2py => }/two_module_2.cpp (100%) rename test/{c2py => }/two_module_2.wrap.cxx (100%) rename test/{c2py => }/two_module_2_test.py (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 768abf9..83a0a82 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,84 +4,82 @@ if(POLICY CMP0144) cmake_policy(SET CMP0144 NEW) endif() -# +# ############ +# Define Project project(c2py VERSION 0.1.0 LANGUAGES C CXX) get_directory_property(IS_SUBPROJECT PARENT_DIRECTORY) -include(CheckIncludeFile) -include(CheckIncludeFileCXX) -# Default to Release build type -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Release CACHE STRING "Type of build" FORCE) -endif() -message(STATUS "-------- BUILD-TYPE: ${CMAKE_BUILD_TYPE} -------------") - -# CXX options -set(CMAKE_CXX_EXTENSIONS OFF) -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -# Global compiler options -option(BUILD_SHARED_LIBS "Enable compilation of shared libraries" OFF) -add_compile_options($<$:-ggdb3>) +message(STATUS "-------- c2py version and git hash detection -------------") +find_package(Git) +execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + OUTPUT_VARIABLE PROJECT_GIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE +) +message(STATUS "c2py version : ${PROJECT_VERSION}") +message(STATUS "c2py Git hash: ${PROJECT_GIT_HASH}") -# Check CMAKE_INSTALL_PREFIX : must be provided and absolute +# Assert that install directory is provided and is absolute path. +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT OR (NOT IS_ABSOLUTE ${CMAKE_INSTALL_PREFIX})) + message(FATAL_ERROR "CMAKE_INSTALL_PREFIX must be specified and must be an absolute path.\n There is no default.\n Current value : ${CMAKE_INSTALL_PREFIX}\n. e.g. ... -DCMAKE_INSTALL_PREFIX=$HOME/clair_install") +endif() if(NOT IS_SUBPROJECT) - if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT OR (NOT IS_ABSOLUTE ${CMAKE_INSTALL_PREFIX})) - message(FATAL_ERROR "CMAKE_INSTALL_PREFIX must be specified and must be an absolute path.\n There is no default.\n Current value : ${CMAKE_INSTALL_PREFIX}\n. e.g. ... -DCMAKE_INSTALL_PREFIX=$HOME/c2py_install") - endif() - message(STATUS "Installation directory will be ${CMAKE_INSTALL_PREFIX}") + message(STATUS "-------- CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX} --------") endif() -set(C2PY_BINARY_DIR ${PROJECT_BINARY_DIR} CACHE STRING "Binary directory of the Clair Project") +set(c2py_BINARY_DIR ${PROJECT_BINARY_DIR} CACHE STRING "Binary directory of the c2py Project") -# add ./cmake to the path for module +# Make additional Find Modules available list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/share/cmake/Modules) -# log info -message( STATUS "-------- c2py version and git hash detection -------------") - -find_package(Git) +# ############ +# CMake Options -# Get the Git Hash -execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD - WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" - OUTPUT_VARIABLE PROJECT_GIT_HASH - OUTPUT_STRIP_TRAILING_WHITESPACE -) - -message(STATUS "${PROJECT_NAME} version : ${PROJECT_VERSION}") -message(STATUS "${PROJECT_NAME} Git hash: ${PROJECT_GIT_HASH}") +# Default to Release build type +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release CACHE STRING "Type of build" FORCE) +endif() +if(NOT IS_SUBPROJECT) + message(STATUS "-------- BUILD-TYPE: ${CMAKE_BUILD_TYPE} --------") +endif() -# --- Python --- -find_package(Python COMPONENTS Interpreter Development NumPy) -set(c2py_all_python_flags " -I${Python_INCLUDE_DIRS} -I${Python_NumPy_INCLUDE_DIRS} -L${Python_LIBRARY_DIRS} -lpython${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}") -configure_file(c2py_flags.py.in c2py_flags @ONLY) +# Testing +option(Build_Tests "Build tests" ON) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/c2py_flags DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) +# ############ +# Global Compilation Settings -# Set binary dir -set(${PROJECT_NAME}_BINARY_DIR ${PROJECT_BINARY_DIR} CACHE STRING "Binary directory of the ${PROJECT_NAME} Project") +# Build static libraries by default +option(BUILD_SHARED_LIBS "Enable compilation of shared libraries" OFF) # Export the list of compile-commands into compile_commands.json set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +# Disable compiler extensions +set(CMAKE_CXX_EXTENSIONS OFF) + +# Provide additional debugging information for Debug builds +add_compile_options($<$:-ggdb3>) + # Create an Interface target for compiler warnings -add_library(${PROJECT_NAME}_warnings INTERFACE) -target_compile_options(${PROJECT_NAME}_warnings +add_library(c2py_warnings INTERFACE) +target_compile_options(c2py_warnings INTERFACE -Wall -Wextra + -Wfloat-conversion -Wpedantic -Wno-sign-compare + $<$:-Wno-comma-subscript> $<$:-Wshadow=local> $<$:-Wno-attributes> - $<$:-Wshadow> - $<$:-Wno-gcc-compat> - $<$:-Wno-unused-parameter> - $<$:-Wno-unused-const-variable> - $<$:-Wno-unused-variable> - $<$:-Wshadow> - $<$:-Wno-gcc-compat> + $<$:-Wno-deprecated-declarations> + $<$:-Wno-deprecated-comma-subscript> + $<$:-Wno-unknown-warning-option> + $<$:-Wshadow> + $<$:-Wno-gcc-compat> + $<$:-Wno-c++20-extensions> + $<$:-Wno-c++20-compat> + $<$:-Wno-tautological-constant-compare> ) # --------------------------------- @@ -92,8 +90,9 @@ target_compile_options(${PROJECT_NAME}_warnings # The clang linker however ignores LIBRARY_PATH. # We thus explicitly add the content of LIBRARY_PATH to the LDFLAGS # FIXME For future cmake versions we should populate the +# INTERFACE_LINK_DIRECTORIES of the target # --------------------------------- -if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND DEFINED ENV{LIBRARY_PATH}) +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND DEFINED ENV{LIBRARY_PATH}) string(REPLACE ":" ";" LINK_DIRS $ENV{LIBRARY_PATH}) foreach(dir ${LINK_DIRS}) string(APPEND CMAKE_SHARED_LINKER_FLAGS " -L${dir}") @@ -102,16 +101,32 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND DEFINED ENV{LIBRARY_PATH}) endforeach() endif() -add_subdirectory(src) -add_subdirectory(share) # Exported Clair-Config +# Provide GNU Installation directories +include(GNUInstallDirs) -option(Build_Tests "Build tests" ON) -if (Build_Tests AND (NOT IS_SUBPROJECT OR IS_CLAIR_BUILD)) - set(H5_INCLUDE_DIR ${CMAKE_BINARY_DIR}/deps/h5_src/c++/) - enable_testing() - add_subdirectory(test) +# Python +message(STATUS "-------- Python detection -------------") +find_package(Python COMPONENTS Interpreter Development NumPy) +set(c2py_all_python_flags " -I${Python_INCLUDE_DIRS} -I${Python_NumPy_INCLUDE_DIRS} -L${Python_LIBRARY_DIRS} -lpython${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}") +configure_file(c2py_flags.py.in c2py_flags @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/c2py_flags DESTINATION ${CMAKE_INSTALL_BINDIR} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) + +# ############# +# Build Project + +# Build and install the library +add_subdirectory(src/c2py) + +# Tests +if(Build_Tests AND NOT IS_SUBPROJECT) + set(H5_INCLUDE_DIR ${PROJECT_BINARY_DIR}/deps/h5_src/c++/) + enable_testing() + add_subdirectory(test) endif() +# Additional configuration files +add_subdirectory(share) + #-------------------------------------------------------- # Sanitizers #-------------------------------------------------------- @@ -130,50 +145,18 @@ if(UBSAN) endif() endif() -#-------------------------------------------------------- -# Remind the user how to set up his/her variables -#-------------------------------------------------------- +# ############# +# Debian Package -if(NOT IS_SUBPROJECT - AND NOT CMAKE_INSTALL_PREFIX STREQUAL "/usr" - AND NOT CMAKE_INSTALL_PREFIX STREQUAL "/usr/local" -) - # Configure and install the file to source to setup the environment variables - message(STATUS "***************************************************************") - message(STATUS "* Use : ") - message(STATUS "* source ${CMAKE_INSTALL_PREFIX}/share/c2py/c2pyvars.sh ") - message(STATUS "* to set up the environment variables ") - if(DEFINED ENV{MODULEPATH}) - message(STATUS "* ") - message(STATUS "* Consider copying ${CMAKE_CURRENT_BINARY_DIR}/c2py.modulefile ") - message(STATUS "* into your environment module directories ") - endif() - message(STATUS "***************************************************************") -endif() - -# uninstall target -#if(NOT TARGET uninstall) - #configure_file( - #"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" - #"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" - #IMMEDIATE @ONLY) - - #add_custom_target(uninstall - #COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) -#endif() - -#-------------------------------------------------------- -# Packaging -#-------------------------------------------------------- option(BUILD_DEBIAN_PACKAGE "Build a deb package" OFF) -if(BUILD_DEBIAN_PACKAGE) +if(BUILD_DEBIAN_PACKAGE AND NOT IS_SUBPROJECT) if(NOT CMAKE_INSTALL_PREFIX STREQUAL "/usr") message(FATAL_ERROR "CMAKE_INSTALL_PREFIX must be /usr for packaging") endif() set(CPACK_PACKAGE_NAME c2py) set(CPACK_GENERATOR "DEB") set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) - set(CPACK_PACKAGE_CONTACT "https://github.com/TRIQS/c2py") + set(CPACK_PACKAGE_CONTACT "https://github.com/flatironinstitute/c2py") execute_process(COMMAND dpkg --print-architecture OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE OUTPUT_STRIP_TRAILING_WHITESPACE) set(CPACK_DEBIAN_PACKAGE_DEPENDS "python") SET(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index abc0fd0..0000000 --- a/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -# Required python packages for this application (these should also be added to Dockerfile for Jenkins) -numpy -scipy diff --git a/share/CMakeLists.txt b/share/CMakeLists.txt index 1ad5883..ce8f29f 100644 --- a/share/CMakeLists.txt +++ b/share/CMakeLists.txt @@ -1,15 +1,31 @@ add_subdirectory(cmake) -if(NOT CMAKE_INSTALL_PREFIX STREQUAL TRIQS_ROOT AND NOT IS_SUBPROJECT) +if(NOT IS_SUBPROJECT + AND NOT CMAKE_INSTALL_PREFIX STREQUAL "/usr" + AND NOT CMAKE_INSTALL_PREFIX STREQUAL "/usr/local" +) - configure_file(${PROJECT_NAME}.modulefile.in ${PROJECT_NAME}.modulefile @ONLY) - configure_file(${PROJECT_NAME}vars.sh.in ${PROJECT_NAME}vars.sh @ONLY) + configure_file(c2py.modulefile.in c2py.modulefile @ONLY) + configure_file(c2pyvars.sh.in c2pyvars.sh @ONLY) install( FILES - ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.modulefile - ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}vars.sh + ${CMAKE_CURRENT_BINARY_DIR}/c2py.modulefile + ${CMAKE_CURRENT_BINARY_DIR}/c2pyvars.sh DESTINATION share/c2py ) + + message(STATUS "*********************************************************************************") + message(STATUS "* Custom install Location. Use: ") + message(STATUS "* ") + message(STATUS "* source ${CMAKE_INSTALL_PREFIX}/share/c2py/c2pyvars.sh ") + message(STATUS "* ") + message(STATUS "* to set up the environment variables ") + if(DEFINED ENV{MODULEPATH}) + message(STATUS "* ") + message(STATUS "* Consider copying ${CMAKE_CURRENT_BINARY_DIR}/c2py.modulefile ") + message(STATUS "* into your environment module directories ") + endif() + message(STATUS "*********************************************************************************") endif() diff --git a/share/c2py.modulefile.in b/share/c2py.modulefile.in index 488cfd4..f03fe63 100644 --- a/share/c2py.modulefile.in +++ b/share/c2py.modulefile.in @@ -7,8 +7,8 @@ set version @C2PY_VERSION@ set root @CMAKE_INSTALL_PREFIX@ set git_hash @C2PY_GIT_HASH@ -set url "https://github.com/TRIQS/c2py" -set description "Cpp2Py is the Python/C++ interfacing tool of the TRIQS project" +set url "https://github.com/flatironinstitute/c2py" +set description "Cpp2Py is a Python/C++ interfacing library" module-whatis "$description" diff --git a/share/cmake/CMakeLists.txt b/share/cmake/CMakeLists.txt index c9f9d6c..46e85eb 100644 --- a/share/cmake/CMakeLists.txt +++ b/share/cmake/CMakeLists.txt @@ -1,10 +1,10 @@ -configure_file(${PROJECT_NAME}-config.cmake.in ${PROJECT_NAME}-config.cmake @ONLY) -configure_file(${PROJECT_NAME}-config-version.cmake.in ${PROJECT_NAME}-config-version.cmake @ONLY) +configure_file(c2py-config.cmake.in c2py-config.cmake @ONLY) +configure_file(c2py-config-version.cmake.in c2py-config-version.cmake @ONLY) install( FILES - ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake - ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake - DESTINATION lib/cmake/${PROJECT_NAME} + ${CMAKE_CURRENT_BINARY_DIR}/c2py-config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/c2py-config-version.cmake + DESTINATION lib/cmake/c2py ) -#install(EXPORT ${PROJECT_NAME}-targets NAMESPACE ${PROJECT_NAME}:: DESTINATION lib/cmake/${PROJECT_NAME}) +install(EXPORT c2py-targets NAMESPACE c2py:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/c2py) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt deleted file mode 100644 index 5da26c8..0000000 --- a/src/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -add_subdirectory(c2py) - - diff --git a/src/c2py/CMakeLists.txt b/src/c2py/CMakeLists.txt index 5c2b2cc..3dd1b2d 100644 --- a/src/c2py/CMakeLists.txt +++ b/src/c2py/CMakeLists.txt @@ -1,39 +1,65 @@ -add_library(c2py_obj OBJECT pyref.cpp pyfunction.cpp dyn_dispatch/pycfun_kw.cpp - converters/wrapped.cpp converters/numpy_proxy.cpp) - -target_compile_features(c2py_obj PRIVATE cxx_std_20) -set_property(TARGET c2py_obj PROPERTY POSITION_INDEPENDENT_CODE ON) - -target_include_directories(c2py_obj - PUBLIC - $ - $ - ) - -target_link_libraries(c2py_obj PRIVATE ${PROJECT_NAME}_warnings) -target_link_libraries(c2py_obj PUBLIC Python::NumPy Python::Python) - -add_library(c2py STATIC $) +file(GLOB_RECURSE sources *.cpp) +add_library(c2py ${sources}) add_library(c2py::c2py ALIAS c2py) -target_include_directories(c2py - PUBLIC - $ - $ - ) +# Enable warnings +target_link_libraries(c2py PRIVATE $) -# Disable the inclusion of the deprecated Numpy API headers starting from 1.8.0. This seems to be buggy for earlier versions. +# Configure target and compilation +target_compile_features(c2py PUBLIC cxx_std_20) +set_target_properties(c2py PROPERTIES + POSITION_INDEPENDENT_CODE ON + VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} +) +target_include_directories(c2py PUBLIC $) +target_include_directories(c2py SYSTEM INTERFACE $) + +# Disable the inclusion of the deprecated Numpy API headers starting from 1.8.0. if(Python_NumPy_VERSION VERSION_GREATER "1.8.0") - set_property(TARGET c2py PROPERTY INTERFACE_COMPILE_DEFINITIONS NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION) - target_compile_definitions(c2py_obj PUBLIC NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION) + target_compile_definitions(c2py PUBLIC NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION) endif() +# Install library and headers +install(TARGETS c2py EXPORT c2py-targets DESTINATION ${CMAKE_INSTALL_LIBDIR}) +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN "*.hpp" PATTERN "*.h") + +# ========= Additional Depdencies ========== + +# Python and Numpy target_link_libraries(c2py PUBLIC Python::NumPy Python::Python) -# Install the library in lib and export the c2py target -install(TARGETS c2py EXPORT c2py-targets DESTINATION lib) -install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION include FILES_MATCHING PATTERN "*.hpp" PATTERN "*.h") -# Install the exported targets -install(EXPORT c2py-targets NAMESPACE c2py:: DESTINATION lib/cmake/c2py) +# ========= Dynamic Analyzer Checks ========== + +option(ASAN OFF "Compile library and executables with LLVM Address Sanitizer") +if(ASAN) + if(NOT TARGET asan) + find_package(sanitizer REQUIRED COMPONENTS asan) + endif() + target_link_libraries(c2py PUBLIC $) +endif() + +option(UBSAN OFF "Compile library and executables with LLVM Undefined Behavior Sanitizer") +if(UBSAN) + if(NOT TARGET ubsan) + find_package(sanitizer REQUIRED COMPONENTS ubsan) + endif() + target_link_libraries(c2py PUBLIC $) +endif() + +option(MSAN OFF "Compile library and executables with LLVM Memory Sanitizer") +if(MSAN) + if(NOT TARGET msan) + find_package(sanitizer REQUIRED COMPONENTS msan) + endif() + target_link_libraries(c2py PUBLIC $) +endif() + +option(TSAN OFF "Compile library and executables with LLVM Thread Sanitizer") +if(TSAN) + if(NOT TARGET tsan) + find_package(sanitizer REQUIRED COMPONENTS tsan) + endif() + target_link_libraries(c2py PUBLIC $) +endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8c734a2..32b689e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1 +1,61 @@ -add_subdirectory(c2py) +# For clair plugin testing we need to add the LD_PRELOAD for the compilation ITSELF +if (IS_CLAIR_BUILD AND (ASAN OR UBSAN)) + message(STATUS "Adding LD_PRELOAD to the compilation to check clair plugin") + message(STATUS "SANITIZER_RT_PRELOAD = ${SANITIZER_RT_PRELOAD}") + set(CMAKE_CXX_COMPILER_LAUNCHER env ${SANITIZER_RT_PRELOAD}) +endif() + +macro(c2py_add_test_1 modulename module_extension) + get_filename_component(test_name ${modulename} NAME_WE) + get_filename_component(test_dir ${modulename} DIRECTORY) + Python_add_library(${modulename} MODULE ${modulename}.${module_extension}) + target_link_libraries(${modulename} PRIVATE c2py c2py_warnings) + add_test(NAME ${modulename}_py COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${test_dir}/${modulename}_test.py WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${test_dir}) + set_property(TEST ${modulename}_py APPEND PROPERTY ENVIRONMENT PYTHONPATH=${h5_BINARY_DIR}/python:${CMAKE_CURRENT_BINARY_DIR}:$ENV{PYTHONPATH} ${SANITIZER_RT_PRELOAD}) +endmacro() + +macro(c2py_add_test modulename) + c2py_add_test_1(${modulename} $,cpp,wrap.cxx>) + target_link_libraries(${modulename} PRIVATE $) +endmacro() + +#-------------------------------------------------------- +# A target to copy the wrap.cxx files back to the src +#-------------------------------------------------------- + +add_custom_target(c2py_copy_wrap_cxx_to_src) +add_custom_command( + TARGET c2py_copy_wrap_cxx_to_src + COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/*.wrap.?xx ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND echo "** Copying all wrap.cxx to c2py test" +) + +# ---------------------------- +set(c2py_all_low_level_tests cls) +set(c2py_all_full_tests + annote basicfun + cls_basic + cls_der + comparison + issue9 + callables + itertool + generator + enumcxx + synth_init + tpl_cls + tpl_derived + callback + two_module_1 + two_module_2) + +foreach(t ${c2py_all_low_level_tests}) + c2py_add_test_1(${t} "cxx") +endforeach() + +foreach(t ${c2py_all_full_tests}) + c2py_add_test(${t}) +endforeach() + +# must compile 1 first to have the hxx of the wrapped objects +add_dependencies(two_module_2 two_module_1) diff --git a/test/c2py/annote.cpp b/test/annote.cpp similarity index 100% rename from test/c2py/annote.cpp rename to test/annote.cpp diff --git a/test/c2py/annote.wrap.cxx b/test/annote.wrap.cxx similarity index 100% rename from test/c2py/annote.wrap.cxx rename to test/annote.wrap.cxx diff --git a/test/c2py/annote_test.py b/test/annote_test.py similarity index 100% rename from test/c2py/annote_test.py rename to test/annote_test.py diff --git a/test/c2py/basicfun.cpp b/test/basicfun.cpp similarity index 100% rename from test/c2py/basicfun.cpp rename to test/basicfun.cpp diff --git a/test/c2py/basicfun.cpp.cxx b/test/basicfun.cpp.cxx similarity index 100% rename from test/c2py/basicfun.cpp.cxx rename to test/basicfun.cpp.cxx diff --git a/test/c2py/basicfun.cxx b/test/basicfun.cxx similarity index 100% rename from test/c2py/basicfun.cxx rename to test/basicfun.cxx diff --git a/test/c2py/basicfun.wrap.cxx b/test/basicfun.wrap.cxx similarity index 100% rename from test/c2py/basicfun.wrap.cxx rename to test/basicfun.wrap.cxx diff --git a/test/c2py/basicfun_test.py b/test/basicfun_test.py similarity index 100% rename from test/c2py/basicfun_test.py rename to test/basicfun_test.py diff --git a/test/c2py/CMakeLists.txt b/test/c2py/CMakeLists.txt deleted file mode 100644 index 8735974..0000000 --- a/test/c2py/CMakeLists.txt +++ /dev/null @@ -1,66 +0,0 @@ -#FILE(COPY ${CMAKE_SOURCE_DIR}/.clang-format DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) - -# I have no clue why it is needed, but it is for the test to PRELOAD properly ? -if (ASAN) - find_package(sanitizer REQUIRED "asan") - MESSAGE(STATUS "SANITIZER_RT_PRELOAD = ${SANITIZER_RT_PRELOAD}") - - # We need to add the LD_PRELOAD for the compilation ITSELF - # When we are testing the clair plugin - if (IS_CLAIR_BUILD) - set(CMAKE_CXX_COMPILER_LAUNCHER env ${SANITIZER_RT_PRELOAD}) - MESSAGE(STATUS "Adding LD_PRELOAD to the compilation to check clair plugin") - endif() -endif() - -macro(c2py_add_test_1 modulename module_extension) - - Python_add_library( ${modulename} MODULE "${modulename}.${module_extension}") - target_compile_options(${modulename} PRIVATE -std=c++20 ) - target_include_directories(${modulename} SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/src) - target_link_libraries(${modulename} PRIVATE c2py ${PROJECT_NAME}_warnings Python::NumPy) - -if(ASAN) - target_link_libraries(${modulename} PRIVATE $) -endif() -if(UBSAN) - target_link_libraries(${modulename} PRIVATE $) -endif() - - get_filename_component(test_name ${modulename} NAME_WE) - get_filename_component(test_dir ${modulename} DIRECTORY) - add_test(NAME ${modulename}_py COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${test_dir}/${modulename}_test.py WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${test_dir}) - set_property(TEST ${modulename}_py APPEND PROPERTY ENVIRONMENT PYTHONPATH=${h5_BINARY_DIR}/python:${CMAKE_CURRENT_BINARY_DIR}:$ENV{PYTHONPATH} ${SANITIZER_RT_PRELOAD}) -endmacro() - -macro(c2py_add_test modulename) - c2py_add_test_1(${modulename} $,cpp,wrap.cxx>) - target_link_libraries(${modulename} PRIVATE $) -endmacro() - -#-------------------------------------------------------- -# A target to copy the wrap.cxx files back to the src -#-------------------------------------------------------- - -add_custom_target(c2py_copy_wrap_cxx_to_src) -add_custom_command( - TARGET c2py_copy_wrap_cxx_to_src - COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/*.wrap.?xx ${CMAKE_CURRENT_SOURCE_DIR} - COMMAND echo "** Copying all wrap.cxx to c2py test" -) - -# ---------------------------- -set(c2py_all_low_level_tests cls CACHE INTERNAL "") -set(c2py_all_full_tests annote basicfun cls_basic cls_der comparison issue9 callables itertool generator - enumcxx synth_init tpl_cls tpl_derived callback two_module_1 two_module_2 CACHE INTERNAL "") - -foreach(t ${c2py_all_low_level_tests} ) - c2py_add_test_1(${t} "cxx") -endforeach() - -foreach(t ${c2py_all_full_tests} ) - c2py_add_test(${t}) -endforeach() - -# must compile 1 first to have the hxx of the wrapped objects -add_dependencies(two_module_2 two_module_1) diff --git a/test/c2py/callables.cpp b/test/callables.cpp similarity index 100% rename from test/c2py/callables.cpp rename to test/callables.cpp diff --git a/test/c2py/callables.wrap.cxx b/test/callables.wrap.cxx similarity index 100% rename from test/c2py/callables.wrap.cxx rename to test/callables.wrap.cxx diff --git a/test/c2py/callables_test.py b/test/callables_test.py similarity index 100% rename from test/c2py/callables_test.py rename to test/callables_test.py diff --git a/test/c2py/callback.cpp b/test/callback.cpp similarity index 100% rename from test/c2py/callback.cpp rename to test/callback.cpp diff --git a/test/c2py/callback.wrap.cxx b/test/callback.wrap.cxx similarity index 100% rename from test/c2py/callback.wrap.cxx rename to test/callback.wrap.cxx diff --git a/test/c2py/callback_test.py b/test/callback_test.py similarity index 100% rename from test/c2py/callback_test.py rename to test/callback_test.py diff --git a/test/c2py/cls.cpp b/test/cls.cpp similarity index 100% rename from test/c2py/cls.cpp rename to test/cls.cpp diff --git a/test/c2py/cls.cxx b/test/cls.cxx similarity index 100% rename from test/c2py/cls.cxx rename to test/cls.cxx diff --git a/test/c2py/cls_basic.cpp b/test/cls_basic.cpp similarity index 100% rename from test/c2py/cls_basic.cpp rename to test/cls_basic.cpp diff --git a/test/c2py/cls_basic.wrap.cxx b/test/cls_basic.wrap.cxx similarity index 100% rename from test/c2py/cls_basic.wrap.cxx rename to test/cls_basic.wrap.cxx diff --git a/test/c2py/cls_basic_test.py b/test/cls_basic_test.py similarity index 100% rename from test/c2py/cls_basic_test.py rename to test/cls_basic_test.py diff --git a/test/c2py/cls_der.cpp b/test/cls_der.cpp similarity index 100% rename from test/c2py/cls_der.cpp rename to test/cls_der.cpp diff --git a/test/c2py/cls_der.cxx b/test/cls_der.cxx similarity index 100% rename from test/c2py/cls_der.cxx rename to test/cls_der.cxx diff --git a/test/c2py/cls_der.wrap.cxx b/test/cls_der.wrap.cxx similarity index 100% rename from test/c2py/cls_der.wrap.cxx rename to test/cls_der.wrap.cxx diff --git a/test/c2py/cls_der_test.py b/test/cls_der_test.py similarity index 100% rename from test/c2py/cls_der_test.py rename to test/cls_der_test.py diff --git a/test/c2py/cls_test.py b/test/cls_test.py similarity index 100% rename from test/c2py/cls_test.py rename to test/cls_test.py diff --git a/test/c2py/comparison.cpp b/test/comparison.cpp similarity index 100% rename from test/c2py/comparison.cpp rename to test/comparison.cpp diff --git a/test/c2py/comparison.wrap.cxx b/test/comparison.wrap.cxx similarity index 100% rename from test/c2py/comparison.wrap.cxx rename to test/comparison.wrap.cxx diff --git a/test/c2py/comparison_test.py b/test/comparison_test.py similarity index 100% rename from test/c2py/comparison_test.py rename to test/comparison_test.py diff --git a/test/c2py/cppcoro/generator.hpp b/test/cppcoro/generator.hpp similarity index 100% rename from test/c2py/cppcoro/generator.hpp rename to test/cppcoro/generator.hpp diff --git a/test/c2py/enumcxx.cpp b/test/enumcxx.cpp similarity index 100% rename from test/c2py/enumcxx.cpp rename to test/enumcxx.cpp diff --git a/test/c2py/enumcxx.wrap.cxx b/test/enumcxx.wrap.cxx similarity index 100% rename from test/c2py/enumcxx.wrap.cxx rename to test/enumcxx.wrap.cxx diff --git a/test/c2py/enumcxx_test.py b/test/enumcxx_test.py similarity index 100% rename from test/c2py/enumcxx_test.py rename to test/enumcxx_test.py diff --git a/test/c2py/generator.cpp b/test/generator.cpp similarity index 100% rename from test/c2py/generator.cpp rename to test/generator.cpp diff --git a/test/c2py/generator.wrap.cxx b/test/generator.wrap.cxx similarity index 100% rename from test/c2py/generator.wrap.cxx rename to test/generator.wrap.cxx diff --git a/test/c2py/generator_test.py b/test/generator_test.py similarity index 100% rename from test/c2py/generator_test.py rename to test/generator_test.py diff --git a/test/c2py/h5_storable_test.py b/test/h5_storable_test.py similarity index 100% rename from test/c2py/h5_storable_test.py rename to test/h5_storable_test.py diff --git a/test/c2py/issue9.cpp b/test/issue9.cpp similarity index 100% rename from test/c2py/issue9.cpp rename to test/issue9.cpp diff --git a/test/c2py/issue9.wrap.cxx b/test/issue9.wrap.cxx similarity index 100% rename from test/c2py/issue9.wrap.cxx rename to test/issue9.wrap.cxx diff --git a/test/c2py/issue9_test.py b/test/issue9_test.py similarity index 100% rename from test/c2py/issue9_test.py rename to test/issue9_test.py diff --git a/test/c2py/itertool.cpp b/test/itertool.cpp similarity index 100% rename from test/c2py/itertool.cpp rename to test/itertool.cpp diff --git a/test/c2py/itertool.wrap.cxx b/test/itertool.wrap.cxx similarity index 100% rename from test/c2py/itertool.wrap.cxx rename to test/itertool.wrap.cxx diff --git a/test/c2py/itertool_test.py b/test/itertool_test.py similarity index 100% rename from test/c2py/itertool_test.py rename to test/itertool_test.py diff --git a/test/c2py/itertools/itertools.hpp b/test/itertools/itertools.hpp similarity index 100% rename from test/c2py/itertools/itertools.hpp rename to test/itertools/itertools.hpp diff --git a/test/c2py/synth_init.cpp b/test/synth_init.cpp similarity index 100% rename from test/c2py/synth_init.cpp rename to test/synth_init.cpp diff --git a/test/c2py/synth_init.wrap.cxx b/test/synth_init.wrap.cxx similarity index 100% rename from test/c2py/synth_init.wrap.cxx rename to test/synth_init.wrap.cxx diff --git a/test/c2py/synth_init_test.py b/test/synth_init_test.py similarity index 100% rename from test/c2py/synth_init_test.py rename to test/synth_init_test.py diff --git a/test/c2py/tpl_cls.cpp b/test/tpl_cls.cpp similarity index 100% rename from test/c2py/tpl_cls.cpp rename to test/tpl_cls.cpp diff --git a/test/c2py/tpl_cls.wrap.cxx b/test/tpl_cls.wrap.cxx similarity index 100% rename from test/c2py/tpl_cls.wrap.cxx rename to test/tpl_cls.wrap.cxx diff --git a/test/c2py/tpl_cls_test.py b/test/tpl_cls_test.py similarity index 100% rename from test/c2py/tpl_cls_test.py rename to test/tpl_cls_test.py diff --git a/test/c2py/tpl_derived.cpp b/test/tpl_derived.cpp similarity index 100% rename from test/c2py/tpl_derived.cpp rename to test/tpl_derived.cpp diff --git a/test/c2py/tpl_derived.wrap.cxx b/test/tpl_derived.wrap.cxx similarity index 100% rename from test/c2py/tpl_derived.wrap.cxx rename to test/tpl_derived.wrap.cxx diff --git a/test/c2py/tpl_derived_test.py b/test/tpl_derived_test.py similarity index 100% rename from test/c2py/tpl_derived_test.py rename to test/tpl_derived_test.py diff --git a/test/c2py/two_module_1.cpp b/test/two_module_1.cpp similarity index 100% rename from test/c2py/two_module_1.cpp rename to test/two_module_1.cpp diff --git a/test/c2py/two_module_1.hpp b/test/two_module_1.hpp similarity index 100% rename from test/c2py/two_module_1.hpp rename to test/two_module_1.hpp diff --git a/test/c2py/two_module_1.wrap.cxx b/test/two_module_1.wrap.cxx similarity index 100% rename from test/c2py/two_module_1.wrap.cxx rename to test/two_module_1.wrap.cxx diff --git a/test/c2py/two_module_1.wrap.hxx b/test/two_module_1.wrap.hxx similarity index 100% rename from test/c2py/two_module_1.wrap.hxx rename to test/two_module_1.wrap.hxx diff --git a/test/c2py/two_module_1_test.py b/test/two_module_1_test.py similarity index 100% rename from test/c2py/two_module_1_test.py rename to test/two_module_1_test.py diff --git a/test/c2py/two_module_2.cpp b/test/two_module_2.cpp similarity index 100% rename from test/c2py/two_module_2.cpp rename to test/two_module_2.cpp diff --git a/test/c2py/two_module_2.wrap.cxx b/test/two_module_2.wrap.cxx similarity index 100% rename from test/c2py/two_module_2.wrap.cxx rename to test/two_module_2.wrap.cxx diff --git a/test/c2py/two_module_2_test.py b/test/two_module_2_test.py similarity index 100% rename from test/c2py/two_module_2_test.py rename to test/two_module_2_test.py