Skip to content

Commit

Permalink
Improve cmake files (inspired from gatb-core)
Browse files Browse the repository at this point in the history
  • Loading branch information
edrezen committed Jan 15, 2014
1 parent 81c93e2 commit 9593eee
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 25 deletions.
86 changes: 71 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,88 @@ find_package (JNI REQUIRED)
#set (EXECUTABLE_OUTPUT_PATH bin/${CMAKE_BUILD_TYPE})

################################################################################
# GENERAL DEFINITIONS
# The version number.
################################################################################
add_definitions (-O3 -funroll-loops -fomit-frame-pointer -msse3 -DOBSFUCATION -DJNI_OBSFUCATION)
set (plast_VERSION_MAJOR 2)
set (plast_VERSION_MINOR 2)
set (plast_VERSION_PATCH 0b)
set (plast-version ${plast_VERSION_MAJOR}.${plast_VERSION_MINOR}.${plast_VERSION_PATCH})
set (plast-date "xxxx-xx-xx")

################################################################################
# Current Date
################################################################################
INCLUDE(FindPerl)

# We execute a command that retrieves the current date.
IF (PERL_FOUND)
EXECUTE_PROCESS (
COMMAND "${PERL_EXECUTABLE}" "-le" "@T=localtime; printf (\"%04d-%02d-%02d %02d:%02d:%02d\",$T[5]+1900,$T[4]+1,$T[3],$T[2],$T[1],$T[0])"
OUTPUT_VARIABLE plast-date
)
ENDIF (PERL_FOUND)

################################################################################
# Compilation options
################################################################################

if (debug)
set (LIBRARY_COMPILE_DEFINITIONS "${LIBRARY_COMPILE_DEFINITIONS} -g -p")
message("-- COMPILATION IN DEBUG MODE")
else()
set (LIBRARY_COMPILE_DEFINITIONS "${LIBRARY_COMPILE_DEFINITIONS} -O3 -funroll-loops -fomit-frame-pointer -msse3 -DOBSFUCATION -DJNI_OBSFUCATION")
endif()

message("-- Options: ${LIBRARY_COMPILE_DEFINITIONS}")

################################################################################
# OPERATING SYSTEM SPECIFIC
################################################################################
IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
add_definitions(-D__DARWIN__)
set (LIBRARY_COMPILE_DEFINITIONS "${LIBRARY_COMPILE_DEFINITIONS} -D__DARWIN__")
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
add_definitions(-D__LINUX__)
set (LIBRARY_COMPILE_DEFINITIONS "${LIBRARY_COMPILE_DEFINITIONS} -D__LINUX__")
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")

IF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
add_definitions(-D__WINDOWS__)
set (LIBRARY_COMPILE_DEFINITIONS "${LIBRARY_COMPILE_DEFINITIONS} -D__WINDOWS__")
# IMPORTANT ! we have to add this flag for getting correct methods names in the library
# otherwise the Java JVM won't find the native JNI methods.
set_target_properties (PlastLibrary PROPERTIES LINK_FLAGS -Wl,--kill-at)
set_target_properties (PlastLibrary PROPERTIES PREFIX "")
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")

################################################################################
# LIBRARY GENERATION
# DIRECTORIES MANAGEMENT
################################################################################

set (LIBRARY_OUTPUT_PATH lib/${CMAKE_BUILD_TYPE})
set (LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib/${CMAKE_BUILD_TYPE})
set (EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE})

file (GLOB_RECURSE LibraryFiles src/*)
################################################################################
# Library variables
################################################################################

# We define the compilation flags used for compiling binary based on the library
set (plast-flags ${LIBRARY_COMPILE_DEFINITIONS})

include_directories (src ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2})
# We define the include directories used for linking binary based on the library
set (plast-includes ${PROJECT_BINARY_DIR}/include)

add_library (PlastLibrary-static STATIC ${LibraryFiles} )
add_library (PlastLibrary-dynamic SHARED ${LibraryFiles} )
# We define the libraries used for linking binary based on the library
set (plast-libraries PlastLibrary-static dl pthread)

set_target_properties (PlastLibrary-static PROPERTIES OUTPUT_NAME PlastLibrary clean_direct_output 1)
set_target_properties (PlastLibrary-dynamic PROPERTIES OUTPUT_NAME PlastLibrary clean_direct_output 1)
# NOTE... we have to duplicate the variables for the other scopes (in particular for sub directories)
set (plast-flags ${plast-flags} PARENT_SCOPE)
set (plast-includes ${plast-includes} PARENT_SCOPE)
set (plast-libraries ${plast-libraries} PARENT_SCOPE)

################################################################################
# LIBRARY GENERATION
################################################################################
ADD_SUBDIRECTORY(src)

################################################################################
# UNIT TESTS GENERATION
Expand All @@ -55,14 +99,26 @@ ADD_SUBDIRECTORY(test)
################################################################################
# DOCUMENTATION GENERATION
################################################################################
ADD_SUBDIRECTORY(doc)
ADD_SUBDIRECTORY (doc EXCLUDE_FROM_ALL)

################################################################################
# EXAMPLES GENERATION
################################################################################
ADD_SUBDIRECTORY(examples)
ADD_SUBDIRECTORY(examples EXCLUDE_FROM_ALL)

################################################################################
# TOOLS GENERATION
################################################################################
ADD_SUBDIRECTORY(tools)

################################################################################
# INSTALLER
################################################################################
SET (CPACK_PACKAGE_DESCRIPTION_SUMMARY "plast project")
SET (CPACK_PACKAGE_VENDOR "INRIA/Korilog")
SET (CPACK_PACKAGE_VERSION_MAJOR "${plast_VERSION_MAJOR}")
SET (CPACK_PACKAGE_VERSION_MINOR "${plast_VERSION_MINOR}")
SET (CPACK_PACKAGE_VERSION_PATCH "${plast_VERSION_PATCH}")
SET (CPACK_PACKAGE_VERSION "${plast-version}")

include (CPack)
27 changes: 20 additions & 7 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,26 @@
# EXAMPLES
################################################################################

set (LIBRARY_OUTPUT_PATH lib/${CMAKE_BUILD_TYPE})
add_definitions (${plast-flags})
include_directories (${plast-includes})

list (APPEND PROGRAMS example1 example2 example3 example4 example5)
list (APPEND PROGRAMS example6 example7 example8 example9 example10)
list (APPEND PROGRAMS example11)
file (GLOB_RECURSE PROGRAMS_FILES *.cpp)

FOREACH (program ${PROGRAMS})
add_executable(${program} ${program}.cpp)
target_link_libraries(${program} PlastLibrary-static dl pthread)
FOREACH (program ${PROGRAMS_FILES})

# we get the base name of the current example
get_filename_component(basename ${program} NAME_WE)

# we add an executable for this example
add_executable (${basename} ${program})

# we use the plast library for the link
target_link_libraries (${basename} ${plast-libraries})

list (APPEND PROGRAMS_NAMES ${basename})

ENDFOREACH (program)

# We add a custom target for making all examples
add_custom_target (examples ALL DEPENDS ${PROGRAMS_NAMES})

2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ ADD_SUBDIRECTORY(unit)
################################################################################
# BENCHMARK TESTS GENERATION
################################################################################
ADD_SUBDIRECTORY(benchmark)
ADD_SUBDIRECTORY(benchmark EXCLUDE_FROM_ALL)
5 changes: 3 additions & 2 deletions test/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
# BENCHMARKS
################################################################################

set (LIBRARY_OUTPUT_PATH lib/${CMAKE_BUILD_TYPE})
add_definitions (${plast-flags})
include_directories (${plast-includes})

list (APPEND PROGRAMS bench1 AlgoAnalysis1)

FOREACH (program ${PROGRAMS})
add_executable(${program} ${program}.cpp)
target_link_libraries(${program} PlastLibrary-static dl pthread)
target_link_libraries(${program} ${plast-libraries})
ENDFOREACH (program)
5 changes: 5 additions & 0 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ FOREACH (program ${PROGRAMS})
add_executable(${program} ${program}.cpp)
target_link_libraries(${program} ${plast-libraries})
ENDFOREACH (program)

################################################################################
# INSTALLATION
################################################################################
install (TARGETS PlastCmd makeplastdb DESTINATION bin)

0 comments on commit 9593eee

Please sign in to comment.