Skip to content

Commit

Permalink
change location of the generated executable to be in relative directory
Browse files Browse the repository at this point in the history
  • Loading branch information
karlnapf committed Mar 10, 2016
1 parent 402f283 commit 38069c2
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions examples/meta/cpp/CMakeLists.txt
Expand Up @@ -4,19 +4,22 @@ FOREACH(META_EXAMPLE ${META_EXAMPLES})
# assume a structure <target_language>/<category>/listing.sg
STRING(REGEX REPLACE ".*/(.*).sg" "\\1" EXAMPLE_NAME ${META_EXAMPLE})
STRING(REGEX REPLACE ".*/(.*/.*).sg" "\\1" EXAMPLE_NAME_WITH_DIR ${META_EXAMPLE})
STRING(REGEX REPLACE "/" "-" EXAMPLE_NAME_WITH_DIR ${EXAMPLE_NAME_WITH_DIR})
STRING(REGEX REPLACE "/" "_" EXAMPLE_NAME_WITH_DIR ${EXAMPLE_NAME_WITH_DIR})
STRING(REGEX REPLACE ".*/(.*)/.*.sg" "\\1" EXAMPLE_REL_DIR ${META_EXAMPLE})

# meta examples have to be generated before executable and test is added
SET(GENERATED_CPP ${EXAMPLE_REL_DIR}/${EXAMPLE_NAME}.cpp)
SET(GENERATED_CPP_BINARY ${EXAMPLE_NAME_WITH_DIR})

# generate binary in relative directory
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${EXAMPLE_REL_DIR})

ADD_EXECUTABLE(${GENERATED_CPP_BINARY} ${GENERATED_CPP})
ADD_DEPENDENCIES(${GENERATED_CPP_BINARY} meta_examples shogun)
TARGET_LINK_LIBRARIES(${GENERATED_CPP_BINARY} shogun)
SET_SOURCE_FILES_PROPERTIES(${GENERATED_CPP} PROPERTIES GENERATED 1)

LIST(APPEND CPP_EXAMPLES ${GENERATED_CPP_BINARY})
LIST(APPEND GENERATED_CPP_EXAMPLES ${GENERATED_CPP_BINARY})

# run test in source dir, to have access to "data" folder
ADD_TEST(NAME generated_cpp-${EXAMPLE_NAME_WITH_DIR}
Expand All @@ -27,7 +30,7 @@ FOREACH(META_EXAMPLE ${META_EXAMPLES})
ENDFOREACH()

add_custom_target(build_cpp_meta_examples ALL
DEPENDS ${CPP_EXAMPLES}
DEPENDS ${GENERATED_CPP_EXAMPLES}
COMMENT "Compiled generated cpp examples")

INSTALL(PROGRAMS ${INSTALL_EXAMPLES}
Expand Down

0 comments on commit 38069c2

Please sign in to comment.