Skip to content
This repository was archived by the owner on Jul 14, 2022. It is now read-only.

Commit 0ec06ef

Browse files
authored
Merge pull request #7 from Alpine-DAV/install_example
Install example
2 parents 5804f3b + 04c9fd6 commit 0ec06ef

File tree

8 files changed

+321
-4
lines changed

8 files changed

+321
-4
lines changed

azure-pipelines.yml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ stages:
9494
echo $PATH
9595
which cmake
9696
cmake --version
97-
# prepare build dir
97+
# prepare build and install dir
98+
mkdir install
9899
mkdir build
99100
cd build
100101
# setup cmake options
@@ -125,3 +126,27 @@ stages:
125126
# run ctest
126127
ctest -T test --output-on-failure -V
127128
displayName: 'Run Unit Tests'
129+
130+
- script: |
131+
#################################
132+
# install
133+
#################################
134+
cd build
135+
make install
136+
displayName: 'Install'
137+
138+
- script: |
139+
###########################
140+
# using with cmake example
141+
###########################
142+
pwd
143+
ls -l
144+
which cmake
145+
cd install/examples/apcomp/using-with-cmake
146+
mkdir _test_build
147+
cd _test_build
148+
cmake ../
149+
make VERBOSE=1
150+
./apcomp_example
151+
displayName: 'Test vs Install (using-with-cmake)'
152+
condition: succeeded()

src/CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,12 @@ endif()
118118
################################
119119
# Add examples
120120
################################
121-
#if(ENABLE_EXAMPLES)
122-
# add_subdirectory(examples)
123-
#endif()
121+
add_subdirectory(examples)
122+
123+
################################
124+
# Add our config helpers
125+
################################
126+
add_subdirectory(config)
124127

125128
################################
126129
# Create CMake importable

