Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve CMake builds #73

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 25 additions & 24 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,54 @@ jobs:
run: |
cmake .
make

mkdir build
cd build
cmake -S .. -B .
cmake --build .
cmake -DCMAKE_BUILD_TYPE=Release ..
make clean build
cd ..

mkdir build-with-libcmp
cd build-with-libcmp
USE_LIBCMP=1 cmake -S .. -B .
make clean build
make build
DESTDIR=tmp make install uninstall
make deb
make clean_all

build_doc_this:
Makefile_v1:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: build_doc_this
- name: Makefile_v1
run: |
# would need access to azure.archive.ubuntu.com:
# sudo apt-get update
# sudo apt-get install -y >/dev/null libssl-dev build-essential # not needed
make -f Makefile_v1
USE_LIBCMP=1 make -f Makefile_v1 clean build_no_tls
USE_LIBCMP=1 make -f Makefile_v1 clean build_no_tls
USE_LIBCMP=1 STATIC_LIBCMP=1 make -f Makefile_v1 clean build_no_tls
make -C libsecutils -f Makefile_v1 clean_config
SKIP_pod2markdown=1 make -f Makefile_v1 doc_this
SKIP_pod2markdown=1 DESTDIR=tmp make -f Makefile_v1 install
DESTDIR=tmp make -f Makefile_v1 uninstall
SKIP_pod2markdown=1 DESTDIR=tmp make -f Makefile_v1 install uninstall
make -f Makefile_v1 clean_all
doc_deb:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: doc_deb
run: |
# needs access to azure.archive.ubuntu.com:
sudo apt-get update
sudo apt-get install -y >/dev/null libpod-markdown-perl
sudo apt-get install -y >/dev/null doxygen graphviz # needed only for recursive 'make doc' in libsecutils
make -f Makefile_v1 doc # ensures presence of cmpClient.md
echo
echo ************************* doc finished *************************
echo
sudo apt-get install -y >/dev/null debhelper devscripts
make -f Makefile_v1 deb

test_all:
runs-on: ubuntu-latest
Expand All @@ -62,20 +80,3 @@ jobs:
# sudo apt-get install -y >/dev/null libssl-dev build-essential # not needed
# USE_LIBCMP=1 make -f Makefile_v1 test_Mock OPENSSL_CMP_ASPECTS=credentials V=1 # can be helpful for debugging
USE_LIBCMP=1 make -f Makefile_v1 test_all

doc_deb:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: doc_deb
run: |
# needs access to azure.archive.ubuntu.com:
sudo apt-get update
sudo apt-get install -y >/dev/null libpod-markdown-perl
sudo apt-get install -y >/dev/null doxygen graphviz # needed only for recursive 'make doc' in libsecutils
make -f Makefile_v1 doc # ensures presence of cmpClient.md
echo
echo ************************* doc finished *************************
echo
sudo apt-get install -y >/dev/null debhelper devscripts
make -f Makefile_v1 deb
89 changes: 55 additions & 34 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,32 +107,8 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux")
endif()
endif()

add_library(${LIBGENCMP_NAME} SHARED
"${PROJECT_SOURCE_DIR}/.github/workflows/build.yml"
${SRC_DIR}/genericCMPClient.c
)

add_executable(cmpClient
${SRC_DIR}/cmpClient.c
)

target_link_libraries(cmpClient
${LIBGENCMP_NAME}
security-utilities::library
$<$<BOOL:${USE_LIBCMP}>:cmp>
# important: libcmp before libcrypto such that its contents are preferred
OpenSSL::Crypto
$<$<NOT:$<BOOL:$ENV{SECUTILS_NO_TLS}>>:OpenSSL::SSL>
)
if(DEFINED ENV{SECUTILS_USE_UTA})
target_link_libraries(cmpClient uta)
target_link_directories(cmpClient PRIVATE /usr/local/lib)
# set(CMAKE_INSTALL_RPATH "/usr/local/lib")
endif()
if(DEFINED ENV{SECUTILS_NO_TLS})
add_compile_definitions(SECUTILS_NO_TLS=1)
endif()

# must do add_compile_options() before add_library() and add_executable() see
# https://stackoverflow.com/questions/40516794/cmake-not-applying-compile-option-using-add-compile-options
if(DEFINED ENV{NDEBUG} OR NOT CMAKE_BUILD_TYPE MATCHES Debug)
set(CMAKE_BUILD_TYPE Release # automatically leads to CFLAGS += -DNDEBUG -O3
CACHE STRING "Choose the type of build." FORCE)
Expand Down Expand Up @@ -168,6 +144,32 @@ add_compile_options(-Wno-sign-conversion -Wno-shorten-64-to-32 -Wno-shadow)
# target_compile_features(${LIBGENCMP_NAME} PRIVATE c_std_90)
# target_compile_features(cmpClient PRIVATE c_std_90)

add_library(${LIBGENCMP_NAME} SHARED
"${PROJECT_SOURCE_DIR}/.github/workflows/build.yml"
${SRC_DIR}/genericCMPClient.c
)

add_executable(cmpClient
${SRC_DIR}/cmpClient.c
)

target_link_libraries(cmpClient
${LIBGENCMP_NAME}
security-utilities::library
$<$<BOOL:${USE_LIBCMP}>:cmp>
# important: libcmp before libcrypto such that its contents are preferred
OpenSSL::Crypto
$<$<NOT:$<BOOL:$ENV{SECUTILS_NO_TLS}>>:OpenSSL::SSL>
)
if(DEFINED ENV{SECUTILS_USE_UTA})
target_link_libraries(cmpClient uta)
target_link_directories(cmpClient PRIVATE /usr/local/lib)
# set(CMAKE_INSTALL_RPATH "/usr/local/lib")
endif()
if(DEFINED ENV{SECUTILS_NO_TLS})
add_compile_definitions(SECUTILS_NO_TLS=1)
endif()

target_link_libraries(${LIBGENCMP_NAME}
security-utilities::library
$<$<BOOL:${USE_LIBCMP}>:cmp>
Expand Down Expand Up @@ -221,8 +223,9 @@ endif()

# installation and uninstall

# default destination on Linux and macOS: "/usr/local"
#if(UNIX AND NOT APPLE)
set(CMAKE_INSTALL_PREFIX "/usr")
# set(CMAKE_INSTALL_PREFIX "/usr")
#else()
# set(CMAKE_INSTALL_PREFIX "tmp")
#endif()
Expand Down Expand Up @@ -255,7 +258,12 @@ install(TARGETS cmpClient
)

if(NOT TARGET uninstall)
add_custom_target(uninstall COMMAND xargs -I{} rm -vf $ENV{DESTDIR}{} <install_manifest.txt)
add_custom_target(uninstall
COMMAND xargs -I% rm -vf \${DESTDIR}% <install_manifest.txt
COMMAND rm -vfr "\${DESTDIR}${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/{secutils,cmp}"
COMMAND rm -vfr "\${DESTDIR}${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DOCDIR}-dev"
COMMAND rm -vfr "\${DESTDIR}${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)
endif()


Expand All @@ -274,21 +282,34 @@ set_property(
_CPack_Packages changelog.gz debian/.debhelper/
)

# https://stackoverflow.com/a/78133906/2145180
if(NOT TARGET clean_all)
add_custom_target(clean_all
# cowardly not doing rm -r ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_BINARY_DIR}
COMMAND ${CMAKE_BUILD_TOOL} clean
COMMAND find . -name "*.o" -o -name "*.d" -o -regex "./libgencmp-.*" | xargs rm
COMMAND find . -name build -type dir | xargs rm -r
COMMAND find . -path ./libsecutils/Makefile | xargs -I % ${CMAKE_BUILD_TOOL} -C libsecutils clean_all || true
COMMAND find . -path ./cmpossl/Makefile | xargs -I % ${CMAKE_BUILD_TOOL} -C cmpossl clean_all || true
COMMAND find . -name "*.o" -o -name "*.d" -o -regex "./libgencmp-.*" | xargs rm || true
COMMAND find . -path ./libsecutils/Makefile
| xargs -I% ${CMAKE_BUILD_TOOL} -C libsecutils clean
COMMAND find . -path ./cmpossl/Makefile
| xargs -I% ${CMAKE_BUILD_TOOL} -C cmpossl clean
COMMAND rm CMakeCache.txt
# after the following, cannot call this target again:
COMMAND find . ( -name "*.cmake" -o -name Makefile )
-not -path ./libsecutils/* -not -path ./cmpossl/*
# -not -path ./libsecutils/* -not -path ./cmpossl/*
-not -path ./libsecutils/src/libsecutils/security-utilities_libraryConfig.cmake
-not -path ./libsecutils/src/util/security-utilities_icvutilConfig.cmake
-not -path ./libsecutils/coverage/Makefile
| xargs rm
COMMAND find . -name CMakeFiles
-not -path ./libsecutils/* -not -path ./cmpossl/*
# -not -path ./libsecutils/* -not -path ./cmpossl/*
| xargs rm -r
COMMAND find . -name build -type dir | xargs rm -r || true
COMMAND find . -type dir -empty | xargs rmdir || true
COMMAND find . -type dir -empty | xargs rmdir || true
COMMAND find . -type dir -empty | xargs rmdir || true
COMMAND find . -type dir -empty | xargs rmdir || true
COMMAND find . -type dir -empty | xargs rmdir || true
COMMAND find . -type dir -empty | xargs rmdir || true
VERBATIM
)
endif()
Expand Down
5 changes: 3 additions & 2 deletions Makefile_v1
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ test: clean build_no_tls

doc: doc_this get_submodules
$(MAKE) -C $(SECUTILS_DIR) -f Makefile_v1 doc -s
# not needed for cmpossl

doc/$(OUT_DEV_DOC): doc/Generic_CMP_client_API.odt # to be done manually

Expand Down Expand Up @@ -817,7 +818,7 @@ clean_deb:
# installation #################################################################

# installation target - append ROOTFS=<path> to install into virtual root filesystem
DEST_PRE=$(ROOTFS)/usr
DEST_PRE=$(ROOTFS)/usr/local
DEST_LIB=$(DEST_PRE)/lib
DEST_INC=$(DEST_PRE)
DEST_BIN=$(DEST_PRE)/bin
Expand All @@ -832,7 +833,7 @@ ifeq ($(ROOTFS),)
@read
endif

install: remind_admin
install: remind_admin doc_this
ifeq ($(LPATH),)
ifneq ($(wildcard $(SECUTILS_DIR)),)
$(MAKE) -C $(SECUTILS_DIR) -f Makefile_v1 doc install OUT_DIR="$(OUT_REVERSE_DIR)" DESTDIR="$(DEST_REVERSE_DIR)"
Expand Down
Loading
Loading