From 1b54d7a6bec39edeafe73796e82944ff75d243fe Mon Sep 17 00:00:00 2001 From: Axel Forsman Date: Fri, 5 Apr 2024 20:49:32 +0200 Subject: [PATCH] Stop defaulting to the "RelWithDebInfo" build type The Nixpkgs build environment i.a. expects CMAKE_BUILD_TYPE to be an empty string (which would set no optimization flags). --- .gitignore | 3 +++ CMakeLists.txt | 19 ++++++------------- README.md | 4 ++-- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 53f9fce..8c72fed 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ /.eldev /Eldev-local + +/build +/hotfuzz-module.so diff --git a/CMakeLists.txt b/CMakeLists.txt index bbd5541..c2f2710 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,17 +1,10 @@ cmake_minimum_required(VERSION 3.19) project(hotfuzz C) -if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) - message(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.") - set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE - STRING "Choose the type of build." FORCE) -endif() - -find_program(EMACS_PROGRAM emacs) -if(EMACS_PROGRAM) - get_filename_component(EMACS_PROGRAM ${EMACS_PROGRAM} REALPATH) - get_filename_component(EMACS_PROGRAM_DIR ${EMACS_PROGRAM} DIRECTORY) - get_filename_component(EMACS_PROGRAM_DIR ${EMACS_PROGRAM_DIR} DIRECTORY) +find_program(EMACS_EXECUTABLE emacs) +if(EMACS_EXECUTABLE) + file(REAL_PATH ${EMACS_EXECUTABLE} EMACS_EXECUTABLE) + set(EMACS_PROGRAM_DIR ${EMACS_EXECUTABLE}/../..) endif() find_path(EMACS_INCLUDE_DIR emacs-module.h @@ -26,8 +19,8 @@ find_package(Threads REQUIRED) add_library(hotfuzz-module MODULE hotfuzz-module.c) set_target_properties(hotfuzz-module PROPERTIES C_STANDARD 11 - POSITION_INDEPENDENT_CODE ON + C_STANDARD_REQUIRED ON PREFIX "" LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}) -target_include_directories(hotfuzz-module PRIVATE ${EMACS_INCLUDE_DIR}) +target_include_directories(hotfuzz-module SYSTEM PRIVATE ${EMACS_INCLUDE_DIR}) target_link_libraries(hotfuzz-module PRIVATE Threads::Threads) diff --git a/README.md b/README.md index ff09d2b..bb7be2d 100644 --- a/README.md +++ b/README.md @@ -55,8 +55,8 @@ and run ```sh mkdir build cd build -cmake -DCMAKE_C_FLAGS='-O3 -march=native' .. \ - && cmake --build . +cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS=-march=native .. && + cmake --build . ``` and place the resulting shared library somewhere in `load-path`.