src/apcomp/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
set(apcomp_headers
66
apcomp.hpp
7+
apcomp_exports.h
78
bounds.hpp
89
error.hpp
910
image.hpp
@@ -53,6 +54,8 @@ if (ENABLE_SERIAL)
5354
target_compile_definitions(apcomp PRIVATE APCOMP_USE_OPENMP)
5455
endif()
5556

57+
target_include_directories(apcomp PUBLIC $<INSTALL_INTERFACE:include>)
58+
5659
# Install libraries
5760
install(TARGETS apcomp
5861
EXPORT ${APComp_EXPORT_NAME}
@@ -105,6 +108,7 @@ if (MPI_FOUND)
105108

106109
#this is a workaround for a cmake issue linking an interface header only library statically
107110
target_include_directories(apcomp_mpi PRIVATE $<TARGET_PROPERTY:apcompdiy,INTERFACE_INCLUDE_DIRECTORIES>)
111+
target_include_directories(apcomp_mpi PUBLIC $<INSTALL_INTERFACE:include>)
108112

109113
target_compile_definitions(apcomp_mpi PRIVATE APCOMP_PARALLEL)
110114
target_compile_definitions(apcomp_mpi PRIVATE APCOMP_COMPILING_FLAG)

src/config/APCompConfig.cmake.in

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
###############################################################################
2+
# Copyright (c) 2015-2019, Lawrence Livermore National Security, LLC.
3+
#
4+
# Produced at the Lawrence Livermore National Laboratory
5+
#
6+
# LLNL-CODE-716457
7+
#
8+
# All rights reserved.
9+
#
10+
# Please also read ascent/LICENSE
11+
#
12+
# Redistribution and use in source and binary forms, with or without
13+
# modification, are permitted provided that the following conditions are met:
14+
#
15+
# * Redistributions of source code must retain the above copyright notice,
16+
# this list of conditions and the disclaimer below.
17+
#
18+
# * Redistributions in binary form must reproduce the above copyright notice,
19+
# this list of conditions and the disclaimer (as noted below) in the
20+
# documentation and/or other materials provided with the distribution.
21+
#
22+
# * Neither the name of the LLNS/LLNL nor the names of its contributors may
23+
# be used to endorse or promote products derived from this software without
24+
# specific prior written permission.
25+
#
26+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29+
# ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY,
30+
# LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY
31+
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33+
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
35+
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
36+
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37+
# POSSIBILITY OF SUCH DAMAGE.
38+
#
39+
###############################################################################
40+
41+
###############################################################################
42+
# Note:
43+
# This file is named APCompConfig.cmake because once upon a time
44+
# when it was named apcomp-config.cmake, we found that CMake's exported
45+
# targets script includes all "apcomp-*.cmake" files. This logic would
46+
# cause this script to be included more than once, seeding instability
47+
# that caused great harm to the kingdom.
48+
###############################################################################
49+
50+
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
51+
52+
@PACKAGE_INIT@
53+
54+
55+
if(NOT APCOMP_FOUND)
56+
57+
set(APCOMP_VERSION "@PROJECT_VERSION@")
58+
set(APCOMP_INSTALL_PREFIX "@ASCENT_INSTALL_PREFIX@")
59+
60+
# pull in vars with details about configured paths
61+
get_filename_component(APCOMP_CMAKE_CONFIG_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
62+
63+
include(${APCOMP_CMAKE_CONFIG_DIR}/APCompTargets.cmake)
64+
65+
set(APCOMP_FOUND TRUE)
66+
67+
endif()

src/config/CMakeLists.txt

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
###############################################################################
2+
# Copyright (c) 2015-2019, Lawrence Livermore National Security, LLC.
3+
#
4+
# Produced at the Lawrence Livermore National Laboratory
5+
#
6+
# LLNL-CODE-716457
7+
#
8+
# All rights reserved.
9+
#
10+
# Please also read ascent/LICENSE
11+
#
12+
# Redistribution and use in source and binary forms, with or without
13+
# modification, are permitted provided that the following conditions are met:
14+
#
15+
# * Redistributions of source code must retain the above copyright notice,
16+
# this list of conditions and the disclaimer below.
17+
#
18+
# * Redistributions in binary form must reproduce the above copyright notice,
19+
# this list of conditions and the disclaimer (as noted below) in the
20+
# documentation and/or other materials provided with the distribution.
21+
#
22+
# * Neither the name of the LLNS/LLNL nor the names of its contributors may
23+
# be used to endorse or promote products derived from this software without
24+
# specific prior written permission.
25+
#
26+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29+
# ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY,
30+
# LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY
31+
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33+
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
35+
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
36+
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37+
# POSSIBILITY OF SUCH DAMAGE.
38+
#
39+
###############################################################################
40+
41+
42+
###############################################################################
43+
#
44+
# file: src/config/CMakeLists.txt
45+
#
46+
###############################################################################
47+
48+
###############################################################################
49+
# export everything for a cmake build to be able to import with find_package
50+
###############################################################################
51+
52+
if (NOT DEFINED APCOMP_INSTALL_INCLUDE_DIR)
53+
set(APCOMP_INSTALL_INCLUDE_DIR "include")
54+
endif()
55+
56+
if (NOT DEFINED APCOMP_INSTALL_CONFIG_DIR)
57+
set(APCOMP_INSTALL_CONFIG_DIR "lib")
58+
endif()
59+
60+
if (NOT DEFINED APCOMP_INSTALL_LIB_DIR)
61+
set(APCOMP_INSTALL_LIB_DIR "lib")
62+
endif()
63+
64+
if (NOT DEFINED APCOMP_INSTALL_BIN_DIR)
65+
set(APCOMP_INSTALL_BIN_DIR "bin")
66+
endif()
67+
68+
if (NOT DEFINED APCOMP_INSTALL_SHARED_RESOURCES_DIR)
69+
set(APCOMP_INSTALL_SHARED_RESOURCES_DIR "share/apcomp")
70+
endif()
71+
72+
if (NOT DEFINED APCOMP_INSTALL_CMAKE_MODULE_DIR)
73+
set(APCOMP_INSTALL_CMAKE_MODULE_DIR "${APCOMP_INSTALL_CONFIG_DIR}/cmake")
74+
endif()
75+
76+
include(CMakePackageConfigHelpers)
77+
78+
# write version heler
79+
write_basic_package_version_file(
80+
${CMAKE_CURRENT_BINARY_DIR}/APCompConfigVersion.cmake
81+
VERSION ${PROJECT_VERSION}
82+
COMPATIBILITY AnyNewerVersion
83+
)
84+
85+
86+
# write cmake package config file
87+
configure_package_config_file(
88+
APCompConfig.cmake.in
89+
${CMAKE_CURRENT_BINARY_DIR}/APCompConfig.cmake
90+
INSTALL_DESTINATION ${APCOMP_INSTALL_CONFIG_DIR}
91+
PATH_VARS
92+
APCOMP_INSTALL_INCLUDE_DIR
93+
APCOMP_INSTALL_LIB_DIR
94+
APCOMP_INSTALL_BIN_DIR
95+
APCOMP_INSTALL_SHARED_RESOURCES_DIR
96+
APCOMP_INSTALL_CMAKE_MODULE_DIR
97+
)
98+
99+
100+
# install everything needed
101+
install(FILES
102+
${CMAKE_CURRENT_BINARY_DIR}/APCompConfig.cmake
103+
${CMAKE_CURRENT_BINARY_DIR}/APCompConfigVersion.cmake
104+
DESTINATION ${APCOMP_INSTALL_CMAKE_MODULE_DIR})
105+
106+
107+
108+
109+
110+

src/examples/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
install(DIRECTORY using-with-cmake
2+
DESTINATION examples/apcomp)
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
###############################################################################
2+
# Copyright (c) 2015-2019, Lawrence Livermore National Security, LLC.
3+
#
4+
# Produced at the Lawrence Livermore National Laboratory
5+
#
6+
# LLNL-CODE-716457
7+
#
8+
# All rights reserved.
9+
#
10+
# Please also read ascent/LICENSE
11+
#
12+
# Redistribution and use in source and binary forms, with or without
13+
# modification, are permitted provided that the following conditions are met:
14+
#
15+
# * Redistributions of source code must retain the above copyright notice,
16+
# this list of conditions and the disclaimer below.
17+
#
18+
# * Redistributions in binary form must reproduce the above copyright notice,
19+
# this list of conditions and the disclaimer (as noted below) in the
20+
# documentation and/or other materials provided with the distribution.
21+
#
22+
# * Neither the name of the LLNS/LLNL nor the names of its contributors may
23+
# be used to endorse or promote products derived from this software without
24+
# specific prior written permission.
25+
#
26+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29+
# ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY,
30+
# LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY
31+
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33+
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
35+
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
36+
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37+
# POSSIBILITY OF SUCH DAMAGE.
38+
#
39+
###############################################################################
40+
41+
###############################################################################
42+
#
43+
# Example that shows how to use an installed instance of Ascent in another
44+
# CMake-based build system.
45+
#
46+
# To build:
47+
# mkdir build
48+
# cd build
49+
# cmake -DAPCOMP_DIR={apcomp install path} ../
50+
# make
51+
# ./apcomp_example
52+
#
53+
# If run in sub directory below using-with-cmake in an apcomp install,
54+
# APCOMP_DIR will be defaulted to ../../..
55+
#
56+
# mkdir build
57+
# cd build
58+
# cmake ..
59+
# make
60+
# ./apcomp_example
61+
#
62+
###############################################################################
63+
64+
cmake_minimum_required(VERSION 3.9)
65+
66+
project(using_with_cmake)
67+
68+
#
69+
# Provide default for APCOMP_DIR that works for an apcomp install
70+
#
71+
if(NOT APCOMP_DIR)
72+
set(APCOMP_DIR "../../..")
73+
endif()
74+
75+
#
76+
# Check for valid apcomp install
77+
#
78+
get_filename_component(APCOMP_DIR ${APCOMP_DIR} ABSOLUTE)
79+
if(NOT EXISTS ${APCOMP_DIR}/lib/cmake/APCompConfig.cmake)
80+
MESSAGE(FATAL_ERROR "Could not find APComp CMake include file (${APCOMP_DIR}/lib/cmake/APCompConfig.cmake)")
81+
endif()
82+
83+
#
84+
# Use CMake's find_package to import apcomps targets
85+
#
86+
find_package(APComp REQUIRED
87+
NO_DEFAULT_PATH
88+
PATHS ${APCOMP_DIR}/lib/cmake)
89+
90+
# create our example
91+
add_executable(apcomp_example apcomp_example.cpp)
92+
93+
# link to ascent
94+
target_link_libraries(apcomp_example apcomp)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <apcomp/apcomp.hpp>
2+
3+
#include <iostream>
4+
5+
using namespace std;
6+
7+
int main(void)
8+
{
9+
std::cout<<apcomp::about();
10+
return 0;
11+
}
12+

0 commit comments

Comments
 (0)