diff --git a/CMakeLists.txt b/CMakeLists.txt index 223fbb39bd2c140303f1549d07a0c06b2f72fb95..73891e77425c45f7b0062b3632d4975db58a358a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,11 @@ cmake_minimum_required(VERSION 3.11) -set(project aidge) +set(project aidge_core) # This will also be python module name +set(module_name _${project}) # target name + + set(version 2.0.0) project(${project}) -enable_testing() -# TODO : use a file to store module_name ? -set(module_name aidge_core) # This will be python module name -set(component core) # Traget name must be different than pybind target ############################################## # Import utils CMakeLists @@ -20,7 +19,6 @@ option(WERROR "Warning as error" OFF) ############################################## # Find system dependencies -generate_python_binding(aidge_${module_name}) # TODO : cannot be component because of target name ############################################## # Create target and set properties @@ -28,50 +26,53 @@ generate_python_binding(aidge_${module_name}) # TODO : cannot be component becau file(GLOB_RECURSE src_files "src/*.cpp") file(GLOB_RECURSE inc_files "include/*.hpp") -add_library(${component} ${src_files} ${inc_files}) - -# namespaced alias -add_library(${project}::${component} ALIAS ${component}) +add_library(${module_name} ${src_files} ${inc_files}) #Set target properties -set_property(TARGET ${component} PROPERTY POSITION_INDEPENDENT_CODE ON) -target_include_directories(${component} +set_property(TARGET ${module_name} PROPERTY POSITION_INDEPENDENT_CODE ON) +target_include_directories(${module_name} PUBLIC $<INSTALL_INTERFACE:include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src ) + +# PYTHON BINDING +generate_python_binding(${project} ${module_name}) + if (PYBIND) message(STATUS "PYTHON INCLUDE DIR : ${PYTHON_INCLUDE_DIRS}") message(STATUS "PYTHON PYTHON_LIBRARY : ${PYTHON_LIBRARIES}") - target_include_directories(${component} + target_include_directories(${module_name} PUBLIC $<BUILD_INTERFACE:${PYTHON_INCLUDE_DIRS}> ) - target_link_libraries(${component} + target_link_libraries(${module_name} PRIVATE ${PYTHON_LIBRARIES} ) endif() -target_compile_features(${component} PRIVATE cxx_std_14) + +target_compile_features(${module_name} PRIVATE cxx_std_14) + if(WERROR) -target_compile_options(${component} PRIVATE -$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>: --Wall -Wextra -Wold-style-cast -Winline -pedantic -Werror=narrowing -Wshadow -Werror>) -target_compile_options(${component} PRIVATE -$<$<CXX_COMPILER_ID:MSVC>: -/W4>) + target_compile_options(${module_name} PRIVATE + $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>: + -Wall -Wextra -Wold-style-cast -Winline -pedantic -Werror=narrowing -Wshadow -Werror>) + target_compile_options(${module_name} PRIVATE + $<$<CXX_COMPILER_ID:MSVC>: + /W4>) else() - target_compile_options(${component} PRIVATE + target_compile_options(${module_name} PRIVATE $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>: -Wall -Wextra -Wold-style-cast -Winline -pedantic -Werror=narrowing -Wshadow -Wpedantic>) - target_compile_options(${component} PRIVATE + target_compile_options(${module_name} PRIVATE $<$<CXX_COMPILER_ID:MSVC>: /W4>) - endif() +endif() ############################################## # Installation instructions @@ -79,66 +80,51 @@ else() include(GNUInstallDirs) set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/${project}) -install(TARGETS ${component} EXPORT ${component}-targets - COMPONENT ${component} +install(TARGETS ${module_name} EXPORT ${project}-targets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) #Export the targets to a script -install(EXPORT ${component}-targets - FILE "${project}-${component}-targets.cmake" - NAMESPACE ${project}:: - DESTINATION ${INSTALL_CONFIGDIR} - COMPONENT ${component} -) + +install(EXPORT ${project}-targets + FILE "${project}-targets.cmake" + DESTINATION ${INSTALL_CONFIGDIR} +# COMPONENT ${module_name} +) #Create a ConfigVersion.cmake file include(CMakePackageConfigHelpers) + write_basic_package_version_file( - "${CMAKE_CURRENT_BINARY_DIR}/${project}-${component}-config-version.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/${project}-config-version.cmake" VERSION ${version} COMPATIBILITY AnyNewerVersion ) -configure_package_config_file("${component}-config.cmake.in" - "${CMAKE_CURRENT_BINARY_DIR}/${project}-${component}-config.cmake" +configure_package_config_file("${project}-config.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/${project}-config.cmake" INSTALL_DESTINATION ${INSTALL_CONFIGDIR} ) #Install the config, configversion and custom find modules install(FILES - "${CMAKE_CURRENT_BINARY_DIR}/${project}-${component}-config.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/${project}-${component}-config-version.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/${project}-config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/${project}-config-version.cmake" DESTINATION ${INSTALL_CONFIGDIR} - COMPONENT ${component} ) ############################################## ## Exporting from the build tree -export(EXPORT ${component}-targets - FILE "${CMAKE_CURRENT_BINARY_DIR}/${project}-${component}-targets.cmake" - NAMESPACE ${project}::) +export(EXPORT ${project}-targets + FILE "${CMAKE_CURRENT_BINARY_DIR}/${project}-targets.cmake") ############################################## ## Add test +enable_testing() add_subdirectory(unit_tests) - -include(CMakePackageConfigHelpers) - -write_basic_package_version_file( - "${CMAKE_BINARY_DIR}/${project}-config-version.cmake" - VERSION ${version} - COMPATIBILITY AnyNewerVersion -) - - -# install( -# FILES -# "${CMAKE_BINARY_DIR}/${project}-config.cmake" -# DESTINATION lib/cmake/${project} -# ) diff --git a/OLD_CMakeLists.txt b/OLD_CMakeLists.txt deleted file mode 100644 index 7cea83d9728a4ac26c1a6d6b1970fd5e3303ff9f..0000000000000000000000000000000000000000 --- a/OLD_CMakeLists.txt +++ /dev/null @@ -1,52 +0,0 @@ - -if (BUILD_CORE_ALONE) - project(Aidge_Core) - cmake_minimum_required(VERSION 3.11) - add_compile_options(-Wall -Wextra -fPIC) -endif() - -if (PYBIND) - add_definitions(-DPYBIND) - Include(FetchContent) - - FetchContent_Declare( - PyBind11 - GIT_REPOSITORY https://github.com/pybind/pybind11.git - GIT_TAG v2.10.4 # or a later release - ) - - FetchContent_MakeAvailable(PyBind11) - file(GLOB_RECURSE pybind_src_files "python_binding/*.cpp") - pybind11_add_module(aidge_core MODULE ${pybind_src_files} "NO_EXTRAS") - target_include_directories(aidge_core PUBLIC ${pybind11_INCLUDE_DIRS} "python_binding") - target_link_libraries(aidge_core PUBLIC core) - # generate_python_binding(aidge_core core) -endif() - -add_library(core STATIC) - -# Add include directories -target_include_directories(core PUBLIC "include") - -# Containers module -file(GLOB_RECURSE src_files "src/*.cpp") -target_sources(core PRIVATE ${src_files}) - -set_property(TARGET core PROPERTY POSITION_INDEPENDENT_CODE ON) - -if (PYBIND) - target_include_directories(core PUBLIC $<BUILD_INTERFACE:${PYTHON_INCLUDE_DIRS}>) - target_link_libraries(core PRIVATE ${PYTHON_LIBRARIES}) -endif() - -if (NOT BUILD_CORE_ALONE) - # Activate compile time reducer for aidge_core - set_target_properties(core PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE) - # set_target_properties(n2d2_cpu_lib PROPERTIES COTIRE_CXX_PREFIX_HEADER_INIT "include/utils/Precompiled.hpp") - cotire(core) -endif() - - -if (TESTS) - add_subdirectory(tests) -endif() \ No newline at end of file diff --git a/core-config.cmake.in b/aidge_core-config.cmake.in similarity index 88% rename from core-config.cmake.in rename to aidge_core-config.cmake.in index 6cf0fac1ea397a33a8c9d8c8d1be8ea2163a2116..adfbf2838bdbba48c7c2e8420fece43054cd39d3 100644 --- a/core-config.cmake.in +++ b/aidge_core-config.cmake.in @@ -1,3 +1,5 @@ +@PACKAGE_INIT@ + include(${CMAKE_CURRENT_LIST_DIR}/aidge_core-config-version.cmake) include(${CMAKE_CURRENT_LIST_DIR}/aidge_core-targets.cmake) diff --git a/cmake/PybindModuleCreation.cmake b/cmake/PybindModuleCreation.cmake index 6ca1aeffec5f07a3b50567f2033af94a714b32f4..c54f1c87e8789ba8f2bb16b19812e263be6dc090 100644 --- a/cmake/PybindModuleCreation.cmake +++ b/cmake/PybindModuleCreation.cmake @@ -1,4 +1,4 @@ -function(generate_python_binding name) +function(generate_python_binding name target_to_bind) if (PYBIND) add_definitions(-DPYBIND) Include(FetchContent) @@ -14,6 +14,7 @@ function(generate_python_binding name) file(GLOB_RECURSE pybind_src_files "python_binding/*.cpp") pybind11_add_module(${name} MODULE ${pybind_src_files}) target_include_directories(${name} PUBLIC ${pybind11_INCLUDE_DIRS} "python_binding") - target_link_libraries(${name} PUBLIC ${component}) + target_link_libraries(${name} PUBLIC ${target_to_bind}) + endif() endfunction() diff --git a/python_binding/CMakeLists.txt b/python_binding/CMakeLists.txt deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/unit_tests/CMakeLists.txt b/unit_tests/CMakeLists.txt index fbd9ec8bb132fb9856f12bc01c473d0fda7f94cc..9d9f81516b0cd2611484ee9e3e06e838833200db 100644 --- a/unit_tests/CMakeLists.txt +++ b/unit_tests/CMakeLists.txt @@ -1,6 +1,3 @@ - -enable_testing() - Include(FetchContent) FetchContent_Declare( @@ -13,13 +10,13 @@ FetchContent_MakeAvailable(Catch2) file(GLOB_RECURSE src_files "*.cpp") -add_executable(tests_core ${src_files}) +add_executable(tests${module_name} ${src_files}) -target_link_libraries(tests_core PUBLIC core) +target_link_libraries(tests${module_name} PUBLIC ${module_name}) -target_link_libraries(tests_core PRIVATE Catch2::Catch2WithMain) +target_link_libraries(tests${module_name} PRIVATE Catch2::Catch2WithMain) list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras) include(CTest) include(Catch) -catch_discover_tests(tests_core) +catch_discover_tests(tests${module_name})