Make codegen target and module functions usable in-tree

This commit is contained in:
Jack Andersen
2019-06-04 14:42:17 -10:00
parent abfbe39870
commit 30ba348bfd
2 changed files with 70 additions and 57 deletions
+68 -55
View File
@@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 3.12)
include(CMakePackageConfigHelpers)
cmake_policy(SET CMP0077 NEW)
project(codegen VERSION 0.1.0)
@@ -15,15 +16,15 @@ target_include_directories(
codegen
INTERFACE
# Add source include files to target's interface include directories for projects using add_subdirectory()
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${codegen_SOURCE_DIR}/include>
)
set(setup_command_args "")
list(APPEND setup_command_args
"${Python3_EXECUTABLE}" "${PROJECT_SOURCE_DIR}/setup.py" "sdist" "-d" "${PROJECT_BINARY_DIR}/dist"
list(APPEND setup_command_args
"${Python3_EXECUTABLE}" "${codegen_SOURCE_DIR}/setup.py" "sdist" "-d" "${codegen_BINARY_DIR}/dist"
)
set(package_file_name "codegen-${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.tar.gz")
set(package_file "${PROJECT_BINARY_DIR}/dist/${package_file_name}")
set(package_file "${codegen_BINARY_DIR}/dist/${package_file_name}")
add_custom_target(
codegen_sdist
@@ -31,77 +32,86 @@ add_custom_target(
COMMAND
${setup_command_args}
WORKING_DIRECTORY
"${PROJECT_SOURCE_DIR}"
"${codegen_SOURCE_DIR}"
)
add_dependencies(codegen codegen_sdist)
# Install the CMake Module
install(
DIRECTORY "${PROJECT_SOURCE_DIR}/cmake"
DESTINATION "share"
)
#
# If we're told to, make install targets
#
option(CODEGEN_GENERATE_INSTALL_TARGETS "Make codegen install targets" ON)
# Install the python package
install(
FILES "${package_file}"
DESTINATION "share/codegen/"
)
if (CODEGEN_GENERATE_INSTALL_TARGETS)
# Install the project headers
install(
DIRECTORY "${PROJECT_SOURCE_DIR}/include/codegen"
DESTINATION include
)
# Install the CMake Module
install(
DIRECTORY "${codegen_SOURCE_DIR}/cmake"
DESTINATION "share"
)
# Install the python package
install(
FILES "${package_file}"
DESTINATION "share/codegen/"
)
# Install the project headers
install(
DIRECTORY "${codegen_SOURCE_DIR}/include/codegen"
DESTINATION include
)
set(version_config_file "${PROJECT_BINARY_DIR}/codegenConfigVersion.cmake")
set(config_file "${PROJECT_BINARY_DIR}/codegenConfig.cmake")
set(config_install_dir "lib/cmake/codegen")
set(version_config_file "${codegen_BINARY_DIR}/codegenConfigVersion.cmake")
set(config_file "${codegen_BINARY_DIR}/codegenConfig.cmake")
set(config_install_dir "lib/cmake/codegen")
# Associate target with export
install(
TARGETS codegen
EXPORT codegenTargets
INCLUDES DESTINATION include # Added to INTERFACE_INCLUDE_DIRECTORIES
)
# Associate target with export
install(
TARGETS codegen
EXPORT codegenTargets
INCLUDES DESTINATION include # Added to INTERFACE_INCLUDE_DIRECTORIES
)
# Install the target config files
install(
EXPORT codegenTargets
NAMESPACE "codegen::"
DESTINATION "${config_install_dir}"
)
# Install the target config files
install(
EXPORT codegenTargets
NAMESPACE "codegen::"
DESTINATION "${config_install_dir}"
)
# Generate version config file
write_basic_package_version_file(
"${version_config_file}"
COMPATIBILITY SameMajorVersion
)
# Generate version config file
write_basic_package_version_file(
"${version_config_file}"
COMPATIBILITY SameMajorVersion
)
# Generate config file
configure_package_config_file(
"Config.cmake.in"
"${config_file}"
INSTALL_DESTINATION "lib/cmake/codegen"
)
# Generate config file
configure_package_config_file(
"Config.cmake.in"
"${config_file}"
INSTALL_DESTINATION "lib/cmake/codegen"
)
# Install the config files
install(
FILES "${config_file}" "${version_config_file}"
DESTINATION ${config_install_dir}
)
# Install the config files
install(
FILES "${config_file}" "${version_config_file}"
DESTINATION ${config_install_dir}
)
endif()
#
# If we're told to, build the python package at configure time
#
#
if (CODEGEN_BUILD_PACKAGE_DURING_CONFIGURE)
message(STATUS "Building CodeGen Package")
execute_process(
COMMAND
${setup_command_args}
WORKING_DIRECTORY
"${PROJECT_SOURCE_DIR}"
"${codegen_SOURCE_DIR}"
RESULT_VARIABLE setup_result
)
if (NOT setup_result EQUAL 0)
@@ -109,7 +119,10 @@ if (CODEGEN_BUILD_PACKAGE_DURING_CONFIGURE)
endif()
# Copy the built package to a place we can easily find it from parent projects
file(COPY "${package_file}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
file(RENAME "${CMAKE_CURRENT_BINARY_DIR}/${package_file_name}" "${CMAKE_CURRENT_BINARY_DIR}/codegen.tar.gz")
file(COPY "${package_file}" DESTINATION "${codegen_BINARY_DIR}")
file(RENAME "${codegen_BINARY_DIR}/${package_file_name}" "${codegen_BINARY_DIR}/codegen.tar.gz")
set(CODEGEN_PACKAGE "${codegen_BINARY_DIR}/codegen.tar.gz" CACHE FILEPATH "")
endif()
# Include module functions for the parent project as well
include(cmake/Modules/codegen.cmake)
+2 -2
View File
@@ -51,7 +51,7 @@ function(add_codegen_targets
endif()
endforeach()
if ("${CODEGEN_PACKAGE}" STREQUAL "")
set(CODEGEN_PACKAGE "CODEGEN_PACKAGE-NOTFOUND" CACHE FILEPATH)
set(CODEGEN_PACKAGE "CODEGEN_PACKAGE-NOTFOUND" CACHE FILEPATH "")
endif()
endif()
if ("${CODEGEN_PACKAGE}" STREQUAL "CODEGEN_PACKAGE-NOTFOUND")
@@ -224,7 +224,7 @@ function(add_codegen_targets
foreach(current_output_file ${current_output_files})
list(APPEND all_output_files "${current_output_file}")
endforeach()
add_custom_command(
OUTPUT "${current_output_files}"
COMMAND