Last active
August 9, 2018 19:14
-
-
Save jcfr/7e342d8ff786b82ff81873a96f66a292 to your computer and use it in GitHub Desktop.
Project created while working on Slicer issue "4595: multiple rules generate slicer (ninja error)". See https://issues.slicer.org/view.php?id=4595
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.12) | |
project(Test LANGUAGES CXX) | |
# launcher executable | |
set(CTKAppLauncher_EXECUTABLE ${CMAKE_CURRENT_BINARY_DIR}/fake_launcher_executable) | |
file(WRITE ${CTKAppLauncher_EXECUTABLE} "") | |
# application and executable name | |
set(application_target "AwesomeApp") | |
set(application_name "Awesome") | |
set(executable_name "Awesome") | |
#if(NOT APPLE | |
# set(executable_name ${executable_name}App-real) # Setting a different filename "workaround" the problem | |
#endif() | |
# | |
# target type | |
# | |
set(target_type) | |
if(APPLE) | |
set(target_type MACOSX_BUNDLE) | |
endif() | |
# | |
# target built in "<root>/bin" | |
# | |
add_executable(${application_target} ${target_type} main.cpp) | |
set_target_properties(${application_target} PROPERTIES | |
OUTPUT_NAME ${executable_name} | |
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin | |
) | |
message(STATUS "Setting ${application_name} executable name to '${executable_name}${CMAKE_EXECUTABLE_SUFFIX}'") | |
# | |
# install target | |
# | |
if(NOT APPLE) | |
set(install_destination_args RUNTIME DESTINATION "bin") | |
else() | |
set(install_destination_args BUNDLE DESTINATION ".") | |
endif() | |
install( | |
TARGETS ${application_target} | |
${install_destination_args} | |
COMPONENT Runtime | |
) | |
# | |
# configured launcher in "<root>" | |
# | |
set(configured_launcher_executable "${CMAKE_CURRENT_BINARY_DIR}/${application_name}") | |
set(configure_launcher_command | |
${CMAKE_COMMAND} -E copy ${CTKAppLauncher_EXECUTABLE} ${configured_launcher_executable} | |
) | |
set(configure_launcher_comment | |
"Configuring application launcher: ${application_name}" | |
) | |
# Create command to copy the launcher | |
if(CMAKE_VERSION VERSION_GREATER 3.12.0) | |
message(STATUS "Adding Configure${application_name}Launcher command as regular regular build rule") | |
add_custom_command( | |
DEPENDS | |
${CTKAppLauncher_EXECUTABLE} | |
OUTPUT | |
${configured_launcher_executable} | |
COMMAND | |
${configure_launcher_command} | |
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} | |
COMMENT | |
${configure_launcher_comment} | |
) | |
add_custom_target(Configure${application_name}Launcher ALL | |
DEPENDS | |
${application_target} | |
${CTKAppLauncher_EXECUTABLE} | |
${configured_launcher_executable} | |
) | |
else() | |
# Workaround issue https://issues.slicer.org/view.php?id=4595 | |
message(STATUS "Adding Configure${application_name}Launcher command as a POST_BUILD event") | |
add_custom_target(Configure${application_name}Launcher ALL | |
DEPENDS | |
${CTKAppLauncher_EXECUTABLE} | |
${application_target} | |
COMMAND | |
${configure_launcher_command} | |
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} | |
COMMENT | |
${configure_launcher_comment} | |
) | |
endif() | |
# | |
# side-effect: When using Ninja generator, it automatically adds an alias target for executables. | |
# This should only happen when there are no conflicting target, | |
# Proposed fix: https://gitlab.kitware.com/jcfr/cmake/commits/ninja-generator-do-not-add-alias-matching-custom-command-output | |
# | |
# | |
# Display path of the "real" application | |
# | |
get_target_property(application_output_dir ${application_target} RUNTIME_OUTPUT_DIRECTORY) | |
set(application_build_subdir "") | |
if(APPLE) | |
get_target_property(_is_bundle ${application_target} MACOSX_BUNDLE) | |
if(_is_bundle) | |
set(application_build_subdir "${application_name}.app/Contents/MacOS/") | |
endif() | |
endif() | |
set(real_executable "${application_output_dir}/${application_build_subdir}${executable_name}${CMAKE_EXECUTABLE_SUFFIX}") | |
message(STATUS "Setting ${application_name} real_executable to '${real_executable}'") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
int main(int, char*[]) | |
{ | |
std::cout << "Hello" << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Another work-around?