Skip to content

Commit

Permalink
Merge branch 'add-cmake-3-support'
Browse files Browse the repository at this point in the history
* add-cmake-3-support:
  ENH: Re-factor GenerateCLP tests to support multi config system
  ENH: Add support for CMake 3.0 removing use of LOCATION target property
  ENH: Set default value for CMAKE_BUILD_TYPE
  • Loading branch information
jcfr committed Jun 17, 2014
2 parents c83b673 + aa34edf commit 11ea15b
Show file tree
Hide file tree
Showing 20 changed files with 401 additions and 104 deletions.
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ if(DEFINED SlicerExecutionModel_LIBRARY_PROPERTIES)
set(ModuleDescriptionParser_LIBRARY_PROPERTIES ${SlicerExecutionModel_LIBRARY_PROPERTIES})
endif()

#-----------------------------------------------------------------------------
# Set a default build type if none was specified
#-----------------------------------------------------------------------------
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Debug' as none was specified.")
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE)
mark_as_advanced(CMAKE_BUILD_TYPE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
endif()

#-----------------------------------------------------------------------------
# Output directories associated with ModuleDescriptionParser and GenerateCLP subprojects
#-----------------------------------------------------------------------------
Expand Down
12 changes: 12 additions & 0 deletions GenerateCLP/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ if(POLICY CMP0017)
cmake_policy(SET CMP0017 OLD)
endif()

#-----------------------------------------------------------------------------
# Set a default build type if none was specified
#-----------------------------------------------------------------------------
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Debug' as none was specified.")
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE)
mark_as_advanced(CMAKE_BUILD_TYPE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
endif()

# --------------------------------------------------------------------------
# Prerequisites
# --------------------------------------------------------------------------
Expand Down
14 changes: 13 additions & 1 deletion GenerateCLP/GenerateCLPConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@


# The GenerateCLP source tree.
set(GenerateCLP_INCLUDE_DIRS "@GenerateCLP_INCLUDE_DIRS_CONFIG@")
set(GenerateCLP_LIBRARY_DIRS "@GenerateCLP_LIBRARY_DIRS_CONFIG@")
set(GenerateCLP_CMAKE_DIR "@GenerateCLP_CMAKE_DIR_CONFIG@")
set(GenerateCLP_USE_FILE "@GenerateCLP_USE_FILE_CONFIG@")
set(GenerateCLP_USE_JSONCPP "@GenerateCLP_USE_JSONCPP@")
set(GenerateCLP_USE_SERIALIZER "@GenerateCLP_USE_SERIALIZER@")
set(GENERATECLP_EXE "@GENERATECLP_EXE_CONFIG@")
set(TCLAP_DIR "@TCLAP_DIR@")
set(ModuleDescriptionParser_DIR "@ModuleDescriptionParser_DIR@")
set(ITK_DIR "@ITK_DIR_CONFIG@")

find_program(GENERATECLP_EXE
NAMES GenerateCLPLauncher GenerateCLP
PATHS
"@GenerateCLP_CONFIG_DIR@/bin"
"@GenerateCLP_CONFIG_DIR@/bin/Release"
"@GenerateCLP_CONFIG_DIR@/bin/RelWithDebInfo"
"@GenerateCLP_CONFIG_DIR@/bin/MinSizeRel"
"@GenerateCLP_CONFIG_DIR@/bin/Debug"
NO_DEFAULT_PATH
)

# The GenerateCLP targets file.
if(NOT TARGET GenerateCLP AND EXISTS "@CMAKE_CURRENT_BINARY_DIR@/GenerateCLPTargets.cmake")
include("@CMAKE_CURRENT_BINARY_DIR@/GenerateCLPTargets.cmake")
Expand Down
24 changes: 1 addition & 23 deletions GenerateCLP/GenerateGenerateCLPConfig.cmake
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
# Generate the GenerateCLPConfig.cmake file in the build tree and configure
# one the installation tree.

# Following the standard pattern, UseGenerateCLP.cmake is a configured file
#

get_target_property(GenerateCLP_EXE_PATH GenerateCLPLauncher LOCATION)

if(GenerateCLP_EXE_PATH)
set(GENERATECLP_EXE "${GenerateCLP_EXE_PATH}")
else()
set(USE_CONFIG_FILE_INSTALL_DIR ${GenerateCLP_BINARY_DIR})
set(GENERATECLP_EXE "${USE_CONFIG_FILE_INSTALL_DIR}/${CMAKE_CFG_INTDIR}/GenerateCLPLauncher")
endif()

# Settings specific to build trees
#
#
Expand All @@ -27,18 +15,8 @@ set(GenerateCLP_LIBRARY_DIRS_CONFIG
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
)
set(GenerateCLP_CMAKE_DIR_CONFIG ${GenerateCLP_BINARY_DIR})
set(GENERATECLP_EXE_CONFIG "${GENERATECLP_EXE}")
set(GenerateCLP_CONFIG_DIR "${GenerateCLP_BINARY_DIR}")
set(ITK_DIR_CONFIG ${ITK_DIR})
configure_file(${GenerateCLP_SOURCE_DIR}/GenerateCLPConfig.cmake.in
${GenerateCLP_BINARY_DIR}/GenerateCLPConfig.cmake @ONLY)


# TODO - Settings specific for installation trees
#
#
#configure_file(${GenerateCLP_SOURCE_DIR}/UseGenerateCLP.cmake.in
# ${GenerateCLP_BINARY_DIR}/UseGenerateCLP.cmake_install
# @ONLY)

#configure_file(${GenerateCLP_SOURCE_DIR}/GenerateCLPInstallConfig.cmake.in
# ${GenerateCLP_BINARY_DIR}/GenerateCLPConfig.cmake_install @ONLY)
File renamed without changes.
File renamed without changes.
82 changes: 82 additions & 0 deletions GenerateCLP/Testing/CLPExample1/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
cmake_minimum_required(VERSION 2.8.2)
project(CLPExample1)

find_package(GenerateCLP NO_MODULE REQUIRED)
include(${GenerateCLP_USE_FILE})

#-----------------------------------------------------------------------------
if(GenerateCLP_USE_JSONCPP)
set(CMAKE_MODULE_PATH ${JsonCpp_CMAKE_MODULE_PATH} ${CMAKE_MODULE_PATH}) # Needed to locate FindJsonCpp.cmake
find_package(JsonCpp REQUIRED)
include_directories(${JsonCpp_INCLUDE_DIRS})
endif()

set(_additional_link_libraries)
if(GenerateCLP_USE_JSONCPP)
list(APPEND _additional_link_libraries ${JsonCpp_LIBRARIES})
endif()
if(GenerateCLP_USE_SERIALIZER)
list(APPEND _additional_link_libraries ${ParameterSerializer_LIBRARIES})
endif()

#-----------------------------------------------------------------------------
# Build
#-----------------------------------------------------------------------------

set(${PROJECT_NAME}_SOURCE ${PROJECT_NAME}.cxx)
GENERATECLP(${PROJECT_NAME}_SOURCE ${PROJECT_NAME}.xml)
add_executable(${PROJECT_NAME} ${${PROJECT_NAME}_SOURCE})
target_link_libraries(${PROJECT_NAME} ITKEXPAT ${_additional_link_libraries})

#-----------------------------------------------------------------------------
# Test
#-----------------------------------------------------------------------------
include(CTest)

set(TEMP ${PROJECT_BINARY_DIR}/Testing/Temporary)
file(MAKE_DIRECTORY ${TEMP})

if(GenerateCLP_USE_SERIALIZER)
add_test(NAME GenerateCLPSerializer-${PROJECT_NAME}-Test1
COMMAND $<TARGET_FILE:${PROJECT_NAME}>
--spatialsamples 3324
--selection 4
--interpolation sinc
--learningrate 0.002,0.001,0.0007,0.0002
--translationscale 20
--serialize ./GenerateCLPSerializer-${PROJECT_NAME}-Test1.json
2
Head.mha
ProgrammingHead.mha
ShrunkHead.mha
WORKING_DIRECTORY ${TEMP}
)

add_test(NAME GenerateCLPSerializer-${PROJECT_NAME}-Test2
COMMAND $<TARGET_FILE:${PROJECT_NAME}>
--deserialize ./GenerateCLPSerializer-${PROJECT_NAME}-Test1.json
--serialize ./GenerateCLPSerializer-${PROJECT_NAME}-Test2.json
2
Head.mha
ProgrammingHead.mha
ShrunkHead.mha
WORKING_DIRECTORY ${TEMP}
)
set_tests_properties( GenerateCLPSerializer-${PROJECT_NAME}-Test2
PROPERTIES DEPENDS GenerateCLPSerializer-${PROJECT_NAME}-Test1)

add_test(NAME GenerateCLPSerializer-${PROJECT_NAME}-Test3
COMMAND $<TARGET_FILE:${PROJECT_NAME}>
--deserialize ./GenerateCLPSerializer-${PROJECT_NAME}-Test1.json
--serialize ./GenerateCLPSerializer-${PROJECT_NAME}-Test3.json
--spatialsamples 2112
--learningrate 0.001,0.001,0.0005,0.0003
2
Head.mha
ProgrammingHead.mha
ShrunkHead.mha
WORKING_DIRECTORY ${TEMP}
)
set_tests_properties( GenerateCLPSerializer-${PROJECT_NAME}-Test3
PROPERTIES DEPENDS GenerateCLPSerializer-${PROJECT_NAME}-Test1)
endif()
24 changes: 24 additions & 0 deletions GenerateCLP/Testing/CMake/GenerateCLPTest-Build.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@


include(${TEST_SOURCE_DIR}/../CMake/GenerateCLPTestMacros.cmake)
include(${TEST_BINARY_DIR}/../CMake/GenerateCLPTestPrerequisites.cmake)

# --------------------------------------------------------------------------
# Debug flags - Set to True to display the command as string
set(PRINT_COMMAND 0)

# --------------------------------------------------------------------------
# Build
set(command ${CMAKE_COMMAND} --build ${TEST_BINARY_DIR} --config ${generateclp_build_type})
execute_process(
COMMAND ${command}
WORKING_DIRECTORY ${TEST_BINARY_DIR}
OUTPUT_VARIABLE ov
RESULT_VARIABLE rv
)

print_command_as_string("${command}")

if(rv)
message(FATAL_ERROR "Failed to build Test:\n${ov}")
endif()
49 changes: 49 additions & 0 deletions GenerateCLP/Testing/CMake/GenerateCLPTest-Configure.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

include(${TEST_SOURCE_DIR}/../CMake/GenerateCLPTestMacros.cmake)
include(${TEST_BINARY_DIR}/../CMake/GenerateCLPTestPrerequisites.cmake)

if(${generateclp_build_type} STREQUAL "")
message(FATAL_ERROR "Make sure variable TEST_BUILD_TYPE is not empty. "
"TEST_BUILD_TYPE [${test_build_type}]")
endif()

# --------------------------------------------------------------------------
# Delete build directory if it exists
execute_process(
COMMAND ${CMAKE_COMMAND} -E remove_directory ${TEST_BINARY_DIR}
)

# --------------------------------------------------------------------------
# Create build directory
execute_process(
COMMAND ${CMAKE_COMMAND} -E make_directory ${TEST_BINARY_DIR}
)

# --------------------------------------------------------------------------
# Debug flags - Set to True to display the command as string
set(PRINT_COMMAND 0)

# --------------------------------------------------------------------------
# Configure
set(command ${CMAKE_COMMAND}
-DCMAKE_BUILD_TYPE:STRING=${generateclp_build_type}
-DGenerateCLP_DIR:PATH=${GenerateCLP_BINARY_DIR}
-DJsonCpp_CMAKE_MODULE_PATH:PATH=${JsonCpp_CMAKE_MODULE_PATH}
-G ${generateclp_cmake_generator} ${TEST_SOURCE_DIR})
if(GenerateCLP_USE_JSONCPP)
list(APPEND command
-DJsonCpp_DIR:PATH=${JsonCpp_DIR}
)
endif()
execute_process(
COMMAND ${command}
WORKING_DIRECTORY ${TEST_BINARY_DIR}
OUTPUT_VARIABLE ov
RESULT_VARIABLE rv
)

print_command_as_string("${command}")

if(rv)
message(FATAL_ERROR "Failed to configure Test:\n${ov}")
endif()
26 changes: 26 additions & 0 deletions GenerateCLP/Testing/CMake/GenerateCLPTest-Test.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@


include(${TEST_SOURCE_DIR}/../CMake/GenerateCLPTestMacros.cmake)
include(${TEST_BINARY_DIR}/../CMake/GenerateCLPTestPrerequisites.cmake)

# --------------------------------------------------------------------------
# Debug flags - Set to True to display the command as string
set(PRINT_COMMAND 0)

# --------------------------------------------------------------------------
# Build
set(command ${CMAKE_CTEST_COMMAND} -C ${generateclp_build_type})
execute_process(
COMMAND ${command}
WORKING_DIRECTORY ${TEST_BINARY_DIR}
OUTPUT_VARIABLE ov
RESULT_VARIABLE rv
)

print_command_as_string("${command}")

message(${ov})

if(rv)
message(FATAL_ERROR "Failed to run Test:\n${ov}")
endif()
13 changes: 13 additions & 0 deletions GenerateCLP/Testing/CMake/GenerateCLPTestMacros.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

# --------------------------------------------------------------------------
# Helper macro
function(print_command_as_string command)
if(PRINT_COMMAND)
set(command_as_string)
foreach(elem ${command})
set(command_as_string "${command_as_string} ${elem}")
endforeach()
message(STATUS "COMMAND:${command_as_string}")
endif()
endfunction()

46 changes: 46 additions & 0 deletions GenerateCLP/Testing/CMake/GenerateCLPTestPrerequisites.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@


set(CMAKE_CONFIGURATION_TYPES "@CMAKE_CONFIGURATION_TYPES@")
set(CMAKE_BUILD_TYPE "@CMAKE_BUILD_TYPE@")
set(CMAKE_EXECUTABLE_SUFFIX "@CMAKE_EXECUTABLE_SUFFIX@")

set(generateclp_cmake_generator "@CMAKE_GENERATOR@")
set(GenerateCLP_BINARY_DIR "@GenerateCLP_BINARY_DIR@")

set(GenerateCLP_USE_JSONCPP @GenerateCLP_USE_JSONCPP@)
set(JsonCpp_DIR "@JsonCpp_DIR@")

set(JsonCpp_CMAKE_MODULE_PATH "@SlicerExecutionModel_SOURCE_DIR@/CMake")

# --------------------------------------------------------------------------
# Sanity checks

if(NOT EXISTS ${GenerateCLP_BINARY_DIR})
message(FATAL_ERROR "Make sure variable GenerateCLP_BINARY_DIR is set to a valid directory. "
"GenerateCLP_BINARY_DIR [${GenerateCLP_BINARY_DIR}]")
endif()


# --------------------------------------------------------------------------
# Attempt to guess GenerateCLP build type

set(generateclp_dir ${GenerateCLP_BINARY_DIR}/bin)
if(CMAKE_CONFIGURATION_TYPES)
foreach (type ${CMAKE_CONFIGURATION_TYPES})
if(EXISTS ${generateclp_dir}/${type}/GenerateCLPLauncher${CMAKE_EXECUTABLE_SUFFIX})
set(generateclp_build_type ${type})
break()
endif()
if(EXISTS ${generateclp_dir}/${type}/GenerateCLP${CMAKE_EXECUTABLE_SUFFIX})
set(generateclp_build_type ${type})
break()
endif()
endforeach()
else()
set(generateclp_build_type "${CMAKE_BUILD_TYPE}")
endif()

if("${generateclp_build_type}" STREQUAL "")
message(FATAL_ERROR "'generateclp_build_type' shouldn't be empty !")
endif()

Loading

0 comments on commit 11ea15b

Please sign in to comment.