From ec6d314eb0cffe5aec712d8ab35f3f4ad2576e32 Mon Sep 17 00:00:00 2001 From: Felipe Olmos Date: Mon, 14 Aug 2023 17:54:35 +0200 Subject: [PATCH] Fix CMake not building the JARs properly The khiops.jar contains only icons/images. They were in the "empty" namespace but the CMake add_jar directive does not work well when the namespace is empty. The solution is to always use a namespace for the jar images. Additionally the add_jar code was refactored to add_khiops_jar function in the top CMakeLists.txt --- CMakeLists.txt | 52 ++++++++++++---- src/Learning/CMakeLists.txt | 48 +++++++++------ src/Learning/MODL/MDKhiopsLearningProject.cpp | 4 +- .../MODL_Coclustering/CCLearningProject.cpp | 4 +- src/Norm/CMakeLists.txt | 59 ++++++++++++------- 5 files changed, 113 insertions(+), 54 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f4f7e51ef..be6b868ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,7 +93,7 @@ if(IS_FEDORA_LIKE) endif(DEFINED ENV{MPI_SUFFIX}) endif(IS_FEDORA_LIKE) -# Set built products location: +# Set the location of the built artifacts: # # - Shared and static library target directory: lib # - Executable target directory: bin @@ -140,23 +140,32 @@ elseif(C11) set(CMAKE_CXX_STANDARD_REQUIRED ON) endif() -# Message the current C++ configuration -message(STATUS "CMake generator is: ${CMAKE_GENERATOR}") -message(STATUS "CMake compiler is: ${CMAKE_CXX_COMPILER_ID}") -message(STATUS "CMake C++ standard is: ${CMAKE_CXX_STANDARD}") - # Find Bison/Flex if required if(BUILD_LEX_YACC) find_package(BISON REQUIRED) find_package(FLEX REQUIRED) endif() -# Find Java +# Find Java if required if(BUILD_JARS) find_package(Java REQUIRED COMPONENTS Development) + include(UseJava) + set(KHIOPS_BUILD_JAR_DIR "${CMAKE_BINARY_DIR}/jars") + message(STATUS "Java JARs will be stored at ${KHIOPS_BUILD_JAR_DIR}") +# Note: For final builds we recommend to use java 1.8 to ensure that the jar is compatible +# with all posterior java versions (from # 1.8 to the most recent ones). The following setting +# accomplish that: +# +# - find_package(Java 1.8 EXACT REQUIRED COMPONENTS Development) endif() -# MSVC: Eliminate some options the old CMake way because VS sets them with default values +# Message the current C++ configuration +message(STATUS "CMake generator is: ${CMAKE_GENERATOR}") +message(STATUS "CMake compiler is: ${CMAKE_CXX_COMPILER_ID}") +message(STATUS "CMake C++ standard is: ${CMAKE_CXX_STANDARD}") + + +# MSVC: Eliminate some options the old CMake way because VS sets them with undesired default values # # - the C++ exception flags # - the runtime information flags @@ -288,14 +297,35 @@ function(display_variables) endforeach() endfunction() +# This function set up a JAR target. Arguments: +# +# - NAME: Name of the JAR target +# - IMAGES: Paths of the image files to include in the JAR +function(add_khiops_jar) + # Parse the function arguments + set(options "") + set(oneValueArgs "NAME") + set(multiValueKwargs "JAVA_FILES" "IMAGES") + cmake_parse_arguments(ADD_KHIOPS_JAR "${options}" "${oneValueArgs}" "${multiValueKwargs}" ${ARGN}) + + # Add the JAR target with its resources and install + message(STATUS "Setting up JAR ${ADD_KHIOPS_JAR_NAME}.jar") + add_jar( + "${ADD_KHIOPS_JAR_NAME}_jar" ${ADD_KHIOPS_JAR_JAVA_FILES} + OUTPUT_NAME ${ADD_KHIOPS_JAR_NAME} RESOURCES NAMESPACE "images" ${ADD_KHIOPS_JAR_IMAGES} + OUTPUT_DIR "${CMAKE_BINARY_DIR}/jars") + install_jar("${ADD_KHIOPS_JAR_NAME}_jar" DESTINATION usr/share/khiops) +endfunction() + # Add targets for Norm Parallel and Learning modules add_subdirectory(src/Norm) add_subdirectory(src/Parallel) add_subdirectory(src/Learning) +# Testing settings if(TESTING) + # Disable gMock from the building of googletest set(BUILD_GMOCK OFF) - set(INSTALL_GTEST OFF) # Fetch googletest from its Git repo include(FetchContent) @@ -318,17 +348,19 @@ if(TESTING) set_property(TARGET gtest_main PROPERTY MSVC_RUNTIME_LIBRARY MultiThreadedDebug) endif() + # Include and enable googletest include(GoogleTest) enable_testing() + # Add testing targets add_subdirectory(test/Norm) add_subdirectory(test/Parallel) add_subdirectory(test/Parallel-mpi) add_subdirectory(test/Learning) - endif(TESTING) # Exclude googletest from the installation set(INSTALL_GTEST OFF) +# Add packaging directory for CPack scripts include(packaging) diff --git a/src/Learning/CMakeLists.txt b/src/Learning/CMakeLists.txt index 1a31e56a0..2816b8427 100644 --- a/src/Learning/CMakeLists.txt +++ b/src/Learning/CMakeLists.txt @@ -26,24 +26,36 @@ add_subdirectory(SNBPredictor) # build norm.jar if(BUILD_JARS) - include(UseJava) - add_jar( - khiops_jar - OUTPUT_NAME - khiops - RESOURCES - NAMESPACE - "" - ../../packaging/common/images/khiops_coclustering_about.gif - ../../packaging/common/images/khiops_coclustering.gif - ../../packaging/common/images/khiops_about.gif - ../../packaging/common/images/khiops.gif - OUTPUT_DIR ${CMAKE_BINARY_DIR}) - message(STATUS "build khiops.jar in ${CMAKE_BINARY_DIR}") - install_jar( - khiops_jar - DESTINATION usr/share/khiops - COMPONENT KHIOPS) + add_khiops_jar( + NAME + "khiops" + NAMESPACE + "images" + IMAGES + "../../packaging/common/images/khiops_coclustering_about.gif" + "../../packaging/common/images/khiops_coclustering.gif" + "../../packaging/common/images/khiops_about.gif" + "../../packaging/common/images/khiops.gif" + ) + + #include(UseJava) + #add_jar( + #khiops_jar + #OUTPUT_NAME + #khiops + #RESOURCES + #NAMESPACE + #"" + #../../packaging/common/images/khiops_coclustering_about.gif + #../../packaging/common/images/khiops_coclustering.gif + #../../packaging/common/images/khiops_about.gif + #../../packaging/common/images/khiops.gif + #OUTPUT_DIR ${CMAKE_BINARY_DIR}) + #message(STATUS "build khiops.jar in ${CMAKE_BINARY_DIR}") + #install_jar( + #khiops_jar + #DESTINATION usr/share/khiops + #COMPONENT KHIOPS) endif() include(install) diff --git a/src/Learning/MODL/MDKhiopsLearningProject.cpp b/src/Learning/MODL/MDKhiopsLearningProject.cpp index bc25eb646..a2a417a78 100644 --- a/src/Learning/MODL/MDKhiopsLearningProject.cpp +++ b/src/Learning/MODL/MDKhiopsLearningProject.cpp @@ -27,10 +27,10 @@ void MDKhiopsLearningProject::OpenLearningEnvironnement() KWGrouper::RegisterGrouper(new DTGrouperMODL); // Parametrage de l'icone de l'application - UIObject::SetIconImage("khiops.gif"); + UIObject::SetIconImage("images/khiops.gif"); // Parametrage du menu about - SetLearningAboutImage("khiops_about.gif"); + SetLearningAboutImage("images/khiops_about.gif"); SetLearningWebSite("www.khiops.com"); // Parametrage de la fenetre de documentation diff --git a/src/Learning/MODL_Coclustering/CCLearningProject.cpp b/src/Learning/MODL_Coclustering/CCLearningProject.cpp index a7650dc6f..a4117501e 100644 --- a/src/Learning/MODL_Coclustering/CCLearningProject.cpp +++ b/src/Learning/MODL_Coclustering/CCLearningProject.cpp @@ -23,10 +23,10 @@ void CCLearningProject::OpenLearningEnvironnement() SetLearningModuleName("Coclustering"); // Parametrage de l'icone de l'application - UIObject::SetIconImage("khiops_coclustering.gif"); + UIObject::SetIconImage("images/khiops_coclustering.gif"); // Parametrage du menu about - SetLearningAboutImage("khiops_coclustering_about.gif"); + SetLearningAboutImage("images/khiops_coclustering_about.gif"); SetLearningWebSite("www.khiops.com"); // Parametrage de la fenetre de documentation diff --git a/src/Norm/CMakeLists.txt b/src/Norm/CMakeLists.txt index 8cf380f89..9f04dc61f 100644 --- a/src/Norm/CMakeLists.txt +++ b/src/Norm/CMakeLists.txt @@ -9,31 +9,46 @@ if(FULL) add_subdirectory(generetest) endif(FULL) -# build norm.jar +# add norm.jar target if(BUILD_JARS) + file(GLOB_RECURSE norm_java_files NormGUI/*.java) + add_khiops_jar( + NAME + "norm" + JAVA_FILES + ${norm_java_files} + NAMESPACE + "images" + IMAGES + "NormGUI/images/sample.png" + "NormGUI/images/sample.jpg" + "NormGUI/images/sample.gif" + "NormGUI/images/sample2.png" + ) + + # we recommend to use java 1.8 to ensure that the jar is compatible with all java versions (from 1.8 to the most # recent ones) find_package(Java 1.8 EXACT REQUIRED COMPONENTS Development) - find_package(Java REQUIRED COMPONENTS Development) + #find_package(Java REQUIRED COMPONENTS Development) - include(UseJava) - file(GLOB_RECURSE javafiles NormGUI/*.java) - add_jar( - norm_jar ${javafiles} - OUTPUT_NAME norm - ENTRY_POINT - normGUI.engine.GUIObject - RESOURCES - NAMESPACE - "images" - NormGUI/images/sample.png - NormGUI/images/sample.jpg - NormGUI/images/sample.gif - NormGUI/images/sample2.png - OUTPUT_DIR ${CMAKE_BINARY_DIR}) - message(STATUS "build norm.jar in ${CMAKE_BINARY_DIR}") - install_jar( - norm_jar - DESTINATION usr/share/khiops - COMPONENT KHIOPS) + #file(GLOB_RECURSE javafiles NormGUI/*.java) + #add_jar( + #norm_jar ${javafiles} + #OUTPUT_NAME norm + #ENTRY_POINT + #normGUI.engine.GUIObject + #RESOURCES + #NAMESPACE + #"images" + #NormGUI/images/sample.png + #NormGUI/images/sample.jpg + #NormGUI/images/sample.gif + #NormGUI/images/sample2.png + #OUTPUT_DIR ${CMAKE_BINARY_DIR}) + #message(STATUS "build norm.jar in ${CMAKE_BINARY_DIR}") + #install_jar( + #norm_jar + #DESTINATION usr/share/khiops + #COMPONENT KHIOPS) endif()