Skip to content

Commit

Permalink
Fix CMake not building the JARs properly
Browse files Browse the repository at this point in the history
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
  • Loading branch information
folmos-at-orange committed Aug 23, 2023
1 parent 7e1cc14 commit ec6d314
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 54 deletions.
52 changes: 42 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
48 changes: 30 additions & 18 deletions src/Learning/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions src/Learning/MODL/MDKhiopsLearningProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Learning/MODL_Coclustering/CCLearningProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
59 changes: 37 additions & 22 deletions src/Norm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit ec6d314

Please sign in to comment